Add search of artist's albums.
[clinton/xbmc-groove.git] / resources / lib / GroovesharkAPI.py
index 70eddfd..d571670 100644 (file)
@@ -433,6 +433,25 @@ class GrooveAPI:
                        return self._parsePlaylists(result)
                else:
                        return []
+               
+       # Get userid from name
+       def _getUserIDFromUsername(self, username):
+               result = self._callRemote('getUserIDFromUsername', {'username' : username})
+               if 'result' in result and result['result']['UserID'] > 0:
+                       return result['result']['UserID']
+               else:
+                       return 0
+
+       # Gets the playlists of the logged-in user
+       def getUserPlaylistsEx(self, username):
+               userID = self._getUserIDFromUsername(username)
+               if (userID > 0):
+                       result = self._callRemote('getUserPlaylistsEx', {'userID' : userID})
+                       if 'result' in result and result['result']['playlists'] != None:
+                               playlists = result['result']['playlists']
+                               return self._parsePlaylists(playlists)
+               else:
+                       return []
 
        # Creates a playlist with songs
        def createPlaylist(self, name, songIDs):
@@ -553,17 +572,20 @@ class GrooveAPI:
                        return []
 
        def _parsePlaylists(self, items):
+               i = 0
+               list = []
                if 'result' in items:
-                       i = 0
-                       list = []
                        playlists = items['result']
-                       while(i < len(playlists)):
-                               s = playlists[i]
-                               list.append([s['Name'].encode('ascii', 'ignore'), s['PlaylistID']])
-                               i = i + 1
-                       return list
+               elif len(items) > 0:
+                       playlists = items
                else:
                        return []
+               
+               while (i < len(playlists)):
+                       s = playlists[i]
+                       list.append([s['Name'].encode('ascii', 'ignore'), s['PlaylistID']])
+                       i = i + 1
+               return list
 
 # Test
 #import sys
@@ -587,5 +609,6 @@ class GrooveAPI:
 #res = groovesharkApi.getPlaylistSongs(40902662)
 #res = groovesharkApi.addUserFavoriteSong('27425375')
 #res = groovesharkApi.logout()
+#res = groovesharkApi.getUserPlaylistsEx('stephendenham')
 #
 #pprint.pprint(res)