Spotipy - get track ids from track names

房东的猫 提交于 2019-12-10 22:38:47

问题


Usually, spotipy requires track IDs as parameters to be passed, in order to return track names.

Say I have two lists, not obtained from the Spotify API:

  1. artists

    [u'Moses Sumney', u'Cherry Glazerr', u'Danny Brown', u'NxWorries']
    

    and their respective songs:

  2. tracks

    [u'Lonely World', u"Told You I'd Be With the Guys", u'Really Doe [ft. Kendrick Lamar, Ab-Soul, and Earl Sweatshirt]', u'Lyk Dis']
    

Is it possible to do it the other way around and get track IDs?


回答1:


Spotipy.search() is what you are looking for.

import spotipy
sp = spotipy.Spotify()

artist= 'Moses Sumney'
track= 'Lonely World'

track_id = sp.search(q='artist:' + artist + ' track:' + track, type='track')

This will return a list of songs that match the query, depending on how precise your search is will depend on how many results are returned.



来源:https://stackoverflow.com/questions/39840319/spotipy-get-track-ids-from-track-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!