PDA

View Full Version : Trying to add List Refresh


XBMCG33K
2008-12-17, 23:19
I cannot figure out for the life of me where: xbmc.executebuiltin("Container.Refresh")
would go in all of this. Here is the code if anyone can help me out with a suggestion or two :)

import urllib,urllib2,re,xbmcplugin,xbmcgui
#BBN

def Step0():
res=[]
url='URL'
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
response = urllib2.urlopen(req)
link=response.read()
code=re.sub(''','',link)
code2=re.sub('&','&',code)
response.close()
p=re.compile('<td align="center" valign="top">[.\r\n.]<div><a href="(.+?)"><img [.\r\n.]src="(.+?)".+? alt="(.+?)"></a></div>[.\r\n.].+?[.\r\n.]<small>Rating: (.+?) .+?[.\r\n.]<div>.+?</div>[.\r\n.]</td>')
match=p.findall(code2)
for url,img,name,rating in match:
res.append((url,img,name,rating))
for url,img,name,rating in res:
addDir0(name,"URL" + url,img,1)

def Step1(url):
res=[]
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
response = urllib2.urlopen(req)
link=response.read()
response.close()
p=re.compile('<tr>[.\r\n.]<td width=".+?">[.\r\n.]<a href="..(.+?)">[.\r\n.]<img src="(.+?)" .+?[.\r\n.]alt="(.+?)">[.\r\n.]</a>')
match=p.findall(link)
for url,img,name in match:
res.append((url,img,name))
addLink(name,url,img)
#addDir1(name,url,img,2)

def addDir0(name,url,img,mode):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&img="+urllib.quote_plus(img)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=img)
liz.setInfo( type="Pictures", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok

def addLink(name,url,img):
res=[]
sfile=None
tfile=None
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=img)
liz.setInfo( type="Pictures", infoLabels={ "Title": name } )

req = urllib2.Request("URL" + url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
response = urllib2.urlopen(req)
link=response.read()
response.close()
p=re.compile('<a href="../(.+?)" class="size1"><big><big>Watch this trailer</big></big></a>')
match=p.findall(link)
for sfile in match:
res.append((sfile))

req = urllib2.Request("URL" + sfile)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
response = urllib2.urlopen(req)
link=response.read()
response.close()
p=re.compile('<a href=\"(.+?)\"><b>right click here</b></a>')
match=p.findall(link)
for tfile in match:
print "XBMCG33K :: " + tfile
res.append((tfile))

ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=tfile,listitem=liz)
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
sfile=None
Tfile=None
name=None
img=None
mode=None
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
sfile=urllib.unquote_plus(params["sfile"])
except:
pass
try:
sfile=urllib.unquote_plus(params["Tfile"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
try:
img=urllib.unquote_plus(params["img"])
except:
pass
try:
sName=urllib.unquote_plus(sName)
except:
pass
try:
sImg=urllib.unquote_plus(sImg)
except:
pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
print "Img: "+str(img)
print "sFile: "+str(sfile)

if mode==None or url==None or len(url)<1:
print "CATEGORY INDEX : "
Step0()
elif mode==1:
print "Create dir for : "+url
Step1(url)
elif mode==9:
print "Create link2 for : "+url
INDEX2(url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))

Voinage
2008-12-18, 02:44
To start with def Step0 correction -
code=re.sub(''','',link)

needs to be code=re.sub(" ' ",'',link) without the spaces of course, if not the whole program becomes a string.


What are you trying to refresh - video links ?

Try this :

http://xbmc.org/forum/showthread.php?t=29577

XBMCG33K
2008-12-18, 03:47
Yes video links :)

Nuka1195
2008-12-18, 04:40
you want to refresh an exiting list created with a plugin?

there's the cacheToDisc option. is this something that would help?

i'm not sure what your doing.

XBMCG33K
2008-12-19, 01:18
To be honest it is a plugin for an adult site that allows you to watch trailers. The plugin still only views the first page, but the list is old and has been updated on the website.

Voinage
2008-12-20, 00:15
make a new plugin from scratch and scrape the new info