Add saved songs to a monthly playlist using GitHub Actions, ditching IFTTT.
The songs you add to your library or give a like to will be included in a monthly playlist (e.g., "Jun '23"), enabling you to revisit and discover the songs you liked 7 months ago during a memorable road trip.
Like this:
🗿 Why not IFTTT?
I have been using that for years, but recently they paywalled it. 🥲
To set up the repository and configure the necessary steps, follow these instructions:
-
Make sure you have a GitHub account. If you don't have one, create an account at github.com/signup.
-
Fork this repository by clicking the "Fork" button at the top right of the repository page. This will create a copy of the repository under your GitHub account.
-
Obtain your
client_id
andclient_secret
from the Spotify Developer Dashboard:- Visit developer.spotify.com and log in with your Spotify account.
- Navigate to your Dashboard.
- Create a new app by clicking the "Create App" button.
- Provide a name and description for your app (you can use any name and description).
- In the Redirect URI field, type
http://localhost:3000
and click "Save". - Open the settings of your app and copy the
client_id
andclient_secret
to a notepad or any text editor. You will need these in the next steps.
-
Before proceeding, you need to run the
main.py
file locally with yourclient_id
andclient_secret
to authenticate your secret credentials. This step gives the necessary permissions to the app you created, allowing it to create new playlists and add songs to them. Just follow these steps to proceed:- Open fork in VS Code
- ⚠︎ Delete
.cache
file (spotify-monthly-saves/.cache) - Run
pip install spotipy
. Not working? - Run the code by pressing Control + Option + N (Control + Alt + N on Windows)
- A window will pop up asking you to Authorise the Spotify app, click authorise.
- If everything goes well and if you've liked any songs on Spotify this month, you'll see something like
[month name] '23
was created and the song names will pop up in the VS Code terminal! - Now a new
.cache
file would've been generated in your project directory, open it and copy all of it's content. - Go to the
.cache
file on your forked repo(github.com/[your-username]/spotify-monthly-saves)
, click on edit and paste what you copied in the previous step, replacing the original content of the file, then click on 'Commit changes'.
-
Go to the "Settings" tab of your forked repository on GitHub, and navigate to "Secrets and variables" → "Actions".
-
Add both the
client_id
andclient_secret
keys as secrets by clicking on "New repository secret" and entering the respective values. -
Next, enable the workflow under the "Actions" tab by clicking the "I understand my workflows, go ahead and enable them" button. This will allow the automated process to run.
-
Additionally, enable the workflow under the sidebar menu called "Run main.py" by clicking the "Enable workflow" button.
-
Please note that the song you like on Spotify won't be instantly added to the monthly playlist. The GitHub action runs at an interval of approximately 15 minutes(sometimes even longer), so there might be a slight delay before the song gets added.
-
Once the setup is complete, you can continue to like songs on Spotify, and they will be automatically added to a new monthly playlist during the next execution of the GitHub action.
-
Profit.
You have the flexibility to customize the interval at which the GitHub Action runs by modifying the - cron:
parameter in the .github/workflows/actions.yml
file. The interval is set using the cron syntax.
Cron syntax consists of five fields representing different time units: minute, hour, day of the month, month, and day of the week. Each field can contain specific values or special characters to define the schedule.
To modify the interval, locate the following line in the .github/workflows/actions.yml
file:
- cron: '*/15 * * * *'
this runs every 15 minutes (recommended)
The * * * * *
represents the default configuration, which executes the workflow every minute. You can change this to your desired schedule. Refer to crontab.guru. It provides a simple and intuitive way to understand and create cron schedules.
Important: There's a limit on how frequently you can run a cron job on GitHub Actions, The best interval is ≥ 15 minutes, it can't really do much below this amount. But again, how often do you like songs on Spotify? LOL I think it's pretty good considering it's totally free.
100%. Yes.