Spotify方法artist_albums()不会返回艺术家的所有专辑

时间:2019-02-04 13:55:06

标签: python spotify spotipy

来自Spotipy示例脚本artist_albums.py,我使用以下代码片段从某个艺术家那里获取了所有专辑。但是我注意到artist_albums()不会返回该艺术家的所有专辑。

我已经尝试了album_type和limit参数。但这无济于事。

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))

就我而言,Spotify应用程序中有60多个专辑,但在我的Python脚本中artis_album()仅返回41个专辑

1 个答案:

答案 0 :(得分:1)

我尝试了4位不同的艺术家,他们似乎都可以正常工作。

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)

我无情地从the spotipy first example那里偷走了那个,然后才恢复了所有的艺术家。

对您有用吗?