This article is a work in progress, I will continue to update it as I advance through the project. GitHub Repository.
(Last updated: Feb 24 2022)
In my previous life as an international marketing manager in the music industry, I often had to fill in forms with information that would be used for pitching to DSPs. There was usually a field for “mood playlists”; if we didn’t get any specific direction on what to target, we would listen to the music and use our intuition to select a few moods that we think fit the song.
I always wondered if there was a more data-driven way to address this. Maybe we were selecting a playlist mood that the service providers would never pick for this track because of their algorithms? Maybe we can strengthen our pitches if we know how to target our tracks?
There is one fault for real-life application and that is this project will be using track features that Spotify has created and made available in their API. As far as I know you can’t get that information until after the song is out on the platform and therefore way beyond the deadline for pitching. Nevertheless, the idea interests me so I’m going to go ahead.
My objectives for this project are to:
- Predict what “mood” a track is based on its features
- Mood: the mood/activity you would do with this track. For example: party, drive, dining.
- Track features: features created by Spotify. For example: danceability, energy, loudness, speechiness, tempo, and more.
The data for this project is acquired through the Spotify public API. It is a bit more fiddly than other API’s, I used the following guide to get set up.
My first step was to pull the list of territories that Spotify is currently operating in, this is to help me pull a global snapshot for future pulls. I could have done a quick for loop to save these into a list variable, but frankly a copy and paste was faster.
My second step was to pull the list of the playlist categories Spotify has. Interestingly they’ve decreased the number of categories, the first time I pulled from this API there were 42 and now there are only 20. In order to avoid any biases, I won’t be working with any genre categories and will stick to more activity-based categories. These are:
- At Home
(Digression: there used to be categories for “in the car” and “travel” — I wonder if those have been removed because of safety concerns and the pandemic?)
Now we get to the good stuff, using the categories and country id’s I have pulled I can now get to playlist and track data. Using a for loop, I loop through the countries and create a database of all playlist names and ids for each category. Then, I repeat this going through all of the playlist ids and grab the playlist follower count and track list (uri and id for each track). Finally, using the track data I grab the track features for the tracks. All of the above will create duplicates but we’ll deal with those later, for now the task is to pull everything we need from the API. This is a bit time consuming as the Spotify API does have a rate limit, since I’m not working to a deadline I didn’t use a sleep timer and instead whenever I hit the limit I used it as a prompt to get up and walk around a bit.
I would love to hear any feedback or questions you may have as I continue my learning journey. Feel free to leave a comment here or contact me on LinkedIn.