SPG Development

Jackie Chan
3 min readJul 13, 2021

A service I use multiple times daily is Spotify. I’m a bit of a music lover, with tastes ranging from classical to metal to dubstep. Many Spotify users would know that Spotify likes to generate a “Discover Weekly” playlist, composed of tunes that their algorithm thinks the user will enjoy, based off “liked” songs. The platform also creates playlists that encompass similar genres in the user’s music library. For the most part, Spotify does a good job with their playlist creation. But occasionally I want to hear some specific tunes from specific artists, which isn’t something Spotify really allows me to do without manually creating a playlist and adding songs one by one. Thus, Spotify Playlist Generator (SPG)was conceived.

When I first came up with the idea for SPG, I had experience with Python. I wrote the first version to work entirely in the terminal, but some challenges quickly arose. In order to access and build playlists for a user, the app needs to use OAuth to login and grab access and refresh tokens. Without owning a domain or having any way to access Spotify’s callbacks, I had to manually trace the request redirects and parse the URLs for tokens. And even then, this only gave me the access token, which would expire after an hour. To keep access tokens alive, I also needed the refresh token, which I grabbed through yet another manual API call. In short, this process was extremely tedious and completely unscalable.

Over time, I picked up some Node.js and Express experience. I realized this would provide a platform to build SPG on, a platform that actually had some sort of associated frontend, domain and database. Node also tends to run much more quickly than Python does, already a good enough reason on its own to rebuild the app. Unfortunately, working with async and promises is not something I was particularly good at. I struggled to deal with a large number of errors as I stumbled my way through learning asynchronous programming languages. A lot of work was also put into understanding exactly how Spotify’s OAuth flow works. The documentation is quote thorough but alas, I am a new programmer and many of the terms went over my head. With a large amount of experimentation, I was able to get login working. Since I was most scared of this part of the project, I made sure to finish it first before moving on to the code to actually generate playlists.

I have no interest in developing frontends, so Express and Handlebars gave me a great way to weasel my way out of writing much more than basic HTML and JQuery. I should also mention that I had zero JQuery experience coming into this project, and learned a bit of it with the help of my teammate. Thankfully, my teammate was much more enthused with JQuery and took it upon himself to stylize and add some functions to the frontend like search autocomplete and Ajax functionality.

SPG works in its current state. A user can enter seed artists and have a generated playlist saved into their account with about 3 mouse clicks. An important feature that we want to add is auto-generated playlists. Put simply, SPG would refresh users’ playlists with new music every 24 hours. This would be vastly more often than Spotify’s “Discover Weekly” playlist. Our database has been set up to begin implementation of this feature. Development of the microservice for the backend is ongoing and we hope to have it running within the next few weeks.

--

--