2014-05-23 11:17:21 +00:00
|
|
|
# shows a user's playlists (need to be authenticated via oauth)
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import spotipy
|
2014-08-14 10:39:24 +00:00
|
|
|
import spotipy.util as util
|
2014-05-23 11:17:21 +00:00
|
|
|
|
|
|
|
def show_tracks(results):
|
|
|
|
for i, item in enumerate(tracks['items']):
|
|
|
|
track = item['track']
|
|
|
|
print " %d %32.32s %s" % (i, track['artists'][0]['name'], track['name'])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
username = sys.argv[1]
|
|
|
|
else:
|
|
|
|
print "Whoops, need your username!"
|
|
|
|
print "usage: python user_playlists.py [username]"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
token = util.prompt_for_user_token(username)
|
|
|
|
|
|
|
|
if token:
|
|
|
|
top = 40
|
|
|
|
sp = spotipy.Spotify(auth=token)
|
|
|
|
playlists = sp.user_playlists(username)
|
|
|
|
for playlist in playlists['items']:
|
|
|
|
if playlist['owner']['id'] == username:
|
|
|
|
print
|
|
|
|
print playlist['name']
|
|
|
|
print ' total tracks', playlist['tracks']['total']
|
|
|
|
results = sp.user_playlist(username, playlist['id'], fields="tracks,next")
|
|
|
|
tracks = results['tracks']
|
|
|
|
show_tracks(tracks)
|
|
|
|
while tracks['next']:
|
|
|
|
tracks = sp.next(tracks)
|
|
|
|
show_tracks(tracks)
|
|
|
|
else:
|
|
|
|
print "Can't get token for", username
|
|
|
|
|