X-Git-Url: https://git.hcoop.net/clinton/xbmc-groove.git/blobdiff_plain/164e42d8abed7c470bf1deb40aaa0428646aac44..86f629eafbd6d6f83b3a1642dc3d2a2b6ff7a861:/resources/lib/GroovesharkAPI.py?ds=sidebyside diff --git a/resources/lib/GroovesharkAPI.py b/resources/lib/GroovesharkAPI.py index 70eddfd..d571670 100644 --- a/resources/lib/GroovesharkAPI.py +++ b/resources/lib/GroovesharkAPI.py @@ -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)