spotipy/examples/user_playlists.py

31 lines
604 B
Python
Raw Normal View History

# shows a user's playlists (need to be authenticated via oauth)
import pprint
import sys
2014-05-18 11:08:51 +00:00
import os
2014-05-19 11:24:09 +00:00
import subprocess
import spotipy
2014-05-23 11:19:16 +00:00
import util
2014-05-18 11:08:51 +00:00
import spotipy.oauth2 as oauth2
2014-05-23 11:19:16 +00:00
if len(sys.argv) > 1:
username = sys.argv[1]
else:
2014-05-18 11:08:51 +00:00
print "Whoops, need your username!"
print "usage: python user_playlists.py [username]"
sys.exit()
2014-05-23 11:19:16 +00:00
token = util.prompt_for_user_token(username)
2014-05-19 11:24:09 +00:00
2014-05-23 11:19:16 +00:00
if token:
sp = spotipy.Spotify(auth=token)
playlists = sp.user_playlists(username)
for playlist in playlists['items']:
print playlist['name']
else:
print "Can't get token for", username