Documentation and support for Your Music methods

This commit is contained in:
Paul Lamere 2014-07-23 10:29:40 -04:00
parent 2d98c30d01
commit 1ebbac6de7
5 changed files with 68 additions and 6 deletions

View File

@ -64,6 +64,10 @@ A full set of examples can be found in the [Spotipy examples directory](https://
- **user_playlist_add_tracks(self, user, playlist_id, tracks, position=None)** - Adds tracks to a playlist - **user_playlist_add_tracks(self, user, playlist_id, tracks, position=None)** - Adds tracks to a playlist
- **user_playlist_create(self, user, name, public=True)** - Creates a playlist for a user - **user_playlist_create(self, user, name, public=True)** - Creates a playlist for a user
- **user_playlists(self, user)** - Gets playlists of a user - **user_playlists(self, user)** - Gets playlists of a user
- **current_user(self)** - Get detailed profile information about the current user.
- **current_user_saved_tracks(self, limit=20, offset=0)** - Gets a list of the tracks saved in the current authorized user's "Your Music" library
- **current_user_saved_tracks_delete(self, limit=20, offset=0)** - Remove tracks from the current authorized user's "Your Music" library
- **current_user_saved_tracks_add(self, limit=20, offset=0)** - Add tracks to the current authorized user's "Your Music" library
Refer to the [Spotify API documentation](https://developer.spotify.com/spotify-web-api/) for details on the methods and parameters. Refer to the [Spotify API documentation](https://developer.spotify.com/spotify-web-api/) for details on the methods and parameters.

View File

@ -0,0 +1,28 @@
# Add tracks to 'Your Collection' of saved tracks
import pprint
import sys
import spotipy
import spotipy.oauth2 as oauth2
import util
scope = 'user-library-modify'
if len(sys.argv) > 2:
username = sys.argv[1]
tids = sys.argv[2:]
else:
print "Usage: %s username track-id ..." % (sys.argv[0],)
sys.exit()
token = util.prompt_for_user_token(username, scope)
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
results = sp.current_user_saved_tracks_add(ids=tids)
pprint.pprint(results)
else:
print "Can't get token for", username

View File

@ -0,0 +1,27 @@
# Delete a track from 'Your Collection' of saved tracks
import pprint
import sys
import spotipy
import spotipy.oauth2 as oauth2
import util
scope = 'user-library-modify'
if len(sys.argv) > 2:
username = sys.argv[1]
tids = sys.argv[2:]
else:
print "Usage: %s username track-id ..." % (sys.argv[0],)
sys.exit()
token = util.prompt_for_user_token(username, scope)
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
results = sp.current_user_saved_tracks_delete(ids=tids)
pprint.pprint(results)
else:
print "Can't get token for", username

View File

@ -3,7 +3,7 @@ from setuptools import setup
setup( setup(
name='SpotipyWebApi', name='SpotipyWebApi',
version='1.46', version='1.48',
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",

View File

@ -67,11 +67,14 @@ class Spotify(object):
print(verb, r.url) print(verb, r.url)
if not (r.status_code >= 200 and r.status_code < 300): if not (r.status_code >= 200 and r.status_code < 300):
raise SpotifyException(r.status_code, -1, u'the requested resource could not be found: ' + r.url) raise SpotifyException(r.status_code, -1, u'the requested resource could not be found: ' + r.url)
results = r.json() if len(r.text) > 0:
if self.trace: results = r.json()
print('RESP', results) if self.trace:
print() print('RESP', results)
return results print()
return results
else:
return {}
def get(self, method, args=None, **kwargs): def get(self, method, args=None, **kwargs):
if args: if args: