BrianFM Spotify playlist

#spotify#aws#serverless


If you’re looking for great songs to listen to, look no further - you’ve come to the right place!

I developed a serverless application that captures songs played on my favorite radio station, BrianFM. It also creates a Spotify playlist featuring songs from the past 24 hours. You can find the playlist below.

But first, let me tell you how I stumbled upon this amazing radio station purely by chance. 🍀

The backstory

BrianFM?!

A few years ago I was studying in Dresden, Germany. There were some challenging exams coming up, so a few friends and I gathered in one of the university’s course rooms to study together. Suddenly some other guys started listening to music via the speaker system of the room. At first I got a little bit annoyed but after a few songs I was really happy with the choice of music. Later I asked them if they could send me a link to their playlist. They said it was a radio station from New Zealand called BrianFM. Weird, I thought - no talking, no ads, just solid music the whole time. That day I found my favourite radio station! 📻

A few weeks later I listend to BrianFM in the kitchen. A roommate entered and I told him about the radio station and how great it was. He looked at me and said Oh yeah BrianFM, I know that station. It turns out he spent a year doing work and travel in New Zealand, where he listened to BrianFM while filling wine bottles at his job. Its a small world… 🍷🎶
Also he even did listen to Brian via FM! 😄

Why we need a playlist

One day I was adding BrianFM to a new device and noticed that the bitrate is relatively low. High quality music deserves high quality internet radio! That’s what I thought but I could not find a stream with higher bitrates. In my despair I even asked BrianFM via facebook but got a response in typical Brian fashion. Let‘s just say they did not care about some random pseudo audiophile bloke sitting in Germany and whishing for at least 256 kbit/s…
We play what we feel like (That’s Brian’s motto). Fair enough.

I decided to take matters into my own hands and came up with the idea of preserving the song selection of BrianFM in some way. Streaming some random high-bitrate music is straightforward, but creating a database of Brian‘s top-notch music taste? That’s where the real adventure starts.

Technical setup

It just so happened that serverless architecture became the latest trend around that time. I decided to give it a try because this type of project is a perfect fit for serverless applications. My program will only run for short periods, do its work and be idle most of the time. So it does not require a server running 24/7.

BrianFM shows a list of recently played songs on their website. In its source code you can find a link to an API which lets you query song information for many radio stations. You can even define time ranges and get a lot of metadata. Perfect!

I came up with the following workflow: Query the radio station api every hour with a time range of the previous hour. Save the results in a DynamoDB database. Then at night query the DynamoDB for songs of the last 24 h. Remove duplicates and search for song title and artist via Spotify API. Finally create a Spotify playlist with all matched songs of the last 24 hours. So we get a fresh playlist every morning — at least in the German timezone. ⏰

sequenceDiagram
    participant RAPI as Radio API
    participant LSH as Save History (Lambda)
    participant DB as DynamoDB
    participant LCP as Create Playlist (Lambda)
    participant SAPI as Spotify API
    loop once per hour
        RAPI->>LSH: Get songs
				LSH->>DB:   Save songs
		end

		loop once per day
        DB->>LCP:   Query songs
				Note right of LCP: Deduplicate songs

    		SAPI->>LCP: Match songs
    		LCP->>SAPI: Create playlist
		end 

I implemented both AWS Lambda functions in Go because it requires less memory and runs faster. Especially cold start is a lot faster in comparison to interpreted languages like Python. Of course, my application doesn’t create much load. The whole thing only costs a few cents a month (if at all). That’s serverless! 😎

Playlist analysis

Now, let’s dive into analyzing the playlist! I’ve been collecting data since February 2023, with a few gaps here and there due to occasional unavailability of the radio playlist API. That said, these missing months don’t significantly impact our ability to uncover Brian’s musical preferences. Let’s explore his taste in music! 🎶🤓

Top 20 artists

Foo Fighters, Green Day and Red Hot Chili Peppers at the top, nice! 🤘🎸


Top 20 songs

Of course, the most-played songs don’t remain the same forever. I’ll update this chart from time to time.


Daytime song rankings

I was curious to explore whether the selection of songs varied based on the time of day. To investigate this, I grouped and analyzed the songs according to New Zealand daytime periods, using the Pacific/Auckland timezone.

You can click/tap on the different bars to see details about a song. The color for a song stays the same between different daytimes.


As you can see the order stays the same for the six most played songs and only starts changing afterwards. So it appears that the song rotation remains largely consistent throughout the day.
 


Perhaps I will add a few additional ideas for analysis in the future.

Listen to the playlist

🎶 Finally it’s time to enjoy some music! 😊🎸

You can preview songs directly here. If you like the playlist, feel free to add it to your favorites on Spotify. It updates automatically every day! ✨  
 

Don’t miss out on some jokes

Sometimes, during short breaks between songs on the real radio station, you get to hear random dad jokes. I’ve noticed that these jokes add a lot of charm to the station. It’s one of those little things that makes tuning in a lot of fun!

Here are some of my favorites 😂

Every book you read is just a remix of the dictionary.

If you’re lonely at home put on a horror movie. After a while you won’t feel lonely anymore.

If poison expires is it more poisonous or is it no longer poison?

Here at BrianFM we live like we type. Fast… and with a lot of mistakes.

You can listen to BrianFM on their website.

Thoughts about IaC and databases

Opinion: I will define database resources outside of IaC (Infrastructure as Code) in the future.

In this project the DynamoDB database resource was defined as part of AWS SAM (AWS Serverless Application Model). This led to some confusion. At one point my goal was to make a bigger change to the application. So just in case I did a backup of the database. Later I did a clean redeploy of the whole application. Then it was difficult to reuse the previous database backup. Perhaps there is a way to reuse an existing resource instead of creating a new one but I understand that this is not the idea of IaC in the first place. I must admit that I’m not an expert on in AWS CDK/SAM. Now I’m just afraid to mess up the existing database in case I change and redeploy the application because the database is kind of hard linked to this one SAM package.

In the future I will not define databases as part of IaC directly. Instead I will define IAM roles to control access via IaC but manage the database itself manually.

For database migrations you could also use specialized tools like flyway. This might be a safer option than managing databases entirely manually.
 


All in all, I’m really happy with the result and hope you enjoy listening to the playlist as much as I do. 🤩


Related content