Tuesday, January 23, 2018

spotify - Spotipy: How do I search by both artist and song



Given a song title and an artist name, I am trying to find the correct song using Spotipy. However, I do not see a way to search by both song title and artist: it's either one or the other:



   sp.search(q="Money", type="track", limit=10)

sp.search(q="Pink Floyd", type="artist", limit=10)


The problem with this is that I get a bunch of irrelevant results, especially if I search by track(example: top result for money is "Rent Money" by Future not "Money" by Pink Floyd). I could extend the limit and filter out irrelevant results, but considering I'll be doing this on a large scale, I'd rather just query Spotify correctly, take the first result, and move on. Is there any way to query on both track name and artist at the same time using Spotipy?


Answer



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



I think that you're misunderstanding type. I always want to return a track list so type is "track". In other words this defines the type of entities to be returned.



The query filter can be completely generic like "Money" or can be focussed to certain parameters like "artist:Floyd track:Money". This can be immensely powerful as you can look at albums, date fields, popularity and all sorts.




I commonly use
let q = String.init(format:"artist:%@ track:%@",artistName,trackName)



Don't forget to %-encode the string!


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...