【问题标题】:Extract artist genre and song release date using spotipy使用 spotipy 提取艺术家流派和歌曲发布日期
【发布时间】:2020-08-20 18:48:12
【问题描述】:

我目前正在研究从 Spotify 中的歌曲中提取特定项目。我想从艺术家那里获取具体的发行日期和流派。我正在从看起来像这样的熊猫数据报中提取信息:。 我已经尝试手动完成大部分工作,但是作为大约 1100 首歌曲的数据框,它变得乏味。所以我一直在研究 API 来帮助解决这个问题,特别是 spotipy。 我有一个想法可以开始:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials #To access authorised Spotify data
client_id = 'client_id'
client_secret = 'client_secret'
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) #spotify object to access API
name = "AJR" #chosen artist
result = sp.search(name) #search query
result['tracks']['items'][0]['artists']

但我不知道该去哪里。我试过查看文档,虽然有关于如何从 Spotify For Developers 页面获取流派和日期的信息,但我似乎无法在 spotipy 中找到它。关于从这里去哪里或如何实现算法以获得所需细节的任何建议都会很棒。谢谢。

【问题讨论】:

    标签: python pandas api spotipy


    【解决方案1】:

    Spotify 尚未公开曲目类型。相反,它会显示与艺术家或专辑相​​关的流派列表。

    同样,它不会公开曲目的发行日期,而只会公开整张专辑的单个发行日期。因此,虽然我不确定艺术家是否有可能在专辑发行后将新曲目添加到专辑中,这意味着专辑发行日期可能并不总是指示相应专辑中所有曲目的正确发行日期。

    我已尝试查看文档,虽然有关于如何从 Spotify For Developers 页面获取流派和日期的信息,但我似乎无法在 spotipy 中找到它。

    您需要访问整页对象才能访问艺术家或专辑的流派信息。

    result = sp.search(name)
    result['tracks']['items'][0]['artists']
    

    您从这段代码中得到的不是艺术家的整页对象,这意味着它缺少一些额外的细节,而流派是其中之一。

    您需要单独调用适当的端点来访问全分页对象。例如这段代码:

    result = sp.search("AJR")
    track = result['tracks']['items'][0]
    
    artist = sp.artist(track["artists"][0]["external_urls"]["spotify"])
    print("artist genres:", artist["genres"])
    
    album = sp.album(track["album"]["external_urls"]["spotify"])
    print("album genres:", album["genres"])
    print("album release-date:", album["release_date"])
    

    输出:

    artist genres: ['modern rock']
    album genres: []
    album release-date: 2020-02-12
    

    Spotify 可能不知道某些专辑(如上面的输出)或艺术家的流派。

    【讨论】:

    • 完全不包括专辑类型
    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 2012-09-04
    相关资源
    最近更新 更多