Performs set operations on Spotify playlists. Ported from the original hacked-together version.
I spent many summers working at a summer camp, where I had to be careful about what songs I played because they had to be appropriate for camp. I wanted to be able to have camp appropriate versions of my existing playlists, but going through and manually finding all songs that were in my master camp appropriate playlist and any other one would take a very long time. This motivated me to create the initial version of this program. It allowed me to perform intersections, unions, and set differences between my playlists to create new ones.
However, I wanted to be able to schedule this to run automatically, creating and updating most of my playlists from a few core playlists. Since the old version ran off a node.js server and required manual login in the browser, I figured it would be easier to simply port everything to Go. While working on the Go port I came up with a few new ideas for added functionality, such as:
- Update existing playlists (and deleting them if empty)
- Be able to work with Liked Songs
- Create a playlist "New" that contains all of my recently liked songs
- Create a playlist "To Sort" that contains all songs I've liked but haven't put into my core playlists
Download the most recent release of spotify_set_operations.exe
. In the same directory, create a folder called playlists
. You will also need the client secret to authenticate with Spotify; please contact me directly for this if you would like to use this program. I'm only building and releasing executables for Windows, but feel free to build it for your platform of choice.
USAGE
spotify_set_operations.exe [update|create] [all|<playlist_name>]
OR
spotify_set_operations.exe [update|create] <category> <playlist_name>
There are two different types of config files associated with this program: global config, and playlist config
Global config lives in the base directory, and is called config.json
. Here is an example, with an explanation of the options.
{
"categories": [
"Pringle"
],
"duplicate_songs": [
"Billionaire (feat. Bruno Mars)",
"I Love It (feat. Charli XCX)"
],
"update_order": [
"Acceptable.json",
"Pringle Energetic.json"
],
"exclude_from_all": [
"template.json"
],
"remove_not_liked": true,
"use_not_liked_songs": [
"Dance Party 2019"
]
}
categories: playlist configs that leave playlist1_name
blank. When running the program with a category specified, a new playlist is created by taking the category config and adding the specified playlist name. Category files are automatically added to exclude_from_all
at runtime.
duplicate_songs: These are songs that have explicit and non-explicit versions, but the same title. Add them to this list and the program will grab the correct version based on the explicit setting of the playlist config.
update_order: When using the all
option, playlist configs in this list will be run in the provided order before any others. Useful if some of your playlists are based on other playlists generated by the program
exclude_from_all: When using the all
option, these files/folders in the playlists
folder will be ignored. The images
folder is automatically added at runtime.
remove_not_liked: When using the all
option, songs in ALL playlists (not just ones with configs) that are not in the "Liked Songs" playlist will be removed. Defaults to false
use_not_liked_songs: Playlists that always keep their songs, regardless of the above setting
Playlist config files live in the playlists
directory. Their name without the file extension is exactly how they will appear in Spotify. Here is a default template, with an explanation of the options. Note that the first three fields are not optional (unless the config is for a category, then you can omit playlist1_name
).
{
"playlist1_name": "",
"playlist2_name": "",
"operation": "intersection",
"set_public": false,
"use_explicit": true,
"description": "",
"image": "",
"only_new_songs": false,
"create_on_update": false,
"delete_if_empty": false
}
playlist1_name: The first playlist name as it appears in Spotify.
playlist2_name: The second playlist name as it appears in Spotify.
operation: The set operation to perform. Pick from intersection
, union
, and difference
. When using difference
, the result will be all of the songs in playlist1_name
, excluding all songs that are also in playlist2_name
set_public: Whether or not this playlist should be public when created.
use_explicit: Whether or not this playlist should use the explicit version of a song specified in duplicate_songs
.
description: The description that will be added to the playlist when created.
image: Filename of an image located in playlists/images
that will be the cover art when the playlist is created
only_new_songs: When enabled, the program will look at the song in each playlist that was added the longest time ago. It takes the most recent time between those two, and only considers songs added to either playlist at the same time or after. (I use this to create my "New" playlist).
create_on_update: Whether or not to create this playlist if it doesn't exist when using update
delete_if_empty: Whether or not to delete this playlist if an update
would leave it empty.