mirror of
https://github.com/c0de-archive/spotipy-experiments.git
synced 2024-12-22 09:42:39 +00:00
Make things executable
This commit is contained in:
parent
bc52b1021e
commit
a469ce59e9
0
get_user_auth.py
Normal file → Executable file
0
get_user_auth.py
Normal file → Executable file
0
set_env.sh
Normal file → Executable file
0
set_env.sh
Normal file → Executable file
@ -1,41 +0,0 @@
|
|||||||
# shows a user's playlists (need to be authenticated via oauth)
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import spotipy
|
|
||||||
import spotipy.util as util
|
|
||||||
|
|
||||||
def show_tracks(tracks):
|
|
||||||
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()
|
|
||||||
|
|
||||||
scope = 'user-library-read'
|
|
||||||
token = util.prompt_for_user_token(username, scope)
|
|
||||||
|
|
||||||
if token:
|
|
||||||
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
|
|
Loading…
Reference in New Issue
Block a user