From 406ab4477f0be3b497d072cad3b8113930b8caab Mon Sep 17 00:00:00 2001 From: stephendenham Date: Thu, 9 Dec 2010 11:35:03 +0000 Subject: [PATCH] Add similar artists function. git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@11 2dec19e3-eb1d-4749-8193-008c8bba0994 --- addon.xml | 2 +- changelog.txt | 4 +++ default.py | 72 ++++++++++---------------------------- description.xml | 2 +- resources/lib/GrooveAPI.py | 2 +- 5 files changed, 26 insertions(+), 56 deletions(-) diff --git a/addon.xml b/addon.xml index 6c49f4a..02eae09 100644 --- a/addon.xml +++ b/addon.xml @@ -1,6 +1,6 @@ + version="0.0.2" provider-name="Stephen Denham"> diff --git a/changelog.txt b/changelog.txt index f1adaf9..1c91c09 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +0.0.2: + +Add similar artists function. + 0.0.1: Dharma version. diff --git a/default.py b/default.py index 30460dd..0e0261e 100644 --- a/default.py +++ b/default.py @@ -9,12 +9,10 @@ MODE_PLAYLISTS = 6 MODE_ALBUM = 7 MODE_ARTIST = 8 MODE_PLAYLIST = 9 -MODE_SONG = 10 -MODE_FAVORITE = 11 -MODE_UNFAVORITE = 12 -MODE_SIMILAR_SONG = 13 -MODE_SIMILAR_ARTIST = 14 -MODE_FROWN = 15 +MODE_SIMILAR_ARTISTS = 10 +MODE_SONG = 11 +MODE_FAVORITE = 12 +MODE_UNFAVORITE = 13 lastID = 0 @@ -139,7 +137,7 @@ class Groveshark: def favorite(self, songid): userid = self._get_login() if (userid != 0): - xbmc.log("Favorite playSong: " + str(songid)) + xbmc.log("Favorite song: " + str(songid)) groovesharkApi.favoriteSong(songID = songid) os.remove(favoritesCache) else: @@ -149,7 +147,7 @@ class Groveshark: def unfavorite(self, songid): userid = self._get_login() if (userid != 0): - xbmc.log("Unfavorite playSong: " + str(songid)) + xbmc.log("Unfavorite song: " + str(songid)) groovesharkApi.unfavoriteSong(songID = songid) os.remove(favoritesCache) else: @@ -159,38 +157,21 @@ class Groveshark: def frown(self, songid): userid = self._get_login() if (userid != 0): - xbmc.log("Frown playSong: " + str(songid)) + xbmc.log("Frown song: " + str(songid)) if groovesharkApi.radioFrown(songId = songid) != True: xbmc.log("Unable to frown song " + str(songid)) else: dialog = xbmcgui.Dialog() dialog.ok('Grooveshark', 'You must be logged in', 'to frown a song.') - def similarSong(self, songid): - userid = self._get_login() - if (userid != 0): - xbmc.log("Add song: " + str(songid)) - if groovesharkApi.radioSong(songId = songid) != False and groovesharkApi.radioStartSongs() == True: - self.playNext() - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark', 'Cannot start radio') + 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', 'You must be logged in', 'to update radio song.') - - def similarArtist(self, artistId): - userid = self._get_login() - if (userid != 0): - xbmc.log("Add radio artist: " + str(artistId)) - if groovesharkApi.radioArtist(artistId = artistId) != False and groovesharkApi.radioStartArtists() == True: - self.playNext() - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark', 'Cannot start radio') - else: - dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark', 'You must be logged in', 'to update radio artists.') + dialog.ok('Grooveshark', 'No similar artists.') + self.categories() def album(self,albumid): album = groovesharkApi.albumGetSongs(albumId = albumid, limit = self.songsearchlimit) @@ -198,7 +179,7 @@ class Groveshark: def artist(self, artistid): albums = groovesharkApi.artistGetAlbums(artistId = artistid, limit = self.albumsearchlimit) - self._add_albums_directory(albums) + self._add_albums_directory(albums, artistid) def playlist(self, playlistid): userid = self._get_login() @@ -214,10 +195,6 @@ class Groveshark: xbmc.log("Playing: " + url) xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item) - def playNext(self): - item = self._get_song_item(groovesharkApi.radioNextSong()[0]) - self.playSong(item) - def songItem(self, id, name, album, artist, duration, thumb, image): url = groovesharkApi.getStreamURL(id) # Only try to get the image @@ -321,7 +298,6 @@ class Groveshark: songduration = song[2] songalbum = song[3] songartist = song[6] - #songartistid = song[7] u=sys.argv[0]+"?url="+urllib.quote_plus(songurl) \ +"&mode="+str(MODE_SONG)+"&name="+urllib.quote_plus(songname)+"&id=" \ +str(songid) \ @@ -332,22 +308,16 @@ class Groveshark: +"&image="+urllib.quote_plus(songimage) 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+")")) item.addContextMenuItems(menuItems, replaceItems=False) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False,totalItems=n) i = i + 1 xbmcplugin.setContent(self._handle, 'songs') xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) - def _add_albums_directory(self, albums): + def _add_albums_directory(self, albums, artistid=0): n = len(albums) xbmc.log("Found " + str(n) + " albums...") i = 0 @@ -359,6 +329,8 @@ 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) @@ -492,14 +464,8 @@ elif mode==MODE_FAVORITE: elif mode==MODE_UNFAVORITE: grooveshark.unfavorite(lastID) -elif mode==MODE_SIMILAR_ARTIST: - grooveshark.similarArtist(lastID) - -elif mode==MODE_SIMILAR_SONG: - grooveshark.similarSong(lastID) +elif mode==MODE_SIMILAR_ARTISTS: + grooveshark.similarArtists(lastID) -elif mode==MODE_FROWN: - grooveshark.frown(lastID) - if (mode < MODE_SONG): xbmcplugin.endOfDirectory(int(sys.argv[1])) diff --git a/description.xml b/description.xml index 03f890e..0bcdf20 100644 --- a/description.xml +++ b/description.xml @@ -18,7 +18,7 @@ Grooveshark for XBMC. - 0.0.1 + 0.0.2