我想使用spotify api获取艺术家的所有专辑。我认为可以通过两种方法来实现此目的:卷曲api网址,或使用Spotipy python api(https://spotipy.readthedocs.io/en/latest/)。我一直在使用Spotipy API,但在获取像New Order(spotify:artist:0yNLKJebCb8Aueb54LYya3)之类的大型唱片发行人的所有发行版时遇到困难
如果我这样请求:
token = util.oauth2.SpotifyClientCredentials(client_id="5a**********0478", client_secret="06c0a2b*******2aabe893")
cache_token = token.get_access_token()
spotify = spotipy.Spotify(cache_token)
newOrderURI = "spotify:artist:0yNLKJebCb8Aueb54LYya3"
artistAlbums = spotify.artist_albums(newOrderURI)
artistAlbums的价值如下:
{
"href": "https: //api.spotify.com/v1/artists/0yNLKJebCb8Aueb54LYya3/albums?offset=0&limit=20&include_groups=album,single,compilation,appears_on",
"items": [
{
"album_group": "album",
"album_type": "album",
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/0yNLKJebCb8Aueb54LYya3"
},
"href": "https://api.spotify.com/v1/artists/0yNLKJebCb8Aueb54LYya3",
"id": "0yNLKJebCb8Aueb54LYya3",
"name": "New Order",
"type": "artist",
"uri": "spotify:artist:0yNLKJebCb8Aueb54LYya3"
}
],
"available_markets": [
"CA",
"US"
],
"external_urls": {
"spotify": "https://open.spotify.com/album/3tVxsOv2aTeaF3zsuWsd3e"
},
"href": "https://api.spotify.com/v1/albums/3tVxsOv2aTeaF3zsuWsd3e",
"id": "3tVxsOv2aTeaF3zsuWsd3e",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b27376ca654fa945d476a2a4d5cb",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e0276ca654fa945d476a2a4d5cb",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/ab67616d0000485176ca654fa945d476a2a4d5cb",
"width": 64
}
],
"name": "∑(No,12k,Lg,17Mif) New Order + Liam Gillick: So it goes.. (Live at MIF)",
"release_date": "2019-07-12",
"release_date_precision": "day",
"total_tracks": 18,
"type": "album",
"uri": "spotify:album:3tVxsOv2aTeaF3zsuWsd3e"
},
{
"album_group": "album",
"album_type": "album",
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/0yNLKJebCb8Aueb54LYya3"
},
"href": "https://api.spotify.com/v1/artists/0yNLKJebCb8Aueb54LYya3",
"id": "0yNLKJebCb8Aueb54LYya3",
"name": "New Order",
"type": "artist",
"uri": "spotify:artist:0yNLKJebCb8Aueb54LYya3"
}
],
"available_markets": [
"JP"
],
"external_urls": {
"spotify": "https://open.spotify.com/album/3tC3rPZOFRoTCFcvDegigj"
},
"href": "https://api.spotify.com/v1/albums/3tC3rPZOFRoTCFcvDegigj",
"id": "3tC3rPZOFRoTCFcvDegigj",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b273c841b10966ce9d95bef0a43e",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e02c841b10966ce9d95bef0a43e",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/ab67616d00004851c841b10966ce9d95bef0a43e",
"width": 64
}
],
"name": "Music Complete",
"release_date": "2015",
"release_date_precision": "year",
"total_tracks": 5,
"type": "album",
"uri": "spotify:album:3tC3rPZOFRoTCFcvDegigj"
}
],
"limit": 20,
"next": "https://api.spotify.com/v1/artists/0yNLKJebCb8Aueb54LYya3/albums?offset=20&limit=20&include_groups=album,single,compilation,appears_on",
"offset": 0,
"previous": None,
"total": 174
}
我从items []列表中删除了很多条目,因此在此问题中更容易阅读,但基本上每个项目条目都是一张专辑/发行版,但一个请求并没有艺术家的所有发行版。最后的'next'字符串使我认为去那会给我剩下的artis专辑,但我认为我不能要求使用Spotipy python库。
我的问题是,我该如何使用Spotipy库尽快获取歌手的每个发行版本?任何帮助表示赞赏。谢谢
答案 0 :(得分:0)
明白了:
while results['next']:
results = spotify.next(results)
albums.extend(results['items'])
for album in albums:
print(album['name'])