mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-04 23:17:48 +00:00
Add support for checking if a user's Your Music library contains a track
This commit is contained in:
parent
6d6841d387
commit
a4e6fc5a39
@ -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
|
- **user_playlists(self, user)** - Gets playlists of a user
|
||||||
- **current_user(self)** - Get detailed profile information about the current 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(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_delete(self, tracks)** - 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_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.
|
Refer to the [Spotify API documentation](https://developer.spotify.com/spotify-web-api/) for details on the methods and parameters.
|
||||||
|
|
||||||
|
25
examples/contains_a_saved_track.py
Normal file
25
examples/contains_a_saved_track.py
Normal file
@ -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
|
@ -272,6 +272,13 @@ class Spotify(object):
|
|||||||
tlist = [self._get_id('track', t) for t in ids]
|
tlist = [self._get_id('track', t) for t in ids]
|
||||||
return self.put('me/tracks/?ids=' + ','.join(tlist))
|
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):
|
def _get_id(self, type, id):
|
||||||
fields = id.split(':')
|
fields = id.split(':')
|
||||||
if len(fields) == 3:
|
if len(fields) == 3:
|
||||||
|
Loading…
Reference in New Issue
Block a user