搜索艺术家的曲目 - Spotify API

时间:2016-12-12 22:47:22

标签: api search spotify spotify-app

使用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

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

3 个答案:

答案 0 :(得分:0)

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

曲目对象(完整)部分下,歌曲标题的关键字不是"曲目"而是" name"。

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

答案 1 :(得分:0)

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

我在Soptify API问题跟踪器Github repo上有opened an issue,但到目前为止,还没有关于实现的信息。

答案 2 :(得分:-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
                
相关问题