我正在构建一个简单的应用程序,用户可以在其中与朋友分享他们正在听的歌曲。如果用户是 Spotify 订阅者,他/她的朋友是 Apple Music 订阅者,并且 Spotify 用户正在分享歌曲,我如何在苹果目录中搜索相同的歌曲?是否有任何通用 ID,例如 Apple Music 上的 ISRC?还是有其他比较方法?我已经知道如何使用搜索歌曲/专辑等。问题是如何确保结果是来自 spotify 的同一首歌曲。有任何想法吗?谢谢!
3 回答
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上写了更多关于这个的内容。祝你好运!
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.