[go: up one dir, main page]

Skip to content

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 . This repo also contains the backend server for Spotkin webapp.

License

Notifications You must be signed in to change notification settings

riverscuomo/spotkin_server

Repository files navigation

Spotkin PRs Welcome

Note: I renamed the project from "Spotnik".

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 spotkin 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 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.

This package can be used in two ways

  1. As a standalone script that runs on your machine
  2. As a server that can process jobs on behalf of clients. (Currently in development at spotkin_flutter). Hit the endpoint with a POST request containing the jobs and a spotify token. The server will update the playlists and return the results. The server is built with Flask and is hosted on Heroku.

Installation

Before you can run the spotkin 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 spotkin 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 spotkin 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 spotkin 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

FLASK_APP=server/src/migrations.py
FLASK_ENV=development

Device-Specific Variables

Add the root dir to the very end of your environment activate.bat file. set PYTHONPATH=c:/RC Dropbox/Rivers Cuomo/Apps/spotkin

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.

Running

Once you have completed all the installation steps, run spotkin script by running py -m spotkin. Run the server with 'flask run"

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 . This repo also contains the backend server for Spotkin webapp.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages