spotipy/examples/user_playlists.py

29 lines
591 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
2014-08-14 10:39:24 +00:00
import spotipy.util as util
2014-05-23 11:19:16 +00:00
if len(sys.argv) > 1:
username = sys.argv[1]
else:
2015-06-05 09:07:28 +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']:
2015-06-05 09:07:28 +00:00
print(playlist['name'])
2014-05-23 11:19:16 +00:00
else:
2015-06-05 09:07:28 +00:00
print("Can't get token for", username)