diff --git a/spotipy/client.py b/spotipy/client.py index ff12ee4..d0636d8 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -97,6 +97,7 @@ class Spotify(object): if self.trace: # pragma: no cover print() + print ('headers', headers) print ('http status', r.status_code) print(method, r.url) if payload: @@ -548,29 +549,27 @@ class Spotify(object): tlist = [self._get_id('track', t) for t in tracks] 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 Parameters: - limit - the number of entities to return - offset - the index of the first entity to return - 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}, - limit=limit,offset=offset) + return self._get('me/top/artists', time_range=time_range, 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 Parameters: - limit - the number of entities to return - offset - the index of the first entity to return - 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}, - limit=limit,offset=offset) + return self._get('me/top/tracks', time_range=time_range, limit=limit,offset=offset) def featured_playlists(self, locale=None, country=None, diff --git a/tests/authtests.py b/tests/authtests.py index 6502abd..540db5f 100644 --- a/tests/authtests.py +++ b/tests/authtests.py @@ -126,6 +126,16 @@ class AuthTestSpotipy(unittest.TestCase): artists = response['artists'] 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): playlists = spotify.user_playlists(username) while playlists: @@ -183,7 +193,8 @@ if __name__ == '__main__': scope += 'user-library-read ' scope += 'user-follow-read ' scope += 'user-library-modify ' - scope += 'user-read-private' + scope += 'user-read-private ' + scope += 'user-top-read' token = util.prompt_for_user_token(username, scope) spotify = spotipy.Spotify(auth=token)