mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-04 23:17:48 +00:00
Added top lists support
This commit is contained in:
parent
4cf7a8ab90
commit
dd021c4087
@ -97,6 +97,7 @@ class Spotify(object):
|
|||||||
|
|
||||||
if self.trace: # pragma: no cover
|
if self.trace: # pragma: no cover
|
||||||
print()
|
print()
|
||||||
|
print ('headers', headers)
|
||||||
print ('http status', r.status_code)
|
print ('http status', r.status_code)
|
||||||
print(method, r.url)
|
print(method, r.url)
|
||||||
if payload:
|
if payload:
|
||||||
@ -548,29 +549,27 @@ class Spotify(object):
|
|||||||
tlist = [self._get_id('track', t) for t in tracks]
|
tlist = [self._get_id('track', t) for t in tracks]
|
||||||
return self._put('me/tracks/?ids=' + ','.join(tlist))
|
return self._put('me/tracks/?ids=' + ','.join(tlist))
|
||||||
|
|
||||||
def current_user_top_artists(self, limit=20, offset=0, time_range='6-months'):
|
def current_user_top_artists(self, limit=20, offset=0, time_range='medium_term'):
|
||||||
''' Get the current user's top artists
|
''' Get the current user's top artists
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- limit - the number of entities to return
|
- limit - the number of entities to return
|
||||||
- offset - the index of the first entity to return
|
- offset - the index of the first entity to return
|
||||||
- time_range - Over what time frame are the affinities computed.
|
- time_range - Over what time frame are the affinities computed.
|
||||||
Valid-values: all-time, 6-months, 14-days. Default: 6-months
|
Valid-values: short_term, medium_term, long_term
|
||||||
'''
|
'''
|
||||||
return self._get('me/toplists/artists', args={'time-range':time_range},
|
return self._get('me/top/artists', time_range=time_range, limit=limit,offset=offset)
|
||||||
limit=limit,offset=offset)
|
|
||||||
|
|
||||||
def current_user_top_tracks(self, limit=20, offset=0, time_range='6-months'):
|
def current_user_top_tracks(self, limit=20, offset=0, time_range='medium_term'):
|
||||||
''' Get the current user's top tracks
|
''' Get the current user's top tracks
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- limit - the number of entities to return
|
- limit - the number of entities to return
|
||||||
- offset - the index of the first entity to return
|
- offset - the index of the first entity to return
|
||||||
- time_range - Over what time frame are the affinities computed.
|
- time_range - Over what time frame are the affinities computed.
|
||||||
Valid-values: all-time, 6-months, 14-days. Default: 6-months
|
Valid-values: short_term, medium_term, long_term
|
||||||
'''
|
'''
|
||||||
return self._get('me/toplists/tracks', args={'time-range':time_range},
|
return self._get('me/top/tracks', time_range=time_range, limit=limit,offset=offset)
|
||||||
limit=limit,offset=offset)
|
|
||||||
|
|
||||||
|
|
||||||
def featured_playlists(self, locale=None, country=None,
|
def featured_playlists(self, locale=None, country=None,
|
||||||
|
@ -126,6 +126,16 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
artists = response['artists']
|
artists = response['artists']
|
||||||
self.assertTrue(len(artists['items']) > 0)
|
self.assertTrue(len(artists['items']) > 0)
|
||||||
|
|
||||||
|
def test_current_user_top_tracks(self):
|
||||||
|
response = spotify.current_user_top_tracks()
|
||||||
|
items = response['items']
|
||||||
|
self.assertTrue(len(items) > 0)
|
||||||
|
|
||||||
|
def test_current_user_top_artists(self):
|
||||||
|
response = spotify.current_user_top_artists()
|
||||||
|
items = response['items']
|
||||||
|
self.assertTrue(len(items) > 0)
|
||||||
|
|
||||||
def get_or_create_spotify_playlist(self, username, playlist_name):
|
def get_or_create_spotify_playlist(self, username, playlist_name):
|
||||||
playlists = spotify.user_playlists(username)
|
playlists = spotify.user_playlists(username)
|
||||||
while playlists:
|
while playlists:
|
||||||
@ -183,7 +193,8 @@ if __name__ == '__main__':
|
|||||||
scope += 'user-library-read '
|
scope += 'user-library-read '
|
||||||
scope += 'user-follow-read '
|
scope += 'user-follow-read '
|
||||||
scope += 'user-library-modify '
|
scope += 'user-library-modify '
|
||||||
scope += 'user-read-private'
|
scope += 'user-read-private '
|
||||||
|
scope += 'user-top-read'
|
||||||
|
|
||||||
token = util.prompt_for_user_token(username, scope)
|
token = util.prompt_for_user_token(username, scope)
|
||||||
spotify = spotipy.Spotify(auth=token)
|
spotify = spotipy.Spotify(auth=token)
|
||||||
|
Loading…
Reference in New Issue
Block a user