Andrej
Andrej

Reputation: 21

Filter Spotify IDs by audio feature

I am trying to filter audio features by item, getting back an array of Spotify IDs. E.g. I would like to receive an array of Spotify IDs of all songs with a danceability between 0.735 and 0.740. I think that this was possible in the old Echo Nest API. Is there still a way of doing this in the new Web-Api?

Upvotes: 2

Views: 855

Answers (2)

arirawr
arirawr

Reputation: 1275

The closest functionality to what you're looking for is the Get Recommendations Based on Seeds endpoint. The documentation for that is here: https://developer.spotify.com/web-api/get-recommendations/

You give the endpoint up to 5 "seeds", which are tracks, artists, or genres you want the recommendations to be based upon. Then, you can specify minimum, maximum, and/or target values for several fields which correspond to the Audio Features. For example, you could get recommendations with a min_danceability of 0.7 and a max_danceability of 0.8.

You can check out a demo of the endpoint in action here.

Hope that helps for your use case!

Upvotes: 1

Rach Sharp
Rach Sharp

Reputation: 2444

I don't think this is possible to do directly through the Web API I'm afraid.

The two relevant endpoints are:

You can search on tracks using keywords, such as genre:"Pop" but this doesn't work for the audio feature names (e.g. tempo:120/tempo:"120"). The audio features endpoints require that you provide track IDs.

If you can identify track IDs for which you might want to search using audio features, by some other method (e.g. you could get all the track IDs for all artists in a genre), you could do something like the following:

  • Get a collection of Track IDs you want to search on
  • For each 100 track IDs, query the 'Get audio features for several tracks' endpoint to get the audio features you want to filter using
  • Select a subset of tracks from your collection by using conditional logic based on those audio features

Upvotes: 0

Related Questions