From 7ce01be6d1a5a7c89224793d310a4623f362e720 Mon Sep 17 00:00:00 2001 From: stephendenham Date: Fri, 14 Jan 2011 12:10:07 +0000 Subject: [PATCH] Version for new API. git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@32 2dec19e3-eb1d-4749-8193-008c8bba0994 --- .pydevproject | 13 + addon.xml | 2 +- changelog.txt | 4 + default.py | 445 ++++++----------------------- description.xml | 2 +- resources/lib/GroovesharkAPI.py | 173 +++++++----- resources/lib/uuid/__init__.py | 477 ++++++++++++++++++++++++++++++++ 7 files changed, 685 insertions(+), 431 deletions(-) create mode 100644 .pydevproject create mode 100644 resources/lib/uuid/__init__.py diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..7848f52 --- /dev/null +++ b/.pydevproject @@ -0,0 +1,13 @@ + + + + +Default +python 2.6 + +/xbmc-groove +/xbmc-groove/resources/lib +/xbmc-groove/resources/lib/simplejson + + + diff --git a/addon.xml b/addon.xml index fd9e4a8..4cb3f96 100644 --- a/addon.xml +++ b/addon.xml @@ -1,6 +1,6 @@ + version="0.2.0" provider-name="Stephen Denham"> diff --git a/changelog.txt b/changelog.txt index 6432b49..622f6dc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +0.2.0: + +Major changes to use new Grooveshark API. + 0.1.5: Big song listing performance improvement. diff --git a/default.py b/default.py index 5c98792..11580b8 100644 --- a/default.py +++ b/default.py @@ -1,5 +1,4 @@ -import urllib, sys, os, shutil, re, xbmcaddon, xbmcplugin, xbmcgui, xbmc - +import urllib, sys, os, shutil, re, time, xbmcaddon, xbmcplugin, xbmcgui, xbmc MODE_SEARCH_SONGS = 1 MODE_SEARCH_ALBUMS = 2 MODE_SEARCH_ARTISTS = 3 @@ -9,15 +8,8 @@ MODE_PLAYLISTS = 6 MODE_ALBUM = 7 MODE_ARTIST = 8 MODE_PLAYLIST = 9 -MODE_SIMILAR_ARTISTS = 10 MODE_SONG = 11 MODE_FAVORITE = 12 -MODE_UNFAVORITE = 13 -MODE_MAKE_PLAYLIST = 14 -MODE_REMOVE_PLAYLIST = 15 -MODE_RENAME_PLAYLIST = 16 -MODE_REMOVE_PLAYLIST_SONG = 17 -MODE_ADD_PLAYLIST_SONG = 18 ACTION_MOVE_LEFT = 1 ACTION_MOVE_UP = 3 @@ -31,20 +23,24 @@ baseDir = os.getcwd() resDir = xbmc.translatePath(os.path.join(baseDir, 'resources')) libDir = xbmc.translatePath(os.path.join(resDir, 'lib')) imgDir = xbmc.translatePath(os.path.join(resDir, 'img')) -thumbDir = os.path.join('special://masterprofile/addon_data/', os.path.join(os.path.basename(os.getcwd()), 'thumb')) +cacheDir = os.path.join(xbmc.translatePath('special://masterprofile/addon_data/'), os.path.basename(os.getcwd())) +thumbDirName = 'thumb' +thumbDir = os.path.join('special://masterprofile/addon_data/', os.path.basename(os.getcwd()), thumbDirName) baseModeUrl = 'plugin://plugin.audio.groove/' playlistUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLIST) playlistsUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLISTS) favoritesUrl = baseModeUrl + '?mode=' + str(MODE_FAVORITES) -thumbDef = os.path.join(os.path.basename(os.getcwd()), 'default.tbn') -listBackground = os.path.join(imgDir, 'listbackground.png') +thumbDef = os.path.join(imgDir, 'default.tbn') sys.path.append (libDir) -from GrooveAPI import GrooveAPI +from GroovesharkAPI import GrooveAPI + try: groovesharkApi = GrooveAPI() + if groovesharkApi.pingService() != True: + raise StandardError('No Grooveshark service') except: dialog = xbmcgui.Dialog() dialog.ok('Grooveshark XBMC', 'Unable to connect with Grooveshark.', 'Please try again later') @@ -55,68 +51,7 @@ class _Info: def __init__( self, *args, **kwargs ): self.__dict__.update( kwargs ) -# Window dialog to select a grooveshark playlist -class GroovesharkPlaylistSelect(xbmcgui.WindowDialog): - - def __init__(self, items=[]): - gap = int(self.getHeight()/100) - w = int(self.getWidth()*0.5) - h = self.getHeight()-30*gap - rw = self.getWidth() - rh = self.getHeight() - x = rw/2 - w/2 - y = rh/2 -h/2 - - self.imgBg = xbmcgui.ControlImage(x+gap, 5*gap+y, w-2*gap, h-5*gap, listBackground) - self.addControl(self.imgBg) - - self.playlistControl = xbmcgui.ControlList(2*gap+x, y+3*gap+30, w-4*gap, h-10*gap, textColor='0xFFFFFFFF', selectedColor='0xFFFF4242', itemTextYOffset=0, itemHeight=50, alignmentY = 0) - self.addControl(self.playlistControl) - - self.lastPos = 0 - self.isSelecting = False - self.selected = -1 - listitems = [] - for playlist in items: - listitems.append(xbmcgui.ListItem(playlist[0])) - listitems.append(xbmcgui.ListItem('New...')) - self.playlistControl.addItems(listitems) - self.setFocus(self.playlistControl) - self.playlistControl.selectItem(0) - item = self.playlistControl.getListItem(self.lastPos) - item.select(True) - - # Highlight selected item - def setHighlight(self): - if self.isSelecting: - return - else: - self.isSelecting = True - - pos = self.playlistControl.getSelectedPosition() - if pos >= 0: - item = self.playlistControl.getListItem(self.lastPos) - item.select(False) - item = self.playlistControl.getListItem(pos) - item.select(True) - self.lastPos = pos - self.isSelecting = False - - # Control - select - def onControl(self, control): - if control == self.playlistControl: - self.selected = self.playlistControl.getSelectedPosition() - self.close() - - # Action - close or up/down - def onAction(self, action): - if action == ACTION_PREVIOUS_MENU: - self.selected = -1 - self.close() - elif action == ACTION_MOVE_UP or action == ACTION_MOVE_DOWN or action == ACTION_PAGE_UP or action == ACTION_PAGE_DOWN == 6: - self.setFocus(self.playlistControl) - self.setHighlight() - + class Groveshark: albumImg = xbmc.translatePath(os.path.join(imgDir, 'album.png')) @@ -129,15 +64,22 @@ class Groveshark: fanImg = xbmc.translatePath(os.path.join(baseDir, 'fanart.png')) settings = xbmcaddon.Addon(id='plugin.audio.groove') - songsearchlimit = settings.getSetting('songsearchlimit') - albumsearchlimit = settings.getSetting('albumsearchlimit') - artistsearchlimit = settings.getSetting('artistsearchlimit') + songsearchlimit = int(settings.getSetting('songsearchlimit')) + albumsearchlimit = int(settings.getSetting('albumsearchlimit')) + artistsearchlimit = int(settings.getSetting('artistsearchlimit')) username = settings.getSetting('username') password = settings.getSetting('password') userid = 0 def __init__( self ): self._handle = int(sys.argv[1]) + if os.path.isdir(cacheDir) == False: + os.makedirs(cacheDir) + xbmc.log("Made " + cacheDir) + if os.path.isdir(thumbDir) == False: + arttDir = os.path.join(cacheDir, thumbDirName) + os.makedirs(arttDir) + xbmc.log("Made " + arttDir) # Top-level menu def categories(self): @@ -146,8 +88,6 @@ class Groveshark: # Setup xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) - if os.path.isdir(thumbDir) == False: - os.makedirs(thumbDir) self._add_dir('Search songs...', '', MODE_SEARCH_SONGS, self.songImg, 0) self._add_dir('Search albums...', '', MODE_SEARCH_ALBUMS, self.albumImg, 0) @@ -161,8 +101,7 @@ class Groveshark: def searchSongs(self): query = self._get_keyboard(default="", heading="Search songs") if (query != ''): - groovesharkApi.setRemoveDuplicates(True) - songs = groovesharkApi.searchSongs(query, limit = self.songsearchlimit) + songs = groovesharkApi.getSongSearchResults(query, limit = self.songsearchlimit) if (len(songs) > 0): self._add_songs_directory(songs) else: @@ -176,7 +115,7 @@ class Groveshark: def searchAlbums(self): query = self._get_keyboard(default="", heading="Search albums") if (query != ''): - albums = groovesharkApi.searchAlbums(query, limit = self.albumsearchlimit) + albums = groovesharkApi.getAlbumSearchResults(query, limit = self.albumsearchlimit) if (len(albums) > 0): self._add_albums_directory(albums) else: @@ -190,7 +129,7 @@ class Groveshark: def searchArtists(self): query = self._get_keyboard(default="", heading="Search artists") if (query != ''): - artists = groovesharkApi.searchArtists(query, limit = self.artistsearchlimit) + artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit) if (len(artists) > 0): self._add_artists_directory(artists) else: @@ -204,9 +143,9 @@ class Groveshark: def favorites(self): userid = self._get_login() if (userid != 0): - favorites = groovesharkApi.userGetFavoriteSongs(userid) + favorites = groovesharkApi.getUserFavoriteSongs() if (len(favorites) > 0): - self._add_songs_directory(favorites, isFavorites=True) + self._add_songs_directory(favorites) else: dialog = xbmcgui.Dialog() dialog.ok('Grooveshark XBMC', 'You have no favorites.') @@ -214,7 +153,7 @@ class Groveshark: # Get popular songs def popularSongs(self): - popular = groovesharkApi.popularGetSongs(limit = self.songsearchlimit) + popular = groovesharkApi.getPopularSongsToday(limit = self.songsearchlimit) if (len(popular) > 0): self._add_songs_directory(popular) else: @@ -226,7 +165,7 @@ class Groveshark: def playlists(self): userid = self._get_login() if (userid != 0): - playlists = groovesharkApi.userGetPlaylists() + playlists = groovesharkApi.getUserPlaylists() if (len(playlists) > 0): self._add_playlists_directory(playlists) else: @@ -242,208 +181,56 @@ class Groveshark: userid = self._get_login() if (userid != 0): xbmc.log("Favorite song: " + str(songid)) - groovesharkApi.favoriteSong(songID = songid) + groovesharkApi.addUserFavoriteSong(songID = songid) xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef + ')') else: dialog = xbmcgui.Dialog() dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.') - - # Remove song from favorites - def unfavorite(self, songid, prevMode=0): - userid = self._get_login() - if (userid != 0): - xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode)) - groovesharkApi.unfavoriteSong(songID = songid) - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef + ')') - # Refresh to remove item from directory - if (int(prevMode) == MODE_FAVORITES): - xbmc.executebuiltin("Container.Refresh(" + favoritesUrl + ")") - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.') - - # 'Frown' a song - def frown(self, songid): - userid = self._get_login() - if (userid != 0): - xbmc.log("Frown song: " + str(songid)) - if groovesharkApi.radioFrown(songId = songid) != True: - xbmc.log("Unable to frown song " + str(songid)) - else: - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef + ')') - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a Grooveshark song.') - - # Find similar artists to searched artist - def similarArtists(self, artistId): - similar = groovesharkApi.artistGetSimilar(artistId, limit = self.artistsearchlimit) - if (len(similar) > 0): - self._add_artists_directory(similar) - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'No similar artists.') - self.categories() - - # Make a playlist from an album - def makePlaylist(self, albumid, name): - userid = self._get_login() - if (userid != 0): - re.split(' - ',name,1) - nameTokens = re.split(' - ',name,1) # suggested name - name = self._get_keyboard(default=nameTokens[0], heading="Grooveshark playlist name") - if name != '': - groovesharkApi.setRemoveDuplicates(True) - album = groovesharkApi.albumGetSongs(albumid, self.songsearchlimit) - songids = [] - for song in album: - songids.append(song[1]) - if groovesharkApi.playlistCreateUnique(name, songids) == 0: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name) - else: - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')') - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.') - - # Rename a playlist - def renamePlaylist(self, playlistid, name): - userid = self._get_login() - if (userid != 0): - newname = self._get_keyboard(default=name, heading="Grooveshark playlist name") - if newname == '': - return - elif groovesharkApi.playlistRename(playlistid, newname) == 0: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name) - else: - # Refresh to show new item name - xbmc.executebuiltin("Container.Refresh") - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.') - - # Remove a playlist - def removePlaylist(self, playlistid, name): - dialog = xbmcgui.Dialog() - if dialog.yesno('Grooveshark XBMC', name, 'Delete this Grooveshark playlist?') == True: - userid = self._get_login() - if (userid != 0): - if groovesharkApi.playlistDelete(playlistid) == 0: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'Cannot remove Grooveshark playlist ', name) - else: - # Refresh to remove item from directory - xbmc.executebuiltin("Container.Refresh(" + playlistsUrl + ")") - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.') - - # Add song to playlist - def addPlaylistSong(self, songid): - userid = self._get_login() - if (userid != 0): - playlists = groovesharkApi.userGetPlaylists() - if (len(playlists) > 0): - ret = 0 - # Select the playlist - playlistSelect = GroovesharkPlaylistSelect(items=playlists) - playlistSelect.setFocus(playlistSelect.playlistControl) - playlistSelect.doModal() - i = playlistSelect.selected - del playlistSelect - if i > -1: - # Add a new playlist - if i >= len(playlists): - name = self._get_keyboard(default='', heading="Grooveshark playlist name") - if name != '': - songIds = [] - songIds.append(songid) - if groovesharkApi.playlistCreateUnique(name, songIds) == 0: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name) - else: - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')') - # Existing playlist - else: - playlist = playlists[i] - playlistid = playlist[1] - xbmc.log("Add song " + str(songid) + " to playlist " + str(playlistid)) - ret = groovesharkApi.playlistAddSong(playlistid, songid, 0) - if ret == 0: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'Cannot add to playlist ') - else: - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added song to Grooveshark playlist, 1000, ' + thumbDef + ')') - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.') - self.categories() - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to add a song to a Grooveshark playlist.') - - # Remove song from playlist - def removePlaylistSong(self, playlistid, playlistname, songpos): - dialog = xbmcgui.Dialog() - if dialog.yesno('Grooveshark XBMC', 'Delete this song from the Grooveshark playlist?') == True: - userid = self._get_login() - if (userid != 0): - if groovesharkApi.playlistDeleteSong(playlistid, songpos) == 0: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'Failed to remove ', ' song from Grooveshark playlist.') - else: - # Refresh to remove item from directory - xbmc.executebuiltin("Container.Refresh(" + playlistUrl + "&id="+str(playlistid) + "&name=" + playlistname + ")") - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a song from a Grooveshark playlist.') # Show selected album def album(self, albumid): - groovesharkApi.setRemoveDuplicates(True) - album = groovesharkApi.albumGetSongs(albumId = albumid, limit = self.songsearchlimit) + album = groovesharkApi.getAlbumSongs(albumid, limit = self.songsearchlimit) self._add_songs_directory(album) # Show selected artist def artist(self, artistid): - albums = groovesharkApi.artistGetAlbums(artistId = artistid, limit = self.albumsearchlimit) + albums = groovesharkApi.getArtistAlbums(artistid, limit = self.albumsearchlimit) self._add_albums_directory(albums, artistid) # Show selected playlist - def playlist(self, playlistid, playlistname): + def playlist(self, playlistid): userid = self._get_login() if (userid != 0): - songs = groovesharkApi.playlistGetSongs(playlistId = playlistid, limit = self.songsearchlimit) - self._add_songs_directory(songs, playlistid, playlistname) + songs = groovesharkApi.getPlaylistSongs(playlistid) + self._add_songs_directory(songs) else: dialog = xbmcgui.Dialog() dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.') # Play a song def playSong(self, item): - url = groovesharkApi.getStreamURL(item.getProperty('id')) - item.setPath(url) - xbmc.log("Playing: " + url) - xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item) + songid = item.getProperty('songid') + song = groovesharkApi.getSongURLFromSongID(songid) + if os.path.isfile(song): + item.setPath(song) + xbmc.log("Playing: " + song) + xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item) + else: + xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Cannot play song, 1000, ' + thumbDef + ')') # Make a song directory item - def songItem(self, id, name, album, artist, duration, thumb, image): - # Only try to get the image - if image != "": - songImg = self._get_icon(image, 'song-' + str(id) + "-image") - songThm = songImg - else: - songThm = self._get_icon(thumb, 'song-' + str(id) + "-thumb") - songImg = songThm - item = xbmcgui.ListItem(label = artist + " - " + album + " - " + name, thumbnailImage=songThm, iconImage=songImg) - item.setInfo( type="music", infoLabels={ "title": name, "duration": duration, "album": album, "artist": artist} ) + def songItem(self, songid, name, album, artist, coverart): + songImg = self._get_icon(coverart, 'song-' + str(songid) + "-image") + item = xbmcgui.ListItem(label = artist + " - " + album + " - " + name, thumbnailImage=songImg, iconImage=songImg) + item.setInfo( type="music", infoLabels={ "title": name, "album": album, "artist": artist} ) item.setProperty('mimetype', 'audio/mpeg') item.setProperty("IsPlayable", "true") - item.setProperty('id', str(id)) - item.setProperty('thumb', songThm) - item.setProperty('image', songImg) + item.setProperty('songid', str(songid)) + item.setProperty('coverart', songImg) + item.setProperty('title', name) + item.setProperty('album', album) + item.setProperty('artist', artist) + return item # Get keyboard input @@ -462,7 +249,7 @@ class Groveshark: return 0 else: if self.userid == 0: - uid = groovesharkApi.loginExt(self.username, self.password) + uid = groovesharkApi.login(self.username, self.password) if (uid != 0): return uid else: @@ -473,62 +260,46 @@ class Groveshark: # Get a song directory item def _get_song_item(self, song): name = song[0] - id = song[1] - duration = song[2] - album = song[3] - artist = song[6] - thumb = song[8] - image = song[9] - return self.songItem(id, name, album, artist, duration, thumb, image) + songid = song[1] + album = song[2] + artist = song[4] + coverart = song[6] + return self.songItem(songid, name, album, artist, coverart) # File download - def _get_icon(self, url, id): - localThumb = os.path.join(xbmc.translatePath(os.path.join(thumbDir, str(id)))) + '.tbn' - try: - if os.path.isfile(localThumb) == False: - xbmc.log('Downloading ' + url + ' to ' + localThumb) - loc = urllib.URLopener() - loc.retrieve(url, localThumb) - except: - shutil.copy2(self.defImg, localThumb) - - return os.path.join(os.path.join(thumbDir, str(id))) + '.tbn' + def _get_icon(self, url, songid): + if url != 'None': + localThumb = os.path.join(xbmc.translatePath(os.path.join(thumbDir, str(songid)))) + '.tbn' + try: + if os.path.isfile(localThumb) == False: + loc = urllib.URLopener() + loc.retrieve(url, localThumb) + except: + shutil.copy2(thumbDef, localThumb) + return os.path.join(os.path.join(thumbDir, str(songid))) + '.tbn' + else: + return thumbDef # Add songs to directory - def _add_songs_directory(self, songs, playlistid=0, playlistname='', isFavorites=False): + def _add_songs_directory(self, songs): n = len(songs) xbmc.log("Found " + str(n) + " songs...") i = 0 while i < n: song = songs[i] item = self._get_song_item(song) - songthumb = item.getProperty('thumb') - songimage = item.getProperty('image') + coverart = item.getProperty('coverart') songname = song[0] songid = song[1] - songduration = song[2] - songalbum = song[3] - songartist = song[6] + songalbum = song[2] + songartist = song[4] u=sys.argv[0]+"?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(songthumb) \ - +"&image="+urllib.quote_plus(songimage) + +"&coverart="+urllib.quote_plus(coverart) fav=sys.argv[0]+"?mode="+str(MODE_FAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid) - unfav=sys.argv[0]+"?mode="+str(MODE_UNFAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)+"&prevmode=" menuItems = [] - if isFavorites == True: - unfav = unfav +str(MODE_FAVORITES) - else: - menuItems.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav+")")) - menuItems.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav+")")) - if playlistid > 0: - rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(i+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname - menuItems.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong+")")) - else: - addplaylstsong=sys.argv[0]+"?id="+str(songid)+"&mode="+str(MODE_ADD_PLAYLIST_SONG) - menuItems.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong+")")) + menuItems.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav+")")) item.addContextMenuItems(menuItems, replaceItems=False) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False, totalItems=n) i = i + 1 @@ -537,7 +308,7 @@ class Groveshark: xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) # Add albums to directory - def _add_albums_directory(self, albums, artistid=0): + def _add_albums_directory(self, albums): n = len(albums) xbmc.log("Found " + str(n) + " albums...") i = 0 @@ -549,8 +320,6 @@ class Groveshark: albumImage = self._get_icon(album[4], 'album-' + str(albumID)) self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, n) i = i + 1 - if artistid > 0: - self._add_dir('Similar artists...', '', MODE_SIMILAR_ARTISTS, self.artistImg, artistid) xbmcplugin.setContent(self._handle, 'albums') xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE) xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) @@ -591,19 +360,6 @@ class Groveshark: u=sys.argv[0]+"?mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&id="+str(id) dir=xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage) dir.setInfo( type="Music", infoLabels={ "title": name } ) - - # Custom menu items - menuItems = [] - if mode == MODE_ALBUM: - mkplaylst=sys.argv[0]+"?mode="+str(MODE_MAKE_PLAYLIST)+"&name="+name+"&id="+str(id) - menuItems.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst+")")) - if mode == MODE_PLAYLIST: - rmplaylst=sys.argv[0]+"?mode="+str(MODE_REMOVE_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id) - menuItems.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst+")")) - mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id) - menuItems.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst+")")) - - dir.addContextMenuItems(menuItems, replaceItems=False) return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items) @@ -633,14 +389,9 @@ params=get_params() mode=None try: mode=int(params["mode"]) except: pass - -if mode > MODE_FAVORITES: - name=None - id=None - try: name=urllib.unquote_plus(params["name"]) - except: pass - try: id=int(params["id"]) - except: pass +id=0 +try: id=int(params["id"]) +except: pass # Call function for URL if mode==None: @@ -665,17 +416,15 @@ elif mode==MODE_PLAYLISTS: grooveshark.playlists() elif mode==MODE_SONG: + try: name=urllib.unquote_plus(params["name"]) + except: pass try: album=urllib.unquote_plus(params["album"]) except: pass try: artist=urllib.unquote_plus(params["artist"]) except: pass - try: duration=int(params["duration"]) + try: coverart=urllib.unquote_plus(params["coverart"]) except: pass - try: thumb=urllib.unquote_plus(params["thumb"]) - except: pass - try: image=urllib.unquote_plus(params["image"]) - except: pass - song = grooveshark.songItem(id, name, album, artist, duration, thumb, image) + song = grooveshark.songItem(id, name, album, artist, coverart) grooveshark.playSong(song) elif mode==MODE_ARTIST: @@ -685,36 +434,10 @@ elif mode==MODE_ALBUM: grooveshark.album(id) elif mode==MODE_PLAYLIST: - grooveshark.playlist(id, name) + grooveshark.playlist(id) elif mode==MODE_FAVORITE: grooveshark.favorite(id) -elif mode==MODE_UNFAVORITE: - try: prevMode=int(urllib.unquote_plus(params["prevmode"])) - except: - prevMode = 0 - grooveshark.unfavorite(id, prevMode) - -elif mode==MODE_SIMILAR_ARTISTS: - grooveshark.similarArtists(id) - -elif mode==MODE_MAKE_PLAYLIST: - grooveshark.makePlaylist(id, name) - -elif mode==MODE_REMOVE_PLAYLIST: - grooveshark.removePlaylist(id, name) - -elif mode==MODE_RENAME_PLAYLIST: - grooveshark.renamePlaylist(id, name) - -elif mode==MODE_REMOVE_PLAYLIST_SONG: - try: playlistID=urllib.unquote_plus(params["playlistid"]) - except: pass - grooveshark.removePlaylistSong(playlistID, name, id) - -elif mode==MODE_ADD_PLAYLIST_SONG: - grooveshark.addPlaylistSong(id) - if mode < MODE_SONG: xbmcplugin.endOfDirectory(int(sys.argv[1])) diff --git a/description.xml b/description.xml index e2e5048..a8ccf8b 100644 --- a/description.xml +++ b/description.xml @@ -18,7 +18,7 @@ Grooveshark XBMC. - 0.1.5 + 0.2.0