【问题标题】:Searching in an artist's tracks - Spotify API搜索艺术家的曲目 - Spotify API
【发布时间】:2017-04-27 22:00:36
【问题描述】:

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

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

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

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

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

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


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

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

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

【问题讨论】:

  • 把歌曲或艺术家的名字放在引号里。 developer.spotify.com/web-api/search-item
  • 我试过了,但没有任何区别。也许我做错了。 https://api.spotify.com/v1/search?q=track:"' + song + '"%20artist:"' + artist + '"&type=track&limit=10。这是正确的方法吗?还是我做错了什么?如果我做对了,那就不能解决问题:/

标签: api search spotify spotify-app


【解决方案1】:

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

我在 Soptify API 问题跟踪器 Github 存储库中有 opened an issue 关于此的信息,但到目前为止,还没有关于实施的信息。

【讨论】:

    【解决方案2】:

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

    track object (full)部分下,歌曲标题的关键字不是“track”而是“name”。

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

    【讨论】:

      【解决方案3】:

      我发现了一项围绕查询结果进行迭代的工作,直到找到与您正在搜索的艺术家姓名完全匹配的结果。在 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
                      
      

      【讨论】:

      • 因为您正式发布了对较早问题的答案。如果您使用一些代码和使用您的代码产生的输出来支持您声称的答案,这将是最有帮助的。
      猜你喜欢
      • 1970-01-01
      • 2013-04-11
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 2012-11-21
      相关资源
      最近更新 更多