Unlocking the Secrets of Songwriting with Spotify’s Web API

Cameron Pollart
6 min readApr 15, 2021

Odds are that if you’re a songwriter, artist or musician of any kind, you’ve at one point asked yourself the question: “How would I write a hit pop song?” Would you make an up-tempo feel-good dance track, or go for a somber yet powerful ballad? Would you keep it short and sweet at two and a half minutes, or would you try to break the mold by incorporating spoken word and live instrumentation?

Songwriters of years past would have to rely on things like ‘music theory’ and ‘inspiration’ to craft a hit song, but no longer are we beholden to such outdated methods. Together with a little help from Spotify’s open source web API (as well as data scraping with Python and visualizations with Tableau), we’re going to take an analytical look at some of the most successful artists from years past and present by breaking their songs down into measurable metrics, to see if we can answer the question of how to write a hit in the nerdiest way possible. Let’s begin with some of the biggest all star artists of all time!

So what are we looking at here? Using a dataset of top 100 songs from 1950–2009, we filtered the results to the top 5 artists with the most hits across all decades, giving us ABBA, Elvis, Madonna, The Beatles and the Stones. Then we took these artists’ hits and broke down their average scores on a variety of metrics provided by Spotify, which you can think of like invisible points that Spotify gives each song based on different features the song has. If you have songs on Spotify, those songs have scores on these metrics, from 0.0 to 1.0. But what are these metrics anyway, and what do the scores mean?

Looking at our bar chart we can see that some metrics don’t matter much when it comes to writing hit songs, like Speechiness (spoken-word), Instrumentalness (vocals-less music), and Acousticness (non-electric instrumentation), though that last one charts pretty high for our oldest artist in the top 5, Elvis. The King of Rock ‘n’ Roll aside, low scores for these metrics simply mean that they are not heavily present in most pop music. But its not exactly rocket science to observe that most pop music lacks spoken word and acoustic strumming. What we’re interested in are the big-3 metrics with high average scores across all our hit songs: Valence, Danceability, and Energy.

Valence in laymen’s terms refers to a song’s mood; high score means happy, low score means sad or angry. And just like with the classics, high Valence scores are prevalent across modern pop hits as well. Below we have the top 5 tracks from the last decade as judged by their Valence score.

No surprises here when it comes to the famously cheery Happy by Pharell, and same goes for the middle-school dance staple of 2015, Watch Me (Whip / Nae Nae) by Silento. The inclusion of Pumped Up Kicks is noteworthy though due to its unique combination of a catchy beat paired with surprisingly depressing lyrics, a la Hey Ya! by Outkast. If your reaction to that comparison was to ask yourself “Wait what’s depressing about Hey Ya?”, then congratulations! You now understand that lyrics matter surprisingly little when it comes to putting people in a good mood with your music. And in case you were wondering Hey Ya!, a song about staying in an unhappy relationship for no good reason, sits at a cool 0.965 on the Valence scale.

Danceability is exactly what it sounds like, a metric defined by how well your music gets people off the wall. Again looking at the biggest hits of the last decade, lets see what the data tells us.

What the…rap music?! Where’s Get Lucky? One Dance? Say So? According to Spotify none of these four-on-the-floor dance tracks are anywhere near as danceable as Gucci Gang by Lil Pump. So what do we do with this bewildering information? One thing important to note here is the absolute dominance that rap has seen on the pop charts since the midpoint of the last decade, where-in rap and pop became ever-less distinguishable. When 16-bar verses officially replaced guitar solos, rap evolved the standard of what we consider to be popular music, so we in turn should allow rap to evolve our understanding of danceability. After all, one of the defining elements of early hip-hop was breakdancing. The lesson? Don’t let pop standards of the past warp your understanding of the trends that today’s listeners are following.

Energy is not the easiest metric to understand at a glance, but its importance as an element in popular music shouldn’t be understated. Not all pop songs are fast and loud, but thanks to professional production standards the majority have enough going on to qualify as ‘energetic’.

If our data makes one thing clear, its that anyone attempting to make a high energy song can never layer on enough synths. Gangnam Style may be the only song here that most will recognize, and Linkin Park certainly has a proven history of being high energy, but the common theme among all these songs is that they came out around 2010. A time when EDM was just beginning to dominate popular music, we saw many producers of this era try to replicate that genre’s high energy, heavily synthesized sound. While I don’t necessarily see that sound returning anytime soon, our most high-energy songs all being a decade old points towards a niche currently left unfulfilled in the modern popular music market.

So, dear artist, will you fill that niche? Or do you see this as an obvious indication that big synths are out? Will you push the boundaries of hip hop and dance, or keep things old school and try to start the next Disco-sized wave? Will you focus more on lyrics or melody with your next single? Is that 2011 Dr. Dre song you’ve never heard of worth checking out? Asking yourself difficult questions is the key to evolving as an artist, so hopefully this breakdown has helped move you along that path and encouraged you to think more analytically about the music that inspires you. And in case you were wondering, the answer to that last question is…no.

--

--