Creates and updates a reordered playlist from your existing Spotify playlists
484
This script is able to create a reordered playlist from your existing Spotify playlists. It was created for two reasons:
There are two playlist types the script can create:
This script only modifies its own playlists that it creates, that is to say the playlists you have made are not modified.
This script uses Discord as an interface for communication and authentication purposes.
This script comes with a .env file that holds all the configuration parameters
For this script to work you will need to create a Spotify application from the Spotify Developer Dashboard
https://redirect-uri-capture.joshlucpoll.dev/spotify-callback sidenote.env file so it has this line:
CLIENT_ID="<Client ID>"
<Client ID> is the Client IDCLIENT_SECRET="<Client Secret>"
<Client Secret> is the Client SecretThis script uses a discord bot to gain the access token and log events, so you'll have to create one:
.env file:
DISCORD_TOKEN="<bot token>"
<bot token> is replaced with your bot tokenNow to add your bot to your server:
<CLIENT_ID> with the client ID from the discord bot
https://discordapp.com/api/oauth2/authorize?client_id=<CLIENT_ID>&permissions=75840&scope=bot
.env file:
DISCORD_CHANNEL=<ID>
<ID> is replace with the channel IDYou will need the ID of the playlists you want the script to use
To get the id of a playlist, right click it then Share > Copy link to playlist. This will give you a link to your playlist in the format:
https://open.spotify.com/playlist/<PLAYLIST_ID>?si=<SI>
where <PLATLIST_ID> and <SI> are random strings of characters
Copy your playlist id and paste it into the .env file:
PLAYLISTS_TO_SHUFFLE=["<PLAYLIST_ID_1>", "<PLAYLIST_ID_2>", "<PLAYLIST_ID_3>"]
PLAYLISTS_TO_NEWEST=["<PLAYLIST_ID_1>", "<PLAYLIST_ID_2>"]
where <PLAYLIST_ID_x> are your playlist IDs
note PLAYLISTS_TO_SHUFFLE and PLAYLISTS_TO_NEWEST can have zero or more values -- if there are zero values: PLAYLISTS_TO_SHUFFLE=[]
In the .env file you will also find a PLAYLIST_ARE_PUBLIC constant. This alters the the output playlist visibility, either True or False
You will need Python3 to run the script -- if you don't have python installed, you can follow this guide
Install the required packages using:
python3 -m pip install -r requirement.txt
Run the main.py script
The first time you run it you should get a discord message asking for an access code. Click the link and sign in with your Spotify account. Copy the access code from the capture website and paste it back into the same channel. The script uses a cache to store Spotify credentials so you won't be asked to sign in every time the script runs.
If successful you should have new playlists created within your account!
This script can also be be used in a docker environment. By default the script will run every day at 8:00. If you want to change this timing go to custom cron timing else continue to running the container
DockerFile file on line 10:RUN printf "0 8 * * * python3 /app/main.py\n" >> crontab-automation
Change 0 8 * * * to preferred cron timing
Build the container:
docker build -t spotify-playlist-utils <path_to_root_folder>
To start, pull the docker image from docker hub:
docker pull joshlucpoll/spotify-playlist-utils
Now run the container:
.env file (same one created in the guide -- you may need to download from Github):docker run --env-file <path_to_.env_file> <image_id>
docker run -e CLIENT_ID="<client_id>" -e CLIENT_SECRET="<client_secret>" -e DISCORD_TOKEN="<discord_token>" -e DISCORD_CHANNEL=<discord_channel> -e PLAYLISTS_TO_SHUFFLE=[] -e PLAYLISTS_TO_NEWEST=[] -e PLAYLIST_ARE_PUBLIC=True <image_id>
The container should now be running and will update your playlists automatically!
For the script to read your playlists it needs to gain an access token from Spotify. This is done by creating a URL that points to Spotify asking you to authenticate. Once you sign in spotify sends an access code to a callback URL. Therefore, to capture this code, I have created a simple website that extracts the code allowing your to copy it back into discord. This website's source code in available here
Content type
Image
Digest
sha256:7c82c9f3f…
Size
57.9 MB
Last updated
about 2 years ago
docker pull joshlucpoll/spotify-playlist-utils