Spotify Live Radio Playlists

Graham Paterson
2 min readMar 17, 2020

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.

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

  1. NME1
  2. NME2
  3. triple j
  4. Double J
  5. delta radio INDIE
  6. SomaFM Indie Pop Rocks!
  7. 181.FM Super 70s
  8. 181FM Old School Hip Hop
  9. The Beat
  10. idobi Radio
  11. 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.

--

--

Graham Paterson

Freelancer Designer specialising in branding and UI design. Exploring new ways to work and appreciate the practice of design.