Starting to code

I am starting to figure out how to write apps, and am messing with other apps’ code. However, whenever I make a small change to the code, the app no longer works. And by small change, I mean add a line of code for a Log() function. What am I doing wrong?

well, without knowing WHAT small changes you’re making that break things, i cant really say… but if you’re new to coding in general, I’d guess that you’re frequently doing something that breaks python syntax. beware of spaces vs tabs, you can not mix the two, and get yourself a proper text editor with syntax highlighting and validation, I strongly recommend Textmate.



No. Seriously. I am trying to fix the NBC plugin. I have coded some plugins for xbmc a year or two ago. I am not a total noob, but this is my first time with the new framework. Here is what I am doing to the _init_.py file:

#Already existing code

#Already existing code

changes to

#Already existing code
Log(pageUrl)
#Already existing code

and the NBC plugin will no longer even start, although prior to the Log line, and if I delete the line also, the plugin does start but does not list anything.

yeah without seeing your actual code in question i cant really tell you anything, but if the plugin will not start at all, its usually due to a python syntax error of some sort, any other problem and generally the plugin would start, but just throw an exception (which gets logged) when it gets to the bad spot.



also, it looks like the NBC plugin is still on framework v0, so it’s due for a major overhaul to bring it up to v1 as well as whatever specific fixes it needs. beware that the older v0 framework stuff it uses is different from what you’ll see in most plugins, is trickier and more limiting to code with, and is almost completely undocumented. dont let the NBC plugin give you a bad impression of our plugin framework, version 1 (and soon v2) is really easy to work with, it’s light-years beyond the original pain in the ass v0 framework.



EDIT: look at the existing logging in the NBC plugin. it seems like the v0 framwork uses Log.Add(), not just Log(). if you’re doing anything more than very minor tweaks to the existing plugin, i’d recommend converting/overhauling it to framwork v1 before you do anything else.


I'm guessing syntax error, try to run "python yourfile.py" through Terminal and see if you get errors other than that it can't find the Plex libs.

You are aware that python use indentation for block delimiters? Setup your editor to show all characters and make sure the identation for the Log() call is correct.

most important is dont use tabs. turn on soft tabs in your editor so that the tab key writes 2 spaces instead of a actual tab

Awesome advice guys. Thanks. I’ll look into overhauling.

I apologise for the existence of the v0 framework :slight_smile: It’s prerelease code that some of the very early plug-ins (including the current App Store) use, so we haven’t been able to retire it yet.



The v0 syntax is Log.Add() instead of Log(), but you should’ve seen an error in your code. If you’re not already, I find it best to run the media server in a Terminal session during development - you can run it with the following command:



~/Library/Application\ Support/Plex/Plex\ Media\ Server.app/Contents/MacOS/Plex\ Media\ Server



If you look inside Framework.bundle in the Plug-ins folder, in Contents/Resources/Versions/0/PMS, you'll find the framework files containing the functions you can call. If you've already had previous Python experience, you'll probably be able to figure it out.

Hope that helps, but I seriously suggest you start with code targeting the v1 framework, as it's much more powerful & easy to use (as Billy Joe said). Feel free to post if you get stuck again :)

Ok, so I have been figuring out Framework v1 most of the day. I am now stuck here:



Traceback (most recent call last):<br />
  File "/Users/harleycolbert/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/0/Python/bootstrap.py", line 19, in <module><br />
    if len(sys.argv) == 2: PMS.Plugin.__run(sys.argv[1])<br />
  File "/Users/harleycolbert/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/0/Python/PMS/Plugin.py", line 391, in __run<br />
    import Code as _plugin<br />
  File "/Users/harleycolbert/Library/Application Support/Plex Media Server/Plug-ins/NBC.bundle/Contents/Code/__init__.py", line 4, in <module><br />
    from PMS.Objects import *<br />




I copied the PMS.Objects line from the hulu plugin. And when I got this error, I deleted the line. And I still keep getting this error. Anybody have an idea on what I am doing wrong with the line:

from PMS.Objects import *

My best guess is that PMS.Objects is a v1 construct but you are still using version 0 (the file path in the stack trace refers to Versions/0 not Versions/1).



Change Info.plist to use version 1:



<br />
<key>PlexFrameworkVersion</key><br />
<string>1</string><br />




hope that helps,
Jonny

Also, importing PMS.Objects is unnecessary - “from PMS import *” should import everything you need :slight_smile:

Still working on the code. Right now I am trying to pull the list of shows and links from the left hand side of the page http://www.nbc.com/Video/library/full-episodes/



My code is as follows:



<br />
def MainMenu():<br />
  url=NBC_FULL_EPISODES_SHOW_LIST<br />
  dir = MediaContainer()<br />
  for showLi in XML.ElementFromURL(url, isHTML=True,).xpath('..//div[contains(@class,"scet-gallery-nav")]'):<br />
    show = showLi.xpath('..//a[contains(@href,"/")]')[0]<br />
    Log("show")<br />
    Log(show)<br />
    title = show.xpath('..').text_content().strip()<br />
    showUrl = show.get('href')<br />
    thumb = ""<br />
    Log(title)<br />
    Log(showUrl)<br />
    dir.Append(Function(DirectoryItem(tv_shows_listings, title=title, thumb=thumb), showUrl=NBC_URL + showUrl))<br />
  return dir<br />




I get the following error: AttributeError: 'list' object has no attribute 'text_content'

I pulled the code form the Hulu plugin, and I don't understand what I am doing wrong. Any suggestions?

Nice to see that someone is working on NBC! I have NBC on my list too, but haven’t had much time to work on plugins lately :frowning:



Anyway, the error you get is probably because of the xpath returning a list (which is correct, even if there’s only one element). Using the first (and probably only) element from this list is your solution I guess:


title = show.xpath('..')[0].text_content().strip()

Try this…





def MainMenu()<br />
  url=NBC_FULL_EPISODES_SHOW_LIST<br />
  dir = MediaContainer()<br />
  for show in XML.ElementFromURL(url, isHTML=True,).xpath('//div[@class="scet-gallery-nav"]//ul[5]/li/a'):<br />
    title = show.text<br />
    showUrl = show.get('href')<br />
    thumb = ""<br />
    Log(title)<br />
    Log(showUrl)<br />
    dir.Append(Function(DirectoryItem(tv_shows_listings, title=title, thumb=thumb), showUrl=NBC_URL + showUrl))<br />
  return dir<br />





I'm new at it too, but it helped me to look at less complex plugin's code.
For example: the MTV Music Videos plugin


didn';t you write the MTV plugin?


no... I wrote an MTV Shows Plugin. (that is incomplete, BTW)
I was referring to the "MTV Music Videos" plugin, available in the App Store.

Anyway, did that code work for you?
Better yet, can you follow it?

Awesome. Checking out the mtv plugin helped a lot. I now have some videos able to be listed. However, when I start to play them the plugin freezes on loading stream. The code in PMS is



WebKit: [nbc.com/parenthood/video/lost-and-found/1230837/]<br />
Found corresponding plug-in: /Users/harleycolbert/Library/Application Support/Plex Media Server/Plug-in Support/Data/com.plexapp.plugins.nbc<br />
Resetting to state wait-for-start<br />
Using /Users/harleycolbert/Library/Application Support/Plex Media Server/Plug-ins/SiteConfigurations.bundle/Contents/Resources/nbc.xml with score of -982.<br />
LINE: HELLO<br />
Received title [Parenthood - Lost and Found - Video - NBC.com].<br />
Frame was loaded.<br />
Frame was loaded.<br />
0x23436e0 Plugin loaded [nbc.com/assets/video/4-0/swf/NBCVideoApp.swf] (55 311 896 529 rewindpl3_0)<br />
Frame was loaded.<br />
0x219fc60 Plugin loaded [static.ak.fbcdn.net/rsrc.php/z6D2S/hash/c729bxo3.swf] (-10000 -9850 1 1 flashXdComm)<br />
Received title [Login Status].<br />
Frame was loaded.<br />
Frame was loaded.<br />
Received title [AddThis utility frame].<br />
Received title [Cross-Domain Receiver Page].<br />
Frame was loaded.<br />
Frame was loaded.<br />




Any ideas?


Check your Site Config.

I now have all the shows listing, but they still don’t play. My site config file is:



<?xml version="1.0" encoding="UTF-8"?><br />
<site site="http://www.nbc.com"<br />
	    plugin="http://www.nbc.com/assets/video/4-0/swf/NBCVideoApp.swf"<br />
			initialState="playing"<br />
			version="1.0"><br />
	<br />
	<br />
	<crop x="0" y="0" width="895" height="529" /><br />
	<br />
	<seekbar type="simple"><br />
		<start x="48" y="516" /><br />
		<end   x="610" y="516" /><br />
		<played><br />
				<color rgb="151515" /><br />
		</played><br />
	</seekbar><br />
	<br />
	<!-- PLAYING --><br />
	<state name="playing"><br />
		<event><br />
			<condition><br />
				<command name="pause" /><br />
			</condition><br />
			<action><br />
				<click x="23" y="516" /><br />
				<goto state="paused" /><br />
			</action><br />
		</event><br />
		<br />
		<!-- Video ends --><br />
		<event><br />
			<condition><br />
				<url matches="http://www.nbc.com/video/library/" /><br />
			</condition><br />
			<action><br />
				<goto state="end" /><br />
			</action><br />
		</event><br />
	</state><br />
	<br />
	<!-- PAUSED --><br />
	<state name="paused"><br />
		<event><br />
			<condition><br />
				<command name="play" /><br />
			</condition><br />
			<action><br />
				<click x="23" y="516" /><br />
				<goto state="playing" /><br />
			</action><br />
		</event><br />
	</state><br />
</site>



and a page I am trying to play is:


http://www.nbc.com/classic-tv/battlestar-galactica/video/battlestar-galactica-part-one/213504



PMS is returning:


WebKit: [nbc.com/classic-tv/battlestar-galactica/video/battlestar-galactica-part-one/213504/]<br />
Found corresponding plug-in: /Users/harleycolbert/Library/Application Support/Plex Media Server/Plug-in Support/Data/com.plexapp.plugins.nbc<br />
Resetting to state playing<br />
Resetting to state playing<br />
Using /Users/harleycolbert/Library/Application Support/Plex Media Server/Site Configurations/NBC2.xml with score of 10018.<br />
LINE: HELLO<br />
Received title [Battlestar Galactica - Battlestar Galactica, Part One - Video - NBC.com].<br />
Frame was loaded.<br />
22:17:30.959293: com.plexapp.plugins.nbc                 :   (Framework) Saved shared HTTP data<br />
Frame was loaded.<br />
0x2156ab0 Plugin loaded [nbc.com/assets/video/4-0/swf/NBCVideoApp.swf] (55 383 896 529 rewindpl3_0)<br />
Frame was loaded.<br />
Received title [TPP].<br />
0x23341d0 Plugin loaded [(null)] (0 1443 300 150 )<br />
Thu May 27 22:17:32 Pro-Office.local Plex Media Server[11901] <Error>: unknown error code: invalid context<br />
Frame was loaded.<br />
0x21a60d0 Plugin loaded [static.ak.fbcdn.net/rsrc.php/z6D2S/hash/c729bxo3.swf] (-10000 -9850 1 1 flashXdComm)<br />
Received title [Login Status].<br />
Frame was loaded.<br />
Frame was loaded.<br />
Received title [Cross-Domain Receiver Page].<br />
Frame was loaded.<br />
Received title [AddThis utility frame].<br />
Frame was loaded.<br />
Frame was loaded.<br />
Received title [Rewind 728x90 Ad Spot].<br />
0x16903140 Plugin loaded [s0.2mdn.net/1870013/PID_1289615_Wishbone_728x90.swf] (0 0 728 90 FLASH_0_1_1275013065321)<br />
Frame was loaded.<br />


Dunno?



It works for me… Although, I’m editing the Site Config. here:

/Users/Me/Library/Application Support/Plex Media Server/Plug-ins/SiteConfigurations.bundle/Contents/Resources/nbc.xml



And, this will probably be over-written when Plex checks for updates. (I’m guessing here.)