DEV Community

Cover image for Spotify Playlist Backup using Github Actions
Luke Secomb
Luke Secomb

Posted on • Originally published at blog.lukesecomb.digital

Spotify Playlist Backup using Github Actions

Platforms come and go, and Spotify most likely wont be around forever. What would you do if you woke up tomorrow and Spotify was gone. I know I wouldn't be too happy, after spending countless hours carefully curating well over 200 playlists.

So, to save your playlists from being erased from the internet forever, lets create a small python script to back them up. This post outlines the steps to configue and a basic walkthrough of my spotify-playlist-backup project.

Spotify Developer Application

Before we can jump into the code we need to setup our own Spotify Developer Application. This will require you to have a Spotify account (a free account should work). Once logged in, create a new application and save the CLIENT_ID and CLIENT_SECRET for later. Make sure you set http://localhost:3000/callback as a return url for your application.

spotify dashboard application page

Into the code

Clone the spotify-playlist-backup repo and create a new .env file. Copy and paste in the following code snippet and replace the values with your configuration.

# .env file
# Values from your Spotify Developer Application
SPOTIFY_CLIENT_ID=laboriselitutenimdoculpa
SPOTIFY_CLIENT_SECRET=laboriselitutenimdoculpa

# Your Spotify Username
SPOTIFY_USERNAME=12345678910

# Your Spotify Password
SPOTIFY_PASSWORD=abcdefghijklmnopqrstuvwxyz

# Comma separated list of usernames of playlist authors.
# This allows you to back up other peoples playlists (that you follow) if you want.
# if left blank, all of your followed/created playlists will be backed up.
SPOTIFY_OWNER_IDS=snoopdogg,drdre,spotify
Enter fullscreen mode Exit fullscreen mode

Run the script

Once you have setup the .env file, you're ready to run the script.

python script.py
Enter fullscreen mode Exit fullscreen mode

This assumes you already have python installed.

Yes, it is that easy. After running the above script you will have a local copy of all your playlist data in beautiful json format.

Github Action setup

Before your Github Action will run successfully, you must setup the above .env variables correctly within the repo.

Make sure your fork is a private repository

Github actions dashboard screenshot

Cron Job

Lets go one step further and set our Github Action to run once a week. By default, the CRON Job Github Action is disabled. To enable this within your repo, open the .github/workflows/python-app.yml file and uncomment the schedule code block.

on:
  schedule:
    # scheduled to run each week at 3am on a Tuesday
    - cron: '0 3 * * 2'
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'
        required: true
        default: 'warning'
        type: choice
        options:
          - info
          - warning
          - debug
Enter fullscreen mode Exit fullscreen mode

You can use the crontab tool to calculate when and how often you want to run the Github Action.

Top comments (1)

Collapse
 
hurricaneinteractive profile image
adro.codes

Love your work <3