2014-05-23 11:17:21 +00:00
|
|
|
# shows a user's playlists (need to be authenticated via oauth)
|
|
|
|
|
|
|
|
import sys
|
|
|
|
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):
|
2017-07-26 16:24:25 +00:00
|
|
|
for i, item in enumerate(results['items']):
|
2014-05-23 11:17:21 +00:00
|
|
|
track = item['track']
|
2015-06-05 09:07:28 +00:00
|
|
|
print(" %d %32.32s %s" % (i, track['artists'][0]['name'], track['name']))
|
2014-05-23 11:17:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
username = sys.argv[1]
|
|
|
|
else:
|
2015-06-05 09:07:28 +00:00
|
|
|
print("Whoops, need your username!")
|
2015-10-13 19:20:53 +00:00
|
|
|
print("usage: python user_playlists_contents.py [username]")
|
2014-05-23 11:17:21 +00:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
token = util.prompt_for_user_token(username)
|
|
|
|
|
|
|
|
if token:
|
|
|
|
sp = spotipy.Spotify(auth=token)
|
|
|
|
playlists = sp.user_playlists(username)
|
|
|
|
for playlist in playlists['items']:
|
|
|
|
if playlist['owner']['id'] == username:
|
2015-06-05 09:07:28 +00:00
|
|
|
print()
|
|
|
|
print(playlist['name'])
|
|
|
|
print(' total tracks', playlist['tracks']['total'])
|
2014-05-23 11:17:21 +00:00
|
|
|
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:
|
2015-06-05 09:07:28 +00:00
|
|
|
print("Can't get token for", username)
|
2014-05-23 11:17:21 +00:00
|
|
|
|