Advertisement
Guest User

Untitled

a guest
Jul 8th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. import urllib,urllib2,re,xbmcplugin,xbmcgui,xbmcaddon
  2.  
  3.  
  4.  
  5. def CATEGORIES():
  6. addDir('Search Mikeys Karaoke','url',1,'http://live-tv-stream.googlecode.com/svn/icons/MikeysKaraoke.png')
  7.  
  8. def INDEX(url):
  9. search_entered = ''
  10. keyboard = xbmc.Keyboard(search_entered, 'Search Mikeys Karaoke')
  11. keyboard.doModal()
  12. if keyboard.isConfirmed():
  13. search_entered = keyboard.getText() .replace(' ','+') # sometimes you need to replace spaces with + or %20#
  14. if search_entered == None:
  15. return False
  16. url = 'http://www.cantanding.com/search/%s/' % (search_entered)
  17. req = urllib2.Request(url)
  18. 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')
  19. response = urllib2.urlopen(req)
  20. link=response.read()
  21. response.close()
  22. match=re.compile('\t<a href="(.+?)">(.+?)</a>').findall(link)
  23. for url,name in match:
  24. addDir(name,url,2,iconimage)
  25.  
  26. def VIDEOLINKS(url):
  27. req = urllib2.Request(url)
  28. 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')
  29. response = urllib2.urlopen(req)
  30. link=response.read()
  31. response.close()
  32. match=re.search(r'<embed src="http://www.youtube.com/v/(.+?)&hl', link)
  33. youtube_id = match.group(1)
  34. xbmc_url = 'plugin://plugin.video.youtube/?path=/root/search/new&action=play_video&videoid=%s' % youtube_id
  35. xbmc.executebuiltin('XBMC.PlayMedia(%s)' % xbmc_url)
  36. iconimage = 'http://i.ytimg.com/vi/%s/0.jpg' % youtube_id
  37. addDir(name,url,2,iconimage)
  38.  
  39.  
  40. def get_params():
  41. param=[]
  42. paramstring=sys.argv[2]
  43. if len(paramstring)>=2:
  44. params=sys.argv[2]
  45. cleanedparams=params.replace('?','')
  46. if (params[len(params)-1]=='/'):
  47. params=params[0:len(params)-2]
  48. pairsofparams=cleanedparams.split('&')
  49. param={}
  50. for i in range(len(pairsofparams)):
  51. splitparams={}
  52. splitparams=pairsofparams[i].split('=')
  53. if (len(splitparams))==2:
  54. param[splitparams[0]]=splitparams[1]
  55.  
  56. return param
  57.  
  58. def addDir(name,url,mode,iconimage):
  59. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&iconimage="+urllib.quote_plus(iconimage)
  60. ok=True
  61. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  62. liz.setInfo( type="Video", infoLabels={ "Title": name } )
  63. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  64. return ok
  65.  
  66.  
  67. params=get_params()
  68. url=None
  69. name=None
  70. mode=None
  71. iconimage=None
  72.  
  73. try:
  74. url=urllib.unquote_plus(params["url"])
  75. except:
  76. pass
  77. try:
  78. name=urllib.unquote_plus(params["name"])
  79. except:
  80. pass
  81. try:
  82. iconimage=urllib.unquote_plus(params["iconimage"])
  83. except:
  84. pass
  85. try:
  86. mode=int(params["mode"])
  87. except:
  88. pass
  89.  
  90. print "Mode: "+str(mode)
  91. print "URL: "+str(url)
  92. print "Name: "+str(name)
  93. print "IconImage: "+str(iconimage)
  94.  
  95. if mode==None or url==None or len(url)<1:
  96. print ""
  97. CATEGORIES()
  98.  
  99. elif mode==1:
  100. print ""+url
  101. INDEX(url)
  102.  
  103. elif mode==2:
  104. print ""+url
  105. VIDEOLINKS(url)
  106.  
  107.  
  108.  
  109. xbmcplugin.endOfDirectory(int(sys.argv[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement