mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-05 07:27:47 +00:00
added current_user_saved_albums_add()
This commit is contained in:
parent
6cbc3586a3
commit
f683535165
27
examples/add_a_saved_album.py
Normal file
27
examples/add_a_saved_album.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
# Add tracks to 'Your Collection' of saved tracks
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import spotipy
|
||||||
|
import spotipy.util as util
|
||||||
|
|
||||||
|
scope = 'user-library-modify'
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
username = sys.argv[1]
|
||||||
|
aids = sys.argv[2:]
|
||||||
|
else:
|
||||||
|
print("Usage: %s username album-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_albums_add(albums=aids)
|
||||||
|
pprint.pprint(results)
|
||||||
|
else:
|
||||||
|
print("Can't get token for", username)
|
@ -660,6 +660,16 @@ class Spotify(object):
|
|||||||
return self._get('me/top/tracks', time_range=time_range, limit=limit,
|
return self._get('me/top/tracks', time_range=time_range, limit=limit,
|
||||||
offset=offset)
|
offset=offset)
|
||||||
|
|
||||||
|
def current_user_saved_albums_add(self, albums=[]):
|
||||||
|
''' Add one or more albums to the current user's
|
||||||
|
"Your Music" library.
|
||||||
|
Parameters:
|
||||||
|
- albums - a list of album URIs, URLs or IDs
|
||||||
|
'''
|
||||||
|
alist = [self._get_id('album', a) for a in albums]
|
||||||
|
r = self._put('me/albums?ids=' + ','.join(alist))
|
||||||
|
return r
|
||||||
|
|
||||||
def featured_playlists(self, locale=None, country=None, timestamp=None,
|
def featured_playlists(self, locale=None, country=None, timestamp=None,
|
||||||
limit=20, offset=0):
|
limit=20, offset=0):
|
||||||
''' Get a list of Spotify featured playlists
|
''' Get a list of Spotify featured playlists
|
||||||
|
Loading…
Reference in New Issue
Block a user