Skip to content

Save Spotify's "Weekly Discover" playlist automatically - Powered by Github Actions.

License

Notifications You must be signed in to change notification settings

LenoxFro/spotify-save-discover-weekly

 
 

Repository files navigation

spotify-save-discover-weekly Save songs GitHub forks


This script automatically saves your "Discover Weekly" playlist which is generated by Spotify and refreshed every Monday. The songs from your temporary playlist are saved into a permanent playlist, using the Spotify API (Authorization Code Flow). The automation is powered by Github Actions and executes automatically on Mondays as defined in the save.yaml.

Initial Set Up (approx: 10 minutes)

You should not need to make any commits back to the repo. The files in /setup will help obtain the authorization information for setting up the environment variables in github secrets in order to allow main.py to execute properly. You need to fork this repo in order to have your own instance of github actions.

(1) Create a Fork

Start off with simple fork by clicking on the "Fork" button. Once you've done that, you can use your favorite git client to clone your repo or use the command line:

# Clone your fork to your local machine
$ git clone https://github.com/<your-username>/spotify-save-discover-weekly.git

(2) Librairies

Use the package manager pip to install all of the required librairies. You could use this with a virtual environment if required.

$ pip install -r requirements.txt

(3) Spotify API Credentials

  1. Open the .sample.env file from the /setup folder on your local machine.
  2. Sign into your Spotify API Dashboard and create a new application. You can use any uri for the redirect uri, this is the base uri you will be redirected to after authorizing the app to access your account. If you see a "INVALID_CLIENT: Invalid redirect URI", then edit settings of your app from the spotify dashboard and add your uri as a redirect uri.
  3. Fill out the env file with the same Client ID, Secret and Redirect URI details used in step 2 and save this file as .env. Do not post these details anywhere publically.

Example:

CLIENT_ID=thisisanid
CLIENT_SECRET=thisisasecret
REDIRECT_URI=https://your.url/here
  1. Execute authorization.py and open the URL generated.
  2. Authorize your app to access your Spotify account, this will then redirect you to your Redirect URI with a ?code= parameter in the url.
  3. Copy the whole url you were redirected to into the console and hit enter, this will then give you your refresh token. Do not post this refresh token anywhere publically.

Example:

$python authorization.py
Open this link in your browser: https://accounts.spotify.com/authorize?client_id=thisisanid&response_type=code&redirect_uri=https%3A%2F%2Fgithub.com%2FRegsonDR&scope=user-library-read+playlist-modify-public+playlist-modify-private+playlist-read-private+playlist-read-collaborative

Enter URL you was redirected to (after accepting authorization):
> https://your.url/here?code=somecodehere

Your refresh token is: somerefreshtokenhere

Obtaining Spotify Playlist IDs

  1. Right click on a playlist > "Share" > Copy the Spotify URI (spotify:playlist:c11M5VLWLMh66yW4gsl51S).
  2. The ID is of this playlist is c11M5VLWLMh66yW4gsl51S, use this for the environment variable.

Local Execution

Store the REFRESH_TOKEN back into your .env file and extend the playlists.json with your own playlists, which should be saved. Execute main.py on your machine when required, maybe manually or using a task schedular. Make sure to have the .env, playlists.json and main.py files in the same directory for this.

$python main.py

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

About

Save Spotify's "Weekly Discover" playlist automatically - Powered by Github Actions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 31.8%
  • HTML 30.8%
  • JavaScript 29.6%
  • SCSS 7.1%
  • Dockerfile 0.7%