问题
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:
artists
[u'Moses Sumney', u'Cherry Glazerr', u'Danny Brown', u'NxWorries']
and their respective songs:
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