【问题标题】:Finding if a song exists by the name of a given input text通过给定输入文本的名称查找歌曲是否存在
【发布时间】:2016-05-18 23:01:05
【问题描述】:

我正在开发一个应用程序,它允许用户输入一些文本作为歌曲名称和另一个输入作为艺术家姓名,然后将检查是否存在与这两个输入参数匹配的歌曲。我目前通过使用此端点查询歌曲“Get In The Game”来使用 Spotify 的 API:

https://api.spotify.com/v1/search?q=get%20in%20the%20game&type=track

但是,Spotify 的 API 不允许同时使用歌曲名称和艺术家姓名来过滤结果。结果,上面的查询返回了与Get in the Game 歌曲标题匹配的所有歌曲的列表。

如何根据歌曲和艺人姓名判断歌曲是否存在?

【问题讨论】:

    标签: python python-2.7 spotify


    【解决方案1】:

    您可以使用last.fm API,特别是track.getInfo Endpoint。这让您可以同时指定artisttrack

    成功时(您也可以请求 json 响应),您会得到如下信息:

    <lfm status="ok">
        <track>
            <name>Shine on You Crazy Diamond</name>
            <mbid>cb20321d-ecda-4fc1-a32a-0439a096a1bc</mbid>
            <url>
                http://www.last.fm/music/Pink+Floyd/_/Shine+on+You+Crazy+Diamond
            </url>
            <duration>763000</duration>
            <streamable fulltrack="0">0</streamable>
            <listeners>256400</listeners>
            <playcount>1511578</playcount>
            <artist>
                <name>Pink Floyd</name>
                <mbid>83d91898-7763-47d7-b03b-b92132375c47</mbid>
                <url>http://www.last.fm/music/Pink+Floyd</url>
            </artist>
            ...
        </track>
    </lfm>
    

    当找不到歌曲时:

    <lfm status="failed">
        <error code="6">Track not found</error>
    </lfm>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多