Added support for 'Your Music' tracks

This commit is contained in:
Paul Lamere
2014-07-23 10:04:07 -04:00
parent 58123eda31
commit 2d98c30d01
3 changed files with 64 additions and 2 deletions

View File

@@ -78,6 +78,16 @@ class Spotify(object):
kwargs.update(args)
return self._internal_call('GET', method, kwargs)
def delete(self, method, args=None, **kwargs):
if args:
kwargs.update(args)
return self._internal_call('DELETE', method, kwargs)
def put(self, method, args=None, **kwargs):
if args:
kwargs.update(args)
return self._internal_call('PUT', method, kwargs)
def post(self, method, payload=None, **kwargs):
args = dict(params=kwargs)
if not method.startswith('http'):
@@ -230,10 +240,35 @@ class Spotify(object):
payload = tracks, position=position)
def me(self):
''' returns info about me
''' Get detailed profile information about the current user.
'''
return self.get('me/')
def current_user(self):
''' Get detailed profile information about the current user.
'''
return self.me()
def 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
'''
return self.get('me/tracks', limit=limit, offset=offset)
def current_user_saved_tracks_delete(self, ids=[]):
''' Remove one or more tracks from the current users
“Your Music” library.
'''
tlist = [self._get_id('track', t) for t in ids]
return self.delete('me/tracks/?ids=' + ','.join(tlist))
def current_user_saved_tracks_add(self, ids=[]):
''' Add one or more tracks to the current users
“Your Music” library.
'''
tlist = [self._get_id('track', t) for t in ids]
return self.put('me/tracks/?ids=' + ','.join(tlist))
def _get_id(self, type, id):
fields = id.split(':')
if len(fields) == 3: