2

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

ryyker
  • 22,849
  • 3
  • 43
  • 87
flotux
  • 53
  • 1
  • 4
  • `artist_albums(artist_id, album_type=None, country=None, limit=20, offset=0)` can you increase the 4th parameter that has limit=20 parameter with default 20 try increasing that? – Samer Tufail Feb 04 '19 at 14:02

1 Answers1

2

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?

marcogemaque
  • 461
  • 6
  • 14
  • 1
    Hi Marco, thanks for you code snippet. I had a stupid small error in my program. Using your code I could retrieve all the albums of the artist. Kind regards Florian – flotux Feb 09 '19 at 21:41