2010-09-11, 05:41
I'm writing my first plugin and I have a few questions. I'm writing it to connect to my SageTV server and list and play recorded shows. I have the basics working just fine so far, but the reason I want a plugin instead of just sharing the directory is to get more readable file names and include show descriptions. The data source is an xml file generated by SageTV.
How do I add the show description to the plugin screen? I've done some searching and I think I'll need to use the Skin.SetString function along with ListItem.Plot, but it wasn't clear to me how or where I call that.
Also, I'm having a heck of a time parsing the xml to get the data. It appears that xpath is not available, and minidom was giving me fits, any tips on an easier way to extract the info I need from an xml file?
Here's the code I have so far, it works great but is basically doing the exact same thing as sharing the folder with SMB.
How do I add the show description to the plugin screen? I've done some searching and I think I'll need to use the Skin.SetString function along with ListItem.Plot, but it wasn't clear to me how or where I call that.
Also, I'm having a heck of a time parsing the xml to get the data. It appears that xpath is not available, and minidom was giving me fits, any tips on an easier way to extract the info I need from an xml file?
Here's the code I have so far, it works great but is basically doing the exact same thing as sharing the folder with SMB.
Code:
import urllib,urllib2,re,xbmcplugin,xbmcgui
#TV DASH - by You 2008.
def CATEGORIES():
addDir('SageTV','http://www.aaronblackshear.com/recordings1.xml',2,'')
def INDEX(url):
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('filePath="(.+?)"').findall(link)
for name in match:
addDir(name.replace('D:\\SageTV\\',''),name.replace('D:\\SageTV\\','smb://sagetv/SageRecordings/'),2,'')
def VIDEOLINKS(url,name):
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('filePath="(.+?)"').findall(link)
for name in match:
displayname = name.replace('D:\\SageTV\\','')
displayname = displayname.replace('.ts','')
addLink(displayname,name.replace('D:\\SageTV\\','smb://sagetv/SageRecordings/'),'')
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def addLink(name,url,iconimage):
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
return ok
def addDir(name,url,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
params=get_params()
url=None
name=None
mode=None
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
if mode==None or url==None or len(url)<1:
print ""
CATEGORIES()
elif mode==1:
print ""+url
INDEX(url)
elif mode==2:
print ""+url
VIDEOLINKS(url,name)
xbmcplugin.endOfDirectory(int(sys.argv[1]))