【问题标题】:Spotify method artist_albums() does not return all albums of an artistSpotify 方法 Artist_albums() 不返回艺术家的所有专辑
【发布时间】:2019-02-04 13:55:05
【问题描述】:

来自 Spotipy 示例脚本 artist_albums.py 我使用以下代码 sn-p 从艺术家那里获取所有专辑。但我注意到 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 张专辑

【问题讨论】:

  • artist_albums(artist_id, album_type=None, country=None, limit=20, offset=0) 你能增加第 4 个参数吗?limit=20 参数默认为 20 试试增加?

标签: python spotify spotipy


【解决方案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那里偷了那个,然后把所有的艺术家都找回来了。

这对你有用吗?

【讨论】:

  • 嗨,Marco,谢谢你的代码 sn-p。我的程序中有一个愚蠢的小错误。使用您的代码,我可以检索艺术家的所有专辑。亲切的问候弗洛里安
猜你喜欢
  • 1970-01-01
  • 2015-01-30
  • 1970-01-01
  • 2012-03-30
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
相关资源
最近更新 更多