2012-07-06, 16:53
problem i have is that when video is playing if i select back or stop it rescrapes and plays
keeps doing that like a continuous loop....
keeps doing that like a continuous loop....
Code:
import urllib,urllib2,re,xbmcplugin,xbmcgui,xbmcaddon
url= "???"'
thumbnail= 'icon.png'
def CATEGORIES():
addDir('Search Mikeys Karaoke','url',1,'icon.png')
def INDEX(url):
search_entered = ''
keyboard = xbmc.Keyboard(search_entered, 'Search Mikeys Karaoke')
keyboard.doModal()
if keyboard.isConfirmed():
search_entered = keyboard.getText() .replace(' ','+') # sometimes you need to replace spaces with + or %20#
if search_entered == None:
return False
url = ???/%s/' % (search_entered)
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('\t<a href="(.+?)">(.+?)</a>').findall(link)
for url,name in match:
addDir(name,url,2,'icon.png')
def VIDEOLINKS(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.search(r'<embed src="http://www.youtube.com/v/(.+?)&hl', link)
youtube_id = match.group(1)
xbmc_url = 'plugin://plugin.video.youtube/?path=/root/search/new&action=play_video&videoid=%s' % youtube_id
xbmc.executebuiltin('XBMC.PlayMedia(%s)' % xbmc_url)
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 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)
xbmcplugin.endOfDirectory(int(sys.argv[1]))