7ce01be6 |
1 | import socket, hmac, urllib, urllib2, pprint, md5, re, sha, time, random, os, pickle, uuid, tempfile |
1413d357 |
2 | |
44dcc6f4 |
3 | SESSION_EXPIRY = 518400 # 6 days in seconds |
4 | |
1413d357 |
5 | # GrooveAPI constants |
6 | THUMB_URL = 'http://beta.grooveshark.com/static/amazonart/' |
1413d357 |
7 | SONG_LIMIT = 25 |
8 | ALBUM_LIMIT = 15 |
9 | ARTIST_LIMIT = 15 |
7ce01be6 |
10 | SONG_SUFFIX = '.mp3' |
1413d357 |
11 | |
12 | # GrooveSong constants |
13 | DOMAIN = "grooveshark.com" |
14 | HOME_URL = "http://listen." + DOMAIN |
1413d357 |
15 | API_URL = "http://cowbell." + DOMAIN + "/more.php" |
16 | SERVICE_URL = "http://cowbell." + DOMAIN + "/service.php" |
44dcc6f4 |
17 | TOKEN_URL = "http://cowbell." + DOMAIN + "/more.php" |
1413d357 |
18 | |
44dcc6f4 |
19 | CLIENT_NAME = "gslite" |
20 | CLIENT_VERSION = "20101012.37" |
1413d357 |
21 | HEADERS = {"Content-Type": "application/json", |
22 | "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)", |
23 | "Referer": "http://listen.grooveshark.com/main.swf?cowbell=fe87233106a6cef919a1294fb2c3c05f"} |
24 | |
44dcc6f4 |
25 | RE_SESSION = re.compile('"sessionID":"\s*?([A-z0-9]+)"') |
1413d357 |
26 | RANDOM_CHARS = "1234567890abcdef" |
27 | |
28 | # Get a song |
29 | class GrooveSong: |
30 | |
7ce01be6 |
31 | def __init__(self): |
1413d357 |
32 | |
33 | import simplejson |
34 | self.simplejson = simplejson |
7ce01be6 |
35 | |
36 | self.cacheDir = os.path.join(tempfile.gettempdir(), 'groovesong') |
44dcc6f4 |
37 | self._lastSessionTime = 0 |
1413d357 |
38 | self.uuid = self._getUUID() |
44dcc6f4 |
39 | |
40 | self._getSavedSession() |
41 | # session ids last 1 week |
42 | if self.sessionID == '' or time.time() - self._lastSessionTime >= SESSION_EXPIRY: |
43 | self.sessionID = self._getSession(HOME_URL) |
44 | if self.sessionID == '': |
45 | raise StandardError('Failed to get session id') |
46 | else: |
47 | print "New GrooveSong session id: " + self.sessionID |
48 | self._setSavedSession() |
1413d357 |
49 | |
50 | # The actual call to the API |
51 | def _callRemote(self, method, params, type="default"): |
52 | postData = { |
53 | "header": { |
54 | "client": CLIENT_NAME, |
55 | "clientRevision": CLIENT_VERSION, |
56 | "uuid": self.uuid, |
57 | "session": self.sessionID}, |
58 | "country": {"IPR":"1021", "ID":"223", "CC1":"0", "CC2":"0", "CC3":"0", "CC4":"2147483648"}, |
59 | "privacy": 1, |
60 | "parameters": params, |
61 | "method": method} |
62 | |
63 | token = self._getMethodToken(method) |
64 | if token == None: |
65 | raise StandardError("Cannot get token") |
66 | |
67 | postData["header"]["token"] = token |
68 | if type == "service": |
69 | url = SERVICE_URL + "?" + method |
70 | else: |
71 | url = API_URL + "?" + method |
72 | |
73 | postData = self.simplejson.dumps(postData) |
74 | print "GrooveSong URL: " + url |
75 | request = urllib2.Request(url, postData, HEADERS) |
76 | |
77 | response = urllib2.urlopen(request).read() |
78 | try: |
79 | response = self.simplejson.loads(response) |
80 | print "GrooveSong Response..." |
81 | pprint.pprint(response) |
82 | except: |
83 | raise StandardError("API error: " + response) |
84 | try: |
85 | response["fault"] |
86 | except KeyError: |
87 | return response |
88 | else: |
89 | raise StandardError("API error: " + response["fault"]["message"]) |
90 | |
91 | # Generate a random uuid |
92 | def _getUUID(self): |
93 | return str(uuid.uuid4()) |
94 | |
95 | # Make a token ready for a request header |
96 | def _getMethodToken(self, method): |
7ce01be6 |
97 | self._token = self._getCommunicationToken() |
98 | if self._token == None: |
99 | return None |
1413d357 |
100 | |
101 | randomChars = "" |
102 | while 6 > len(randomChars): |
103 | randomChars = randomChars + random.choice(RANDOM_CHARS) |
104 | |
7ce01be6 |
105 | token = sha.new(method + ":" + self._token + ":quitStealinMahShit:" + randomChars).hexdigest() |
106 | |
1413d357 |
107 | return randomChars + token |
108 | |
109 | # Generate a communication token |
110 | def _getCommunicationToken(self): |
111 | params = {"secretKey": self._getSecretKey(self.sessionID)} |
112 | postData = { |
113 | "header": { |
114 | "client": CLIENT_NAME, |
115 | "clientRevision": CLIENT_VERSION, |
116 | "uuid": self.uuid, |
117 | "session": self.sessionID}, |
118 | "country": {"IPR":"1021", "ID":"223", "CC1":"0", "CC2":"0", "CC3":"0", "CC4":"2147483648"}, |
119 | "privacy": 1, |
120 | "parameters": params, |
121 | "method": "getCommunicationToken"} |
122 | |
123 | postData = self.simplejson.dumps(postData) |
124 | request = urllib2.Request(TOKEN_URL, postData, HEADERS) |
125 | response = urllib2.urlopen(request).read() |
126 | try: |
127 | response = self.simplejson.loads(response) |
128 | except: |
129 | raise StandardError("API error: " + response) |
130 | try: |
131 | response["fault"] |
132 | except KeyError: |
133 | return response["result"] |
134 | else: |
135 | return None |
136 | |
137 | # Generate a secret key from a sessionID |
138 | def _getSecretKey(self, sessionID): |
7ce01be6 |
139 | return md5.new(sessionID).hexdigest() |
1413d357 |
140 | |
141 | # Get a session id from some HTML |
142 | def _getSession(self, html): |
143 | html = urllib2.urlopen(HOME_URL).read() |
144 | session = RE_SESSION.search(html) |
145 | if session: |
44dcc6f4 |
146 | self._lastSessionTime = time.time() |
1413d357 |
147 | return session.group(1) |
148 | else: |
149 | return None |
44dcc6f4 |
150 | |
151 | def _getSavedSession(self): |
152 | path = os.path.join(self.cacheDir, 'session.dmp') |
153 | try: |
154 | f = open(path, 'rb') |
155 | session = pickle.load(f) |
156 | self.sessionID = session['sessionID'] |
157 | self._lastSessionTime = session['lastSessionTime'] |
44dcc6f4 |
158 | f.close() |
159 | except: |
160 | self.sessionID = '' |
161 | self._lastSessionTime = 0 |
44dcc6f4 |
162 | pass |
163 | |
164 | def _setSavedSession(self): |
165 | try: |
166 | # Create the 'data' directory if it doesn't exist. |
167 | if not os.path.exists(self.cacheDir): |
168 | os.makedirs(self.cacheDir) |
169 | path = os.path.join(self.cacheDir, 'session.dmp') |
170 | f = open(path, 'wb') |
7ce01be6 |
171 | session = {'sessionID' : self.sessionID, 'lastSessionTime' : self._lastSessionTime} |
44dcc6f4 |
172 | pickle.dump(session, f, protocol=pickle.HIGHEST_PROTOCOL) |
173 | f.close() |
174 | except: |
175 | print "An error occurred during save session" |
176 | pass |
1413d357 |
177 | |
178 | # Gets a stream key and host to get song content |
179 | def _getStreamDetails(self, songID): |
180 | params = { |
181 | "songID": songID, |
182 | "prefetch": False, |
183 | "mobile": False, |
184 | "country": {"IPR":"1021","ID":"223", "CC1":"0", "CC2":"0", "CC3":"0", "CC4":"2147483648"} |
185 | } |
186 | response = self._callRemote("getStreamKeyFromSongIDEx", params) |
7ce01be6 |
187 | try: |
188 | self._lastStreamKey = response["result"]["streamKey"] |
189 | self._lastStreamServer = response["result"]["ip"] |
190 | self._lastStreamServerID = response["result"]["streamServerID"] |
191 | return True |
192 | except: |
193 | return False |
1413d357 |
194 | |
195 | # Tells Grooveshark you have downloaded a song |
196 | def _markSongDownloaded(self, songID): |
197 | params = { |
198 | "streamKey": self._lastStreamKey, |
199 | "streamServerID": self._lastStreamServerID, |
200 | "songID": songID} |
201 | self._callRemote("markSongDownloaded", params) |
202 | |
203 | # Download a song to a temporary file |
204 | def getSongURL(self, songID): |
7ce01be6 |
205 | filename = os.path.join(self.cacheDir, songID + SONG_SUFFIX) |
206 | print "Caching song " + songID + " to " + filename |
1413d357 |
207 | if os.path.isfile(filename) == False: |
7ce01be6 |
208 | if self._getStreamDetails(songID) == True: |
209 | postData = {"streamKey": self._lastStreamKey} |
210 | postData = urllib.urlencode(postData) |
211 | urllib.FancyURLopener().retrieve( "http://" + self._lastStreamServer + "/stream.php", filename, data=postData) |
212 | self._markSongDownloaded(songID) |
213 | else: |
214 | return '' |
1413d357 |
215 | return filename |
216 | |
1413d357 |
217 | # Main API |
218 | class GrooveAPI: |
219 | |
220 | sessionID = '' |
221 | userID = 0 |
222 | host = 'api.grooveshark.com' |
0e7dbdf7 |
223 | lastSessionTime = 0 |
1413d357 |
224 | |
225 | # Constructor |
7ce01be6 |
226 | def __init__(self): |
227 | |
1413d357 |
228 | import simplejson |
229 | self.simplejson = simplejson |
230 | socket.setdefaulttimeout(40) |
7ce01be6 |
231 | |
232 | self.cacheDir = os.path.join(tempfile.gettempdir(), 'grooveapi') |
233 | if os.path.isdir(self.cacheDir) == False: |
234 | os.makedirs(self.cacheDir) |
235 | print "Made " + self.cacheDir |
236 | |
44dcc6f4 |
237 | self._getSavedSession() |
0e7dbdf7 |
238 | # session ids last 1 week |
44dcc6f4 |
239 | if self.sessionID == '' or time.time()- self.lastSessionTime >= SESSION_EXPIRY: |
1413d357 |
240 | self.sessionID = self._getSessionID() |
241 | if self.sessionID == '': |
242 | raise StandardError('Failed to get session id') |
243 | else: |
44dcc6f4 |
244 | print "New GrooveAPI session id: " + self.sessionID |
245 | self._setSavedSession() |
0e7dbdf7 |
246 | |
1413d357 |
247 | # Sort keys |
248 | def _keySort(self, d): |
249 | return [(k,d[k]) for k in sorted(d.keys())] |
250 | |
251 | # Make a message sig |
252 | def _createMessageSig(self, method, params, secret): |
253 | args = self._keySort(params); |
254 | data = ''; |
255 | for arg in args: |
256 | data += str(arg[0]) |
257 | data += str(arg[1]) |
258 | data = method + data |
259 | |
260 | h = hmac.new(secret, data) |
261 | return h.hexdigest() |
262 | |
263 | # The actual call to the API |
264 | def _callRemote(self, method, params = {}): |
265 | url = 'http://%s/ws/2.1/?method=%s&%s&wsKey=wordpress&sig=%s&format=json' % (self.host, method, urllib.urlencode(params), self._createMessageSig(method, params, 'd6c59291620c6eaa5bf94da08fae0ecc')) |
266 | print url |
267 | req = urllib2.Request(url) |
268 | response = urllib2.urlopen(req) |
269 | result = response.read() |
7ce01be6 |
270 | print "Response..." |
1413d357 |
271 | pprint.pprint(result) |
272 | response.close() |
273 | try: |
274 | result = self.simplejson.loads(result) |
275 | return result |
276 | except: |
277 | return [] |
278 | |
279 | # Get a session id |
280 | def _getSessionID(self): |
281 | params = {} |
282 | result = self._callRemote('startSession', params) |
0e7dbdf7 |
283 | self.lastSessionTime = time.time() |
1413d357 |
284 | return result['result']['sessionID'] |
285 | |
44dcc6f4 |
286 | def _getSavedSession(self): |
7ce01be6 |
287 | path = os.path.join(self.cacheDir, 'session.dmp') |
1413d357 |
288 | try: |
289 | f = open(path, 'rb') |
0e7dbdf7 |
290 | session = pickle.load(f) |
291 | self.sessionID = session['sessionID'] |
292 | self.lastSessionTime = session['lastSessionTime'] |
44dcc6f4 |
293 | self.userID = session['userID'] |
1413d357 |
294 | f.close() |
295 | except: |
0e7dbdf7 |
296 | self.sessionID = '' |
297 | self.lastSessionTime = 0 |
44dcc6f4 |
298 | self.userID = 0 |
1413d357 |
299 | pass |
1413d357 |
300 | |
44dcc6f4 |
301 | def _setSavedSession(self): |
1413d357 |
302 | try: |
7ce01be6 |
303 | # Create the directory if it doesn't exist. |
304 | if not os.path.exists(self.cacheDir): |
305 | os.makedirs(self.cacheDir) |
306 | path = os.path.join(self.cacheDir, 'session.dmp') |
1413d357 |
307 | f = open(path, 'wb') |
44dcc6f4 |
308 | session = { 'sessionID' : self.sessionID, 'lastSessionTime' : self.lastSessionTime, 'userID': self.userID} |
0e7dbdf7 |
309 | pickle.dump(session, f, protocol=pickle.HIGHEST_PROTOCOL) |
1413d357 |
310 | f.close() |
311 | except: |
44dcc6f4 |
312 | print "An error occurred during save session" |
1413d357 |
313 | pass |
314 | |
315 | # Make user authentication token |
316 | def _getUserToken(self, username, password): |
317 | return md5.new(username.lower() + md5.new(password).hexdigest()).hexdigest() |
318 | |
319 | # Authenticates the user for current API session |
320 | def _authenticateUser(self, username, token): |
321 | params = {'sessionID': self.sessionID, 'username': username, 'token': token} |
322 | result = self._callRemote('authenticateUser', params) |
323 | return result['result']['UserID'] |
324 | |
325 | # Login |
326 | def login(self, username, password): |
44dcc6f4 |
327 | if self.userID <= 0: |
328 | # Check cache |
329 | self._getSavedSession() |
330 | if self.userID <= 0: |
331 | token = self._getUserToken(username, password) |
332 | self.userID = self._authenticateUser(username, token) |
333 | if self.userID > 0: |
334 | self._setSavedSession() |
1413d357 |
335 | return self.userID |
336 | |
337 | # Logs the user out |
338 | def logout(self): |
44dcc6f4 |
339 | result = self._callRemote('logout', {'sessionID' : self.sessionID}) |
340 | if 'result' in result and result['result']['success'] == True: |
341 | self.userID = 0 |
342 | self._setSavedSession() |
343 | return True |
344 | return False |
1413d357 |
345 | |
1413d357 |
346 | # Search for albums |
347 | def getArtistSearchResults(self, query, limit=ARTIST_LIMIT): |
348 | result = self._callRemote('getArtistSearchResults', {'query' : query,'limit' : limit}) |
349 | if 'result' in result: |
350 | return self._parseArtists(result) |
351 | else: |
352 | return [] |
353 | |
354 | # Search for albums |
355 | def getAlbumSearchResults(self, query, limit=ALBUM_LIMIT): |
356 | result = self._callRemote('getAlbumSearchResults', {'query' : query,'limit' : limit}) |
357 | if 'result' in result: |
358 | return self._parseAlbums(result) |
359 | else: |
360 | return [] |
361 | |
362 | # Search for songs |
363 | def getSongSearchResults(self, query, limit=SONG_LIMIT): |
364 | result = self._callRemote('getSongSearchResultsEx', {'query' : query, 'limit' : limit}) |
365 | if 'result' in result: |
366 | return self._parseSongs(result) |
367 | else: |
368 | return [] |
7ce01be6 |
369 | |
370 | # Get artists albums |
371 | def getArtistAlbums(self, artistID, limit=ALBUM_LIMIT): |
372 | result = self._callRemote('getArtistAlbums', {'artistID' : artistID}) |
373 | if 'result' in result: |
374 | return self._parseAlbums(result, limit) |
375 | else: |
376 | return [] |
377 | |
378 | # Get album songs |
379 | def getAlbumSongs(self, albumID, limit=SONG_LIMIT): |
380 | result = self._callRemote('getAlbumSongsEx', {'albumID' : albumID, 'limit' : limit}) |
381 | if 'result' in result: |
382 | return self._parseSongs(result) |
383 | else: |
384 | return [] |
385 | |
1413d357 |
386 | # Gets the popular songs |
387 | def getPopularSongsToday(self, limit=SONG_LIMIT): |
388 | result = self._callRemote('getPopularSongsToday', {'limit' : limit}) |
389 | if 'result' in result: |
7ce01be6 |
390 | # Note limit is broken in the Grooveshark getPopularSongsToday method |
391 | return self._parseSongs(result, limit) |
1413d357 |
392 | else: |
393 | return [] |
394 | |
395 | # Gets the favorite songs of the logged-in user |
396 | def getUserFavoriteSongs(self): |
397 | if (self.userID == 0): |
398 | return []; |
399 | result = self._callRemote('getUserFavoriteSongs', {'sessionID' : self.sessionID}) |
400 | if 'result' in result: |
401 | return self._parseSongs(result) |
402 | else: |
403 | return [] |
404 | |
40ac5d22 |
405 | # Add song to user favorites |
406 | def addUserFavoriteSong(self, songID): |
407 | if (self.userID == 0): |
408 | return False; |
409 | result = self._callRemote('addUserFavoriteSong', {'sessionID' : self.sessionID, 'songID' : songID}) |
410 | return result['result']['success'] |
7ce01be6 |
411 | |
1413d357 |
412 | # Get the url to link to a song on Grooveshark |
413 | def getSongURLFromSongID(self, songID): |
7ce01be6 |
414 | song = GrooveSong() |
1413d357 |
415 | return song.getSongURL(songID) |
416 | |
417 | # Get the url to link to a song on Grooveshark |
418 | def getSongInfo(self, songID): |
419 | result = self._callRemote('getSongInfoEx', {'songID' : songID}) |
420 | if 'result' in result and 'SongID' in result['result']: |
421 | info = result['result'] |
422 | if 'CoverArtFilename' in info and info['CoverArtFilename'] != None: |
423 | info['CoverArtFilename'] = THUMB_URL+info['CoverArtFilename'].encode('ascii', 'ignore') |
424 | else: |
7ce01be6 |
425 | info['CoverArtFilename'] = 'None' |
1413d357 |
426 | return info |
427 | else: |
7ce01be6 |
428 | return 'None' |
1413d357 |
429 | |
430 | # Gets the playlists of the logged-in user |
431 | def getUserPlaylists(self): |
432 | if (self.userID == 0): |
433 | return []; |
434 | result = self._callRemote('getUserPlaylists', {'sessionID' : self.sessionID}) |
435 | if 'result' in result: |
436 | return self._parsePlaylists(result) |
437 | else: |
438 | return [] |
439 | |
440 | # Creates a playlist with songs |
441 | def createPlaylist(self, name, songIDs): |
442 | result = self._callRemote('createPlaylist', {'name' : name, 'songIDs' : songIDs, 'sessionID' : self.sessionID}) |
40ac5d22 |
443 | if 'result' in result and result['result']['success'] == True: |
7ce01be6 |
444 | return result['result']['playlistID'] |
1413d357 |
445 | elif 'errors' in result: |
446 | return 0 |
447 | |
448 | # Sets the songs for a playlist |
449 | def setPlaylistSongs(self, playlistID, songIDs): |
450 | result = self._callRemote('setPlaylistSongs', {'playlistID' : playlistID, 'songIDs' : songIDs, 'sessionID' : self.sessionID}) |
40ac5d22 |
451 | if 'result' in result and result['result']['success'] == True: |
7ce01be6 |
452 | return True |
1413d357 |
453 | else: |
7ce01be6 |
454 | return False |
1413d357 |
455 | |
456 | # Gets the songs of a playlist |
457 | def getPlaylistSongs(self, playlistID): |
458 | result = self._callRemote('getPlaylistSongs', {'playlistID' : playlistID}); |
459 | if 'result' in result: |
460 | return self._parseSongs(result) |
461 | else: |
462 | return [] |
7ce01be6 |
463 | |
464 | # Check the service |
465 | def pingService(self,): |
466 | result = self._callRemote('pingService', {}); |
467 | if 'result' in result and result['result'] != '': |
468 | return True |
469 | else: |
470 | return False |
1413d357 |
471 | |
472 | # Extract song data |
7ce01be6 |
473 | def _parseSongs(self, items, limit=0): |
1413d357 |
474 | if 'result' in items: |
475 | i = 0 |
476 | list = [] |
477 | if 'songs' in items['result']: |
478 | l = len(items['result']['songs']) |
479 | index = 'songs' |
480 | elif 'song' in items['result']: |
481 | l = 1 |
482 | index = 'song' |
483 | else: |
484 | l = len(items['result']) |
485 | index = '' |
7ce01be6 |
486 | if limit > 0 and l > limit: |
487 | l = limit |
1413d357 |
488 | while(i < l): |
489 | if index == 'songs': |
490 | s = items['result'][index][i] |
491 | elif index == 'song': |
492 | s = items['result'][index] |
493 | else: |
494 | s = items['result'][i] |
495 | if 'CoverArtFilename' not in s: |
496 | info = self.getSongInfo(s['SongID']) |
497 | coverart = info['CoverArtFilename'] |
498 | elif s['CoverArtFilename'] != None: |
499 | coverart = THUMB_URL+s['CoverArtFilename'].encode('ascii', 'ignore') |
500 | else: |
7ce01be6 |
501 | coverart = 'None' |
1413d357 |
502 | list.append([s['SongName'].encode('ascii', 'ignore'),\ |
503 | s['SongID'],\ |
504 | s['AlbumName'].encode('ascii', 'ignore'),\ |
505 | s['AlbumID'],\ |
506 | s['ArtistName'].encode('ascii', 'ignore'),\ |
507 | s['ArtistID'],\ |
508 | coverart]) |
509 | i = i + 1 |
510 | return list |
511 | else: |
512 | return [] |
513 | |
514 | # Extract artist data |
515 | def _parseArtists(self, items): |
516 | if 'result' in items: |
517 | i = 0 |
518 | list = [] |
519 | artists = items['result']['artists'] |
520 | while(i < len(artists)): |
521 | s = artists[i] |
522 | list.append([s['ArtistName'].encode('ascii', 'ignore'),\ |
523 | s['ArtistID']]) |
524 | i = i + 1 |
525 | return list |
526 | else: |
527 | return [] |
528 | |
529 | # Extract album data |
7ce01be6 |
530 | def _parseAlbums(self, items, limit=0): |
1413d357 |
531 | if 'result' in items: |
532 | i = 0 |
533 | list = [] |
7ce01be6 |
534 | try: |
535 | albums = items['result']['albums'] |
536 | except: |
537 | res = items['result'][0] |
538 | albums = res['albums'] |
539 | l = len(albums) |
540 | if limit > 0 and l > limit: |
541 | l = limit |
542 | while(i < l): |
1413d357 |
543 | s = albums[i] |
544 | if 'CoverArtFilename' in s and s['CoverArtFilename'] != None: |
545 | coverart = THUMB_URL+s['CoverArtFilename'].encode('ascii', 'ignore') |
546 | else: |
7ce01be6 |
547 | coverart = 'None' |
1413d357 |
548 | list.append([s['ArtistName'].encode('ascii', 'ignore'),\ |
549 | s['ArtistID'],\ |
550 | s['AlbumName'].encode('ascii', 'ignore'),\ |
551 | s['AlbumID'],\ |
552 | coverart]) |
553 | i = i + 1 |
554 | return list |
555 | else: |
556 | return [] |
557 | |
558 | def _parsePlaylists(self, items): |
559 | if 'result' in items: |
560 | i = 0 |
561 | list = [] |
562 | playlists = items['result'] |
563 | while(i < len(playlists)): |
564 | s = playlists[i] |
7ce01be6 |
565 | list.append([s['Name'].encode('ascii', 'ignore'), s['PlaylistID']]) |
1413d357 |
566 | i = i + 1 |
567 | return list |
568 | else: |
569 | return [] |
1413d357 |
570 | |
571 | # Test |
7ce01be6 |
572 | #import sys |
573 | #res = [] |
574 | #groovesharkApi = GrooveAPI() |
575 | #res = groovesharkApi.pingService() |
44dcc6f4 |
576 | #res = groovesharkApi.login(sys.argv[1], sys.argv[2]) |
7ce01be6 |
577 | #songIDs = ['23404546','23401810','23401157'] |
578 | #res = groovesharkApi.createPlaylist("Test") |
579 | #res = groovesharkApi.setPlaylistSongs(res, songIDs) |
580 | #res = groovesharkApi.getPlaylistSongs(42251632) |
1413d357 |
581 | #res = groovesharkApi.getSongSearchResults('jimmy jazz', 3) |
7ce01be6 |
582 | #res = groovesharkApi.getPopularSongsToday(3) |
583 | #res = groovesharkApi.getSongURLFromSongID('26579347') |
1413d357 |
584 | #res = groovesharkApi.getAlbumSearchResults('london calling', 3) |
7ce01be6 |
585 | #res = groovesharkApi.getArtistAlbums('52283') |
1413d357 |
586 | #res = groovesharkApi.getArtistSearchResults('the clash', 3) |
587 | #res = groovesharkApi.getUserFavoriteSongs() |
44dcc6f4 |
588 | #res = groovesharkApi.getUserPlaylists() |
40ac5d22 |
589 | #res = groovesharkApi.getSongInfo('27425375') |
1413d357 |
590 | #res = groovesharkApi.getPlaylistSongs(40902662) |
40ac5d22 |
591 | #res = groovesharkApi.addUserFavoriteSong('27425375') |
44dcc6f4 |
592 | #res = groovesharkApi.logout() |
7ce01be6 |
593 | # |
594 | #pprint.pprint(res) |