3

使用 Spotify API,我正在尝试搜索艺术家的曲目。我使用的查询正在运行,看起来像:

https://api.spotify.com/v1/search?q=track:' + song + '%20artist:' + artist + '&type=track&limit=10

它正在工作,但是它正在为包含艺术家姓名字符串的任何部分中提供的艺术家姓名的艺术家返回曲目。例如,如果我想明确艺术家姓名,并想在 ZHU 的曲目中进行搜索,我找不到应该如何进行查询的方法,所以它会明确艺术家姓名。

正如我所说,如果我要搜索朱的曲目,它也会返回我娜塔莉朱的曲目。

明确艺术家姓名的正确方法是什么?

有没有办法明确定义我要搜索 ZHU 的曲目?


编辑:我也尝试使用引号:

https://api.spotify.com/v1/search?q=track:"' + song + '"%20artist:"' + artist + '"&type=track&limit=10

也许我用错了,我不确定,但如果我没有,这似乎无法解决:/

4

3 回答 3

1

目前似乎没有办法明确搜索单个艺术家的曲目。正如您所做的那样,您只能按名称限制艺术家,但这样做的缺点是可能包括其他艺术家的曲目,其名称中包含预期艺术家的姓名,正如您所解释的那样。解决此问题的唯一方法是过滤返回的结果并在必要时获取更多结果。

我在 Soptify API 问题跟踪器 Github 存储库中打开了一个关于此的问题,但到目前为止,还没有关于实现的信息。

于 2017-06-01T16:32:06.383 回答
0

https://developer.spotify.com/web-api/search-item/

曲目对象(完整)部分下,歌曲标题的关键字不是“曲目”而是“名称”。

https://api.spotify.com/v1/search?q=name:' + song + '%20artist:' + artist + '&type=track&limit=10
于 2017-04-09T21:11:43.277 回答
-1

我发现了一项围绕查询结果进行迭代的工作,直到您找到与您正在搜索的艺术家姓名完全匹配的内容。在 20 位限制下,我从我正在寻找的 2280 位艺术家中得到了 2269 位。使用 Spotipy 库。

 
        artist = "ZHU"
        search_results = sp.search(artist, 20, 0, "artist")
        if len(search_results['artists']['items']) != 0:
            total = len(search_results['artists']['items'])
            z = 0
            artist_info = search_results['artists']['items'][z]
            name = artist_info['name']
            while name != artist:
                z += 1
                artist_info = search_results['artists']['items'][z]
                name = artist_info['name']
                if z+1 == total:
                    break
                
于 2020-09-24T18:13:53.503 回答