Website is currently a WIP. All projects & articles are in progress.
Spotify Live Radio Playlists

A while ago I thought it would be a good idea to create some “live” Spotify playlists based on radio stations from around the world. By “live” I mean the playlists have a limited number of tracks (in this case 85) and every time a new song is added the oldest song is removed.

Graph Image

Each playlist is based on a radio station so, for example, NME from the UK, triple j from Australia and some others.

How it works

A python script periodically scrapes an online music radio website for song data (title and artist). The script then searches for the song on Spotify using the Spotify API and spotipy. If there’s a match it will add to the playlist and remove the oldest song.

The script itself is quite small, about 240 lines and mostly makes use of Flask, Spotipy and Requests packages to make everything run smoothly. The script runs off a raspberry pi in my living room on a 3 min or so sleep timer.

Complications and Bugs

Duplicate Songs

Trivial but obviously if the script was checking every 3 mins and the same song was playing, I didn’t want it to add that song again. The script keeps tracking of the last song added and makes sure it doesn’t add it twice.

Loadshedding

Because we occasionally have loadshedding in South Africa the electricity periodically goes off for a couple of hours a day which is an issue because the script would need to be restarted constantly. I worked around this by pickling (storing on disk) the Spotify refresh tokens (the Spotify API keys expire every couple hours and you need to refresh them using a refresh token) and running a CRON job to start the script automatically every time the raspberry pi restarts.

Incorrect Songs

Because the script adds the first result, relying on Spotify to supply the best result, sometimes the wrong song can be added. I’ve found this mostly happens when a song can’t be found on Spotify but there is an orchestral or karaoke version for some reason 🤷‍♀

Playlists

NME1

NME2

triple j

Double J

delta radio INDIE

SomaFM Indie Pop Rocks!

181.FM Super 70s

181FM Old School Hip Hop

The Beat

idobi Radio

SomaFM Groove Salad

It’s quite nice to have some playlists that just play a new selection of curated music constantly outside of the existing Spotify algorithms.

Articles

A Figma plugin for everythingFinding Second Hand Car Deals with Python and MatplotlibDesign Systems Case StudyBanking Widget ExplorationsImproving the UX of InsightsSpotify Live Radio PlaylistsWavehaus font process