在 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 张专辑
请您参考如下方法:
我尝试了 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偷了那个并且刚刚恢复了所有艺术家。
这对你有用吗?
