2009-04-23, 17:02
Hi guys, I have this plugin:
The thing I would like to do is move that code
into something like this
Basically the urls sent in the addDirectoryItem works for just few minutes, because they are dinamically generated. I have no solutions if not refreshing them (but xbmcplugin.disableCache was removed) or, better, perform the request when launching them (the request is the getHTML(url), because when you connect to the site it gives you the mms url, which as said is valid only for few minutes so when you change channel you have to reload the plugin).
Code:
import xbmc, xbmcgui, xbmcplugin, urllib2, urllib, re
baseurl = 'http://www.rai.tv/dl/RaiTV/videoWall/PublishingBlock-5566288c-3d21-48dc-b3e2-af7fbe3b2af8.xml'
def getHTML( url ):
print 'Rai Italian Tv --> getHTML :: url = '+url
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.0.6) Gecko/2009011912 Firefox/3.0.6')
response = urllib2.urlopen(req)
link=response.read()
response.close()
return link
def SHOWS():
data = getHTML(baseurl)
shows = re.compile('<videoUnit name="(.+?)" type=".+?">\s*<url>(.+?)</url>').findall(data, re.DOTALL)
for name, url in shows:
if 'full' in name:
name = name.replace('diretta','').replace('full','').replace(' - ','')
data = getHTML(url)
print data
mmsurl = re.compile('<REF HREF="(.+?)" />').findall(data, re.DOTALL)[0]
addLink(name,mmsurl)
addDir(' Altri video',url,1,'')
return
def OTHER():
data = getHTML(baseurl)
shows = re.compile('<videoUnit name="(.+?)" type=".+?">\s*<url>(.+?)</url>').findall(data, re.DOTALL)
for name, url in shows:
if 'full' in name:
continue
else:
addLink(name,url)
return
def addLink(name,url):
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage='')
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
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
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 ""
SHOWS()
xbmcplugin.endOfDirectory(int(sys.argv[1]))
elif mode==1:
print ""+url
OTHER()
xbmcplugin.endOfDirectory(int(sys.argv[1]))
The thing I would like to do is move that code
Code:
data = getHTML(url)
print data
mmsurl = re.compile('<REF HREF="(.+?)" />').findall(data, re.DOTALL)[0]
addLink(name,mmsurl)
Code:
addLink(name,url)
+
[do the second part of the code when clicking an item]
Basically the urls sent in the addDirectoryItem works for just few minutes, because they are dinamically generated. I have no solutions if not refreshing them (but xbmcplugin.disableCache was removed) or, better, perform the request when launching them (the request is the getHTML(url), because when you connect to the site it gives you the mms url, which as said is valid only for few minutes so when you change channel you have to reload the plugin).