-
- # File download
- def _get_thumb(self, url, id):
- # Get the channel icon
- localThumb = os.path.join(xbmc.translatePath(os.path.join(thumbDir, str(id)))) + '.tbn'
- try:
- if os.path.isfile(localThumb) == False:
- loc = urllib.URLopener()
- loc.retrieve(url, localThumb)
- except:
- xbmc.log('URL download failed of ' + url + ' to ' + localThumb)
- return ""
-
- return os.path.join(os.path.join(thumbDir, str(id))) + '.tbn'
-
- def _add_song(self, songid, songname, songurl, songduration, songalbum, songartist, songartistid, songthumb, songimage):
- songImg = self._get_thumb(songimage, str(songid) + "-image")
- if songImg == "":
- songImg = songimage
- songThm = self._get_thumb(songthumb, str(songid) + "-thumb")
- if songThm == "":
- songThm = songthumb
- u=sys.argv[0]+"?url="+urllib.quote_plus(songurl)+"&mode="+str(MODE_SONG)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid) \
- +"&album="+urllib.quote_plus(songalbum) \
- +"&artist="+urllib.quote_plus(songartist) \
- +"&duration="+str(songduration) \
- +"&thumb="+urllib.quote_plus(songThm) \
- +"&image="+urllib.quote_plus(songImg)
- songItem = xbmcgui.ListItem(label = songartist + " - " + songalbum + " - " + songname, iconImage=songImg, thumbnailImage=songThm, path=songurl)
- songItem.setInfo( type="Music", infoLabels={ "title": songname, "duration": songduration, "album": songalbum, "artist": songartist} )
- fav=sys.argv[0]+"?url="+urllib.quote_plus(songurl)+"&mode="+str(MODE_FAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)
- unfav=sys.argv[0]+"?url="+urllib.quote_plus(songurl)+"&mode="+str(MODE_UNFAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)
- similarArtist=sys.argv[0]+"?mode="+str(MODE_SIMILAR_ARTIST)+"&id="+str(songartistid)
- similarSong=sys.argv[0]+"?mode="+str(MODE_SIMILAR_SONG)+"&id="+str(songid)
- frown=sys.argv[0]+"?mode="+str(MODE_FROWN)+"&id="+str(songid)
- menuItems = []
- menuItems.append(("Grooveshark Favorite", "XBMC.RunPlugin("+fav+")"))
- menuItems.append(("Not Grooveshark Favorite", "XBMC.RunPlugin("+unfav+")"))
- menuItems.append(("Listen to similar artist", "XBMC.RunPlugin("+similarArtist+")"))
- menuItems.append(("Listen to similar song", "XBMC.RunPlugin("+similarSong+")"))
- menuItems.append(("No thanks!", "XBMC.RunPlugin("+frown+")"))
- songItem.addContextMenuItems(menuItems, replaceItems=False)
- xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=songItem,isFolder=False)
- return songItem
-
- def _add_next(self, stop=0):
- print "_add_next " + str(stop)
- if stop == 1:
- groovesharkApi.radioEnabled = False
- self.playlist.clear()
- elif groovesharkApi.radioTurnedOn() == True:
- next = self._get_next()
- self.playlist.add(url, next)