riverscuomo / spotkin

A python package that updates one or more of your Spotify playlists every day with a random selection of songs from any playlists you specify. Here's mine: https://open.spotify.com/playlist/1HaQfSGjNzIsiC5qOsCUcW?si=ddc16d3e9524410c

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spotkin PRs Welcome

(in the middle of re-naming hell: at first it was 'spotkin' then I changed it to 'spotnik' now I'm changing it back to 'spotkin'. It's supposed to be short for 'spotify controller'.)

A python package that updates one or more of your Spotify playlists every day with a random selection of tracks from any public playlists.

For example, I have a playlist called "Rivers Radio" that is updated by Spotnik every day.

I developed this script because I didn't like fiddling with the Spotify app all the time. I just wanted a great selection of music in one playlist every day. I've been it using it every day for a few years. It's run automatically at 2am by a Windows Task Scheduler job. It works best when you draw from many playlists, especially:

  • dynamic playlists like "New Music Friday" or "Today's Top Hits" because they frequently change
  • large curated playlists like Rolling Stone's "fivehundredalbums"
  • a playlist generated by my new_albums script which has the latest album releases in all the genres you're interested in

You can also ban artists, tracks, or genres. That's great for avoiding music you don't like (obviously) but also for avoiding music you don't want to hear right now even though you love it. For example, I love the Beach Boys. Spotify knows that so they keep adding them to the algorthmic playlists. But I've heard all their songs a zillion times and I don't need to hear them now.

On tour, I realized I needed a second playlist, for warming up before a show, so I added the ability to update as many playlists as you want--and to set minimun values for 'energy', etc. I recommend sticking with one or two playlists, though, otherwise you're just fiddling with the Spotify app all over again.

I find that I tweak my recipe about once a week.

Installation

Before you can run the Spotnik script, there are some pre-requisites the script assumes.

Spotify Developer Account

The script will need a Spotify Client Id and Client Secret to interact with Spotify's Web API.

Register for a developer account on Spotify. After registering, create a new app. Once you create a new app, a Client Id and Client Secret will be generated. You will need these in later steps.

Additionally, the Spotnik script uses an Authorization Code Flow. Due to this, you will need to set a redirect URL for your app. To add a redirect URL, open the app's settings. Note: The Spotnik script is only intended to run locally, on your machine, so add a redirect link to http://localhost:8080.

Spotify Playlist Id

The script will need the unique ID for at least one of your Spotify playlists. This is where your Spotnik playlist will be updated. To get the ID for a playlist, in Spotify, right-click on the playlist > Share > Copy Share Link. The link will contain the playlist ID. It is the string between playlist/ and ?si=.

Environment Variables

You can specify custom variables to include using a .env file. Alternatively, you can set them as Environment Variables.

SPOTIFY_CLIENT_ID=xxx
SPOTIFY_CLIENT_SECRET=xxx
SPOTIFY_REDIRECT_URI=http://localhost:8080

Setup your settings in Google Sheets

Import with our script:

Tiny script to copy the template sheet to a user-specified gmail. The function can be imported:

python3 copy_sheet.py "/path/to/credentials.json" "myemail@gmail.com" TLDR: fetches the template sheet, duplicates it and shares the duplicated sheet to a gmail.

Manually make a copy:

https://docs.google.com/spreadsheets/d/1z5MejG6EKg8rf8vYKeFhw9XT_3PxkDFOrPSEKT_jYqI/edit#gid=1936655481

The spreadsheet should be called "Spotify Controller" and have a sheet named "recipes" and a sheet "settings"

Put your target playlist id(s) in the playlist_id row of the settings sheet.

Share your google spreadsheet with the client_email address in your google credentials file.

Set the following environment variables to get the data from the sheet:

GSPREADER_GOOGLE_CLIENT_EMAIL=client_email_from_your_creds.json GSPREADER_GOOGLE_CREDS_PATH=path_to_your_creds.json

To add more target playlists

Simply add columns in the "recipes" sheet and in the "settings" sheet. I like keeping it to one or two.

Poetry

poetry init poetry install

Running

Once you have completed all the installation steps, run Spotnik script by running py -m spotnik.

Contributing

Feel free to make pull requests for any changes you'd like to see.

see discussions for some ideas.

About

A python package that updates one or more of your Spotify playlists every day with a random selection of songs from any playlists you specify. Here's mine: https://open.spotify.com/playlist/1HaQfSGjNzIsiC5qOsCUcW?si=ddc16d3e9524410c

License:GNU General Public License v3.0


Languages

Language:Python 100.0%