diff --git a/README.md b/README.md index dad3cd0..7e84177 100644 --- a/README.md +++ b/README.md @@ -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_create(self, user, name, public=True)** - Creates a playlist for 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. diff --git a/examples/add_a_saved_track.py b/examples/add_a_saved_track.py new file mode 100644 index 0000000..72686fc --- /dev/null +++ b/examples/add_a_saved_track.py @@ -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 diff --git a/examples/delete_a_saved_track.py b/examples/delete_a_saved_track.py new file mode 100644 index 0000000..97f5c8a --- /dev/null +++ b/examples/delete_a_saved_track.py @@ -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 diff --git a/setup.py b/setup.py index 3d35f16..9bd8486 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name='SpotipyWebApi', - version='1.46', + version='1.48', description='simple client for the Spotify Web API', author="@plamere", author_email="paul@echonest.com", diff --git a/spotipy/__init__.py b/spotipy/__init__.py index a011c2e..c7e884d 100644 --- a/spotipy/__init__.py +++ b/spotipy/__init__.py @@ -67,11 +67,14 @@ class Spotify(object): print(verb, r.url) 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) - results = r.json() - if self.trace: - print('RESP', results) - print() - return results + if len(r.text) > 0: + results = r.json() + if self.trace: + print('RESP', results) + print() + return results + else: + return {} def get(self, method, args=None, **kwargs): if args: