Add similar artists function.
authorstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Thu, 9 Dec 2010 11:35:03 +0000 (11:35 +0000)
committerstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Thu, 9 Dec 2010 11:35:03 +0000 (11:35 +0000)
git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@11 2dec19e3-eb1d-4749-8193-008c8bba0994

addon.xml
changelog.txt
default.py
description.xml
resources/lib/GrooveAPI.py

index 6c49f4a..02eae09 100644 (file)
--- a/addon.xml
+++ b/addon.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon id="plugin.audio.groove" name="Grooveshark for XBMC"
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon id="plugin.audio.groove" name="Grooveshark for XBMC"
-       version="0.0.1" provider-name="Stephen Denham">
+       version="0.0.2" provider-name="Stephen Denham">
        <requires>
                <import addon="xbmc.python" version="1.0" />
        </requires>
        <requires>
                <import addon="xbmc.python" version="1.0" />
        </requires>
index f1adaf9..1c91c09 100644 (file)
@@ -1,3 +1,7 @@
+0.0.2:
+
+Add similar artists function.
+
 0.0.1:
 
 Dharma version.
 0.0.1:
 
 Dharma version.
index 30460dd..0e0261e 100644 (file)
@@ -9,12 +9,10 @@ MODE_PLAYLISTS = 6
 MODE_ALBUM = 7
 MODE_ARTIST = 8
 MODE_PLAYLIST = 9
 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
 
 
 lastID = 0
 
@@ -139,7 +137,7 @@ class Groveshark:
     def favorite(self, songid):
         userid = self._get_login()
         if (userid != 0):
     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:
             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):
     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:
             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):
     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.')
 
             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()
         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)
     
     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)
     
     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()
     
     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)
     
         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
     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]
             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) \
             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)
             +"&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 = []
             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)
             
             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
         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
             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)
         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_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]))
 if (mode < MODE_SONG):    
     xbmcplugin.endOfDirectory(int(sys.argv[1]))
index 03f890e..0bcdf20 100644 (file)
@@ -18,7 +18,7 @@
        <title>Grooveshark for XBMC.</title>
 
        <!-- (required) Major.minor.build -->
        <title>Grooveshark for XBMC.</title>
 
        <!-- (required) Major.minor.build -->
-       <version>0.0.1</version>
+       <version>0.0.2</version>
 
        <!--
                (required) author name & email. at least one author name is required
 
        <!--
                (required) author name & email. at least one author name is required
index b1e5c7e..8cfa941 100644 (file)
@@ -626,7 +626,7 @@ class GrooveAPI:
                                                s['artistID'],\
                                                s['albumName'].encode('ascii', 'ignore'),\
                                                s['albumID'],\
                                                s['artistID'],\
                                                s['albumName'].encode('ascii', 'ignore'),\
                                                s['albumID'],\
-                                               s['image']['tiny'].encode('ascii', 'ignore')])
+                                               s['image']['medium'].encode('ascii', 'ignore')])
                                        except:
                                                print 'GrooveShark: Could not parse album number: ' + str(i)
                                                traceback.print_exc()
                                        except:
                                                print 'GrooveShark: Could not parse album number: ' + str(i)
                                                traceback.print_exc()