簡體   English   中英

spotipy spotify python api 獲取藝術家的所有版本

[英]spotipy spotify python api get all of an artist's releases

我想使用 Spotify api 來獲取藝術家的所有版本。 我認為有兩種方法可以做到這一點,通過卷曲 api url,或使用 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[] 列表中刪除了很多條目,因此在這個問題中更容易閱讀,但基本上每個條目都是一張專輯/發行版,但一個請求並不包含藝術家的所有發行版。 最后的“下一個”字符串讓我覺得去那會給我剩下的藝術家專輯,但我認為我不能要求使用spotipy python庫。

所以我的問題是,如何使用 spotipy 庫盡快從藝術家那里獲得每個版本? 任何幫助表示贊賞。 謝謝你

知道了:

    while results['next']:
    results = spotify.next(results)
    albums.extend(results['items'])

for album in albums:
    print(album['name'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM