diff --git a/README.md b/README.md index fb2a188..d7ebb87 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,9 @@ A full set of examples can be found in the [Spotipy examples directory](https:// - **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 + - **current_user_saved_tracks_delete(self, tracks)** - Remove tracks from the current authorized user's "Your Music" library + - **current_user_saved_tracks_add(self, tracks)** - Add tracks to the current authorized user's "Your Music" library + - **current_user_saved_tracks_contains(self, tracks)** - Check if one or more tracks is already saved in the current Spotify 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/contains_a_saved_track.py b/examples/contains_a_saved_track.py new file mode 100644 index 0000000..6155fad --- /dev/null +++ b/examples/contains_a_saved_track.py @@ -0,0 +1,25 @@ +import pprint +import sys + +import spotipy +import spotipy.oauth2 as oauth2 +import util + +scope = 'user-library-read' + +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_contains(ids=tids) + pprint.pprint(results) +else: + print "Can't get token for", username \ No newline at end of file diff --git a/spotipy/__init__.py b/spotipy/__init__.py index c7e884d..009d5a2 100644 --- a/spotipy/__init__.py +++ b/spotipy/__init__.py @@ -272,6 +272,13 @@ class Spotify(object): tlist = [self._get_id('track', t) for t in ids] return self.put('me/tracks/?ids=' + ','.join(tlist)) + def current_user_saved_tracks_contains(self, ids=[]): + ''' Check if one or more tracks is already saved in + the current Spotify user’s “Your Music” library. + ''' + tlist = [self._get_id('track', t) for t in ids] + return self.get('me/tracks/contains?ids=' + ','.join(tlist)) + def _get_id(self, type, id): fields = id.split(':') if len(fields) == 3: