1

我正在构建一个简单的应用程序,用户可以在其中与朋友分享他们正在听的歌曲。如果用户是 Spotify 订阅者,他/她的朋友是 Apple Music 订阅者,并且 Spotify 用户正在分享歌曲,我如何在苹果目录中搜索相同的歌曲?是否有任何通用 ID,例如 Apple Music 上的 ISRC?还是有其他比较方法?我已经知道如何使用搜索歌曲/专辑等。问题是如何确保结果是来自 spotify 的同一首歌曲。有任何想法吗?谢谢!

4

3 回答 3

5

ISRC 代码当然是这里的诀窍。以下是在任一方向搜索的方法:

Spotify 到 Apple Music

curl -g -X "GET" "https://api.music.apple.com/v1/catalog/us/songs?filter[isrc]=ISRC" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer DEVELOPER_TOKEN"

Apple Music 到 Spotify

curl -X "GET" "https://api.spotify.com/v1/search?q=isrc:ISRC&type=track" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer OAUTH_TOKEN"

我在我的Medium上写了更多关于这个的内容。祝你好运!

于 2018-11-02T01:37:18.900 回答
2

根据文档,MusicKit 的歌曲模型没有 ISRC 。iTunes EPF有 ISRC 信息,但这不是 MusicKit API 的一部分。

于 2017-07-29T17:59:30.813 回答
1

I did something similar with one of my projects, so hopefully it can get you on the right track. In short, you can use the iTunes API alongside the Spotify API to search for the same results.

An example in Python.

Get the current playing song/artist with the Spotify API. Search through the response for the information you want, in my case, it was the artist name and album name.

results = sp.currently_playing()
artist = results["item"]["album"]["artists"][0]["name"]
album = results["item"]["album"]["name"]

Look it up with the iTunes API.

i_artist = itunes.search_album(album, artist)[0]

You'll have to learn how the API's work. With iTunes, a search results in a list of results. I'm taking my chances and just grabbing the first one (the most popular). But you can certainly filter through them to make sure it matches what you want. You'll obviously run into things like artists having the same album titles, or even sharing the same name.

It looks like your target platform is iOS, but my code should be a starting point. It's just a matter of saving the information from one platform into variables, and the searching then next one with them.

Hopefully I understood your question correctly, I can expand or provide more code if needed.

于 2017-08-02T23:36:51.383 回答