Reputation: 73
from the Spotipy example script artist_albums.py I used the following code snippet to get all albums from an artist. But I noticed that artist_albums() does not return all albums of the artist.
I already experimented with the album_type and limit parameters. But that doesn't help.
albums = []
results = sp.artist_albums(artist['id'], album_type='album')
albums.extend(results['items'])
while results['next']:
results = sp.next(results)
albums.extend(results['items'])
albums.sort(key=lambda album:album['name'].lower())
for album in albums:
name = album['name']
print((' ' + name))
In my case there are over 60 albums available inside the Spotify app but in my Python script artis_album() return only 41 albums
Upvotes: 4
Views: 512
Reputation: 481
I tried it with 4 different artists and they all seem to work just fine.
beatles_uri = 'spotify:artist:3WrFJ7ztbogyGnTHbHJFl2'
glass_uri = 'spotify:artist:4yvcSjfu4PC0CYQyLy4wSq'
metallica_uri = 'spotify:artist:2ye2Wgw4gimLv2eAKyk1NB'
arctic_uri = '7Ln80lUS6He07XvHI8qqHH'
list_artists = [beatles_uri,glass_uri,metallica_uri,arctic_uri]
def get_albums(name):
results = sp.artist_albums(name,album_type='album')
albums = results['items']
while results['next']:
results = sp.next(results)
albums.extend(results['items'])
for album in albums:
print(album['name'])
print('END OF LIST')
for artist in list_artists:
get_albums(artist)
I mercilessly stole that one from the spotipy first example and just recovered all the artists.
Does that work for you?
Upvotes: 2