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):
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
#res = groovesharkApi.getPlaylistSongs(40902662)
#res = groovesharkApi.addUserFavoriteSong('27425375')
#res = groovesharkApi.logout()
+#res = groovesharkApi.getUserPlaylistsEx('stephendenham')
#
#pprint.pprint(res)