是否有某种通用ID用于其API中的spotify轨道?

时间:2017-07-31 16:02:58

标签: spotify

我在Spotify API中为每个音轨寻找某种通用标识符。所以,例如,如果我获取迈克尔·杰克逊的“Thriller”曲目,我会获得所有曲目信息和Spotify自己的唯一标识符,但是当你在杂货店结账并购买香蕉时,我也会获得相当于4011的音乐。 。无论你去哪家商店,总是输入4011购买香蕉。谢谢!

1 个答案:

答案 0 :(得分:2)

你想要的并不存在,但有一个名为ISRC的标识符,它可能与你要求的非常接近。

https://en.wikipedia.org/wiki/International_Standard_Recording_Code

此Spotify曲目与uri spotify:曲目:2LlQb7Uoj1kKyGhlkBf9aC是迈克尔杰克逊的惊悚片。该轨道的ISRC代码是USSM19902989,您可以在Web API中找到它:

$ curl -s -X GET "https://api.spotify.com/v1/tracks/2LlQb7Uoj1kKyGhlkBf9aC" \
       -H "Accept: application/json" \
       -H "Authorization: Bearer <INSERT ACCESS TOKEN>" \
| jq -r .external_ids.isrc
USSM19902989

Yoy可以使用此标识符在Spotify(或其他服务)中通过Michael Jackson查找Thriller。

$ curl -s -X GET "https://api.spotify.com/v1/search?q=isrc%3AUSSM19902989&type=track" \
       -H "Accept: application/json" \
       -H "Authorization: Bearer <INSERT ACCESS TOKEN>" \
| jq -c '.tracks.items[] | {uri, name, album: .album.name, available_markets}'
{"uri":"spotify:track:1D9KEXIrlmPUkMTdYzqgX4","name":"Thriller","album":"Michael Jackson's This Is It","available_markets":["AD","AR","AT","AU","BE","BG","BO","BR","CA","CH","CL","CO","CR","CY","CZ","DE","DK","DO","EC","EE","ES","FI","FR","GB","GR","GT","HK","HN","HU","ID","IE","IS","IT","JP","LI","LT","LU","LV","MC","MT","MX","MY","NI","NL","NO","NZ","PA","PE","PH","PL","PT","PY","SE","SG","SK","SV","TR","TW","US","UY"]}
{"uri":"spotify:track:3S2R0EVwBSAVMd5UMgKTL0","name":"Thriller","album":"Thriller 25 Super Deluxe Edition","available_markets":["AD","AR","AT","AU","BE","BG","BO","BR","CA","CH","CL","CO","CR","CY","CZ","DE","DK","DO","EC","EE","ES","FI","FR","GB","GR","GT","HK","HN","HU","ID","IE","IS","IT","JP","LI","LT","LU","LV","MC","MT","MX","MY","NI","NL","NO","NZ","PA","PE","PH","PL","PT","PY","SE","SG","SK","SV","TR","TW","US","UY"]}
{"uri":"spotify:track:2LlQb7Uoj1kKyGhlkBf9aC","name":"Thriller","album":"Thriller","available_markets":["AD","AR","AU","BE","BG","BO","BR","CA","CL","CO","CR","CY","CZ","DK","DO","EC","EE","ES","FI","FR","GB","GR","GT","HK","HN","HU","ID","IE","IS","IT","JP","LT","LU","LV","MC","MT","MX","MY","NI","NL","NO","NZ","PA","PE","PH","PL","PT","PY","SE","SG","SK","SV","TR","TW","US","UY"]}
{"uri":"spotify:track:6ZntYOZ44LwdrowjJRzvoQ","name":"Thriller","album":"Michael Jackson: The Ultimate Collection","available_markets":[]}

你在这里得到的是迈克尔杰克逊的许多不同的惊悚片。它们可以在不同的市场上买到,来自不同版本的Thriller或Michael Jackson编辑。

ISRC代码USSM19902989可以说是Michael Jackson唯一指向Thriller,但事实恰恰相反。它可能有多个ISRC代码。用你的比喻来说,4011总是指向香蕉,但可能有更多的代码指向相同的香蕉。虽然这听起来不像是一个问题,但事实上确实如此。不同的轨道数据库不包含相同的ISRC。因此,尽管4011总是指向香蕉而不是其他任何东西,但USSM19902989将永远指向惊悚片,而不是别的。但是,在某些商店中,4011并不指向任何东西。

以我在这里描述的方式使用ISRC有效,但有点烦人。如果您只为Spotify用户编写应用程序,使用Spotify Web API,您不需要关心市场可用性或ISRC,并且可以发送spotify跟踪uris。例如,spotify:track:2LlQb7Uoj1kKyGhlkBf9aC似乎在德国不可用。但是,如果德国Spotify用户尝试播放此曲目,他们仍会听到迈克尔杰克逊的惊悚片,因为Spotify会播放另一首可用曲目,例如spotify:track:3S2R0EVwBSAVMd5UMgKTL0。