mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-08 15:42:48 +00:00
Added example that gets a user's starred items
This commit is contained in:
parent
7d284dbeab
commit
dde80bae6a
32
examples/user_starred_playlist.py
Normal file
32
examples/user_starred_playlist.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# shows a user's starred playlist
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import spotipy
|
||||||
|
import util
|
||||||
|
import spotipy.oauth2 as oauth2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
sp = spotipy.Spotify(auth=token)
|
||||||
|
results = sp.user_playlist(username)
|
||||||
|
tracks = results['tracks']
|
||||||
|
which = 1
|
||||||
|
while tracks:
|
||||||
|
for item in tracks['items']:
|
||||||
|
track = item['track']
|
||||||
|
print which, track['name' ], ' --', track['artists'][0]['name']
|
||||||
|
which += 1
|
||||||
|
tracks = sp.next(tracks)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print "Can't get token for", username
|
@ -5,7 +5,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import spotipy.oauth2 as oauth2
|
import spotipy.oauth2 as oauth2
|
||||||
|
|
||||||
def prompt_for_user_token(username, scope):
|
def prompt_for_user_token(username, scope=None):
|
||||||
''' prompts the user to login if necessary and returns
|
''' prompts the user to login if necessary and returns
|
||||||
the user token suitable for use with the spotipy.Spotify
|
the user token suitable for use with the spotipy.Spotify
|
||||||
constructor
|
constructor
|
||||||
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='SpotipyWebApi',
|
name='SpotipyWebApi',
|
||||||
version='1.42',
|
version='1.43',
|
||||||
description='simple client for the Spotify Web API',
|
description='simple client for the Spotify Web API',
|
||||||
author="@plamere",
|
author="@plamere",
|
||||||
author_email="paul@echonest.com",
|
author_email="paul@echonest.com",
|
||||||
|
@ -203,7 +203,7 @@ class Spotify(object):
|
|||||||
'''
|
'''
|
||||||
return self.get("users/%s/playlists" % user)
|
return self.get("users/%s/playlists" % user)
|
||||||
|
|
||||||
def user_playlist(self, user, playlist_id, fields=None):
|
def user_playlist(self, user, playlist_id = None, fields=None):
|
||||||
''' Gets playlist of a user
|
''' Gets playlist of a user
|
||||||
'''
|
'''
|
||||||
if playlist_id == None:
|
if playlist_id == None:
|
||||||
|
Loading…
Reference in New Issue
Block a user