Superfly Yachthafen is a radio show airing every Friday 17:00 - 18:00 CET on Superfly.fm. The show is hosted by Austrian DJ Legend Eberhard Forcher and features his personal favourites in the styles of California Westcoast Sounds, Blued Eyed Soul, Smooth Jazz, Brazil, R&B, and Yachtrock.
The show’s website regularly updates the playlist of the current week. This project aims to add the weekly playlists to a Spotify Playlist. To achieve this, we use Azure Functions, an event-driven, serverless compute platform.
The project runs in Python. The requests library is used for API calls and for accessing the radio show’s website. The playlist is subsequently obtained by parsing the HTML content using Beautifulsoup.
To modify the playlist, we use Spotify’s Authorization Code Flow. This flow is suitable for long-running applications and uses a refresh token to generate a new access token at the start of executing the function. The secrets for updating the access token are securely stored in the Azure Key Vault. For developing the project locally, the secrets are stored in a .env file.
To find the Spotify IDs of the new tracks, we use the search request and pass the artist and track names. We then iterate the results and check matches using difflib’s Sequencematcher. The first result that has at least an 80% match for both artist and track is accepted as the track to be added. This way we find the matching tracks despite minor differences, such as special characters (e.g. “e” for “é”) or typos.
To avoid duplicate tracks in our playlist, we get a list of all tracks in our current Spotify playlist using the get playlist request and filter our results.
With our filtered list of new tracks, we update the playlist using the add items to playlist request.
The function is triggered once per day, as configured in functions.json. The weekly playlist update doesn’t always come on the same day, so this ensures we don’t miss a week in case the update is made a different day. We also observed that Spotify doesn’t always return the same search results. Sometimes we get a new matching track in the days after the playlist was first published and updated.
The project is automatically built and deployed to Azure using Github Actions.