Advertisement
Guest User

XBMC Shoutcast add-on 1.1.1 fixed by f0xhu

a guest
Feb 27th, 2011
1,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.76 KB | None | 0 0
  1. #/*
  2. # *      Copyright (C) 2010 Team XBMC
  3. # *
  4. # *
  5. # *  This Program is free software; you can redistribute it and/or modify
  6. # *  it under the terms of the GNU General Public License as published by
  7. # *  the Free Software Foundation; either version 2, or (at your option)
  8. # *  any later version.
  9. # *
  10. # *  This Program is distributed in the hope that it will be useful,
  11. # *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # *  GNU General Public License for more details.
  14. # *
  15. # *  You should have received a copy of the GNU General Public License
  16. # *  along with this program; see the file COPYING.  If not, write to
  17. # *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. # *  http://www.gnu.org/copyleft/gpl.html
  19. # *
  20. # */
  21.  
  22. import urllib2,string,xbmc,xbmcgui,xbmcplugin, xbmcaddon
  23. from xml.dom import minidom
  24. from urllib import quote_plus
  25. import unicodedata
  26.  
  27. __XBMC_Revision__ = xbmc.getInfoLabel('System.BuildVersion')
  28. __settings__      = xbmcaddon.Addon(id='plugin.audio.shoutcast')
  29. __language__      = __settings__.getLocalizedString
  30. __version__       = __settings__.getAddonInfo('version')
  31. __cwd__           = __settings__.getAddonInfo('path')
  32. __addonname__    = "Shoutcast"
  33. __addonid__      = "plugin.audio.shoutcast"
  34. __author__        = "Team XBMC"
  35.  
  36. BASE_URL = 'http://www.shoutcast.com/sbin/newxml.phtml/'
  37. FAKEHEADER = {'User-Agent': "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13"}
  38.  
  39. def INDEX():
  40.   req = urllib2.Request(BASE_URL, '', FAKEHEADER)
  41.   response = urllib2.urlopen(req)
  42.   link=response.read()
  43.   response.close()
  44.   for stat in minidom.parseString(link).getElementsByTagName('genre'):
  45.     name = stat.attributes["name"].value
  46.     addDir(name)
  47.  
  48. def RESOLVE(id):
  49.   url = "%s?genre=%s" % (BASE_URL, quote_plus(id),)
  50.   log("RESOLVE URL: %s" % url )
  51.   req3 = urllib2.Request(url, '', FAKEHEADER)
  52.   response = urllib2.urlopen(req3)
  53.   link = response.read()
  54.   response.close()
  55.   node = minidom.parseString(link).firstChild
  56.   for stat in node.getElementsByTagName('station'):
  57.     name = unicodedata.normalize('NFKD',stat.attributes["name"].value).encode('ascii','ignore')
  58.     url = "%s?play=%s&tunein=%s" % (sys.argv[0], stat.attributes["id"].value,node.getElementsByTagName('tunein')[0].attributes["base"].value)
  59.     addLink(name,url,stat.attributes["br"].value, stat.attributes["lc"].value)
  60.  
  61. def keyboard():
  62.   kb = xbmc.Keyboard("", __language__(30092), False)
  63.   kb.doModal()
  64.   if (kb.isConfirmed() and len(kb.getText()) > 2):
  65.     doSearch(kb.getText())
  66.  
  67. def doSearch(search):
  68.   url = "%s?search=%s" % (BASE_URL, quote_plus(search),)
  69.   log("SEARCH URL: %s" % url )
  70.   req3 = urllib2.Request(url, '', FAKEHEADER)
  71.   response = urllib2.urlopen(req3)
  72.   link = response.read()
  73.   response.close()
  74.   node = minidom.parseString(link).firstChild
  75.   for stat in node.getElementsByTagName('station'):
  76.     name = unicodedata.normalize('NFKD',stat.attributes["name"].value).encode('ascii','ignore')
  77.     url = "%s?play=%s&tunein=%s" % (sys.argv[0], stat.attributes["id"].value,node.getElementsByTagName('tunein')[0].attributes["base"].value)
  78.     addLink(name,url,stat.attributes["br"].value, stat.attributes["lc"].value)
  79.  
  80. def PLAY(st_id, tunein):
  81.   if __XBMC_Revision__.startswith("10.0"):
  82.     url = "shout://yp.shoutcast.com%s?id=%s" %(tunein,st_id,)
  83.   else:
  84.     url = "http://yp.shoutcast.com%s?id=%s" %(tunein,st_id,)
  85.   log("PLAY URL: %s" % url )  
  86.   xbmc.Player().play(url)
  87.  
  88. def addLink(name,url,size,rating):
  89.   ok=True
  90.   liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage="")
  91.   if __XBMC_Revision__.startswith("10.0"):
  92.     liz.setInfo( type="Music", infoLabels={ "Title": name ,"Size": int(size)} )
  93.   else:
  94.     liz.setInfo( type="Music", infoLabels={ "Title": name ,"Size": int(size), "Listeners": int(rating)} )
  95.   liz.setProperty("IsPlayable","false");
  96.   ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz,isFolder=False)
  97.   return ok
  98.  
  99. def get_params():
  100.   param=[]
  101.   paramstring=sys.argv[2]
  102.   if len(paramstring)>=2:
  103.     params=sys.argv[2]
  104.     cleanedparams=params.replace('?','')
  105.     if (params[len(params)-1]=='/'):
  106.       params=params[0:len(params)-2]
  107.     pairsofparams=cleanedparams.split('&')
  108.     param={}
  109.     for i in range(len(pairsofparams)):
  110.       splitparams={}
  111.       splitparams=pairsofparams[i].split('=')
  112.       if (len(splitparams))==2:
  113.         param[splitparams[0]]=splitparams[1]
  114.   return param
  115.  
  116. def addDir(name):
  117.   u = "%s?id=%s" % (sys.argv[0], name,)
  118.   liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage="")
  119.   ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  120.   return ok
  121.  
  122. def log(msg):
  123.   xbmc.output("### [%s] - %s" % (__addonname__,msg,),level=xbmc.LOGDEBUG )
  124.  
  125. def sort(dir = False):
  126.   if dir:
  127.     xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_BITRATE )
  128.     xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
  129.     try:
  130.       xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LISTENERS )
  131.     except: pass
  132.   else:
  133.     xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_BITRATE, label2Mask="%X" )
  134.     xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL, label2Mask="%X" )
  135.     try:
  136.       xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LISTENERS )
  137.     except: pass
  138.   xbmcplugin.endOfDirectory(int(sys.argv[1]))        
  139.  
  140. params=get_params()
  141. try:
  142.   id = params["id"]
  143. except:
  144.   id = "0";
  145. try:
  146.   initial = params["initial"]
  147. except:
  148.   initial = "0";
  149. try:
  150.   play = params["play"]
  151. except:
  152.   play = "0";
  153. try:
  154.   srch = params["search"]
  155. except:
  156.   srch = "0";
  157.  
  158. iid = len(id)
  159. iplay = len(play)
  160. iinitial = len(initial)
  161. isearch=len(srch);
  162.  
  163. if iid > 1 :
  164.   RESOLVE(id)
  165.   sort()
  166.  
  167. elif iinitial > 1:
  168.   if initial == "search":
  169.     keyboard()
  170.     sort()
  171.   else:
  172.     INDEX()
  173.     sort(True)
  174.          
  175. elif iplay > 1:
  176.   PLAY(play,params["tunein"] )
  177.  
  178. elif isearch > 1:
  179.   doSearch(srch)
  180.   sort()
  181.  
  182. else:
  183.   u = "%s?initial=search" % (sys.argv[0],)
  184.   liz=xbmcgui.ListItem(__language__(30091), iconImage="DefaultFolder.png", thumbnailImage="")
  185.   ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  186.   u = "%s?initial=list" % (sys.argv[0],)
  187.   liz=xbmcgui.ListItem(__language__(30090), iconImage="DefaultFolder.png", thumbnailImage="")
  188.   ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  189.   xbmcplugin.endOfDirectory(int(sys.argv[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement