Spotify tools to make it easy to:
- query and control Spotify
- backup all your Spotify playlists
- keep human-readable
Artist - Track
playlists (could migrate to another music system)
My epic Spotify Playlists collection (recently open sourced) uses this heavily.
Hari Sekhon
Cloud & Big Data Architect, United Kingdom
(you're welcome to connect with me on LinkedIn)
- bash-tools/spotify/spotify_*.sh` - Spotify API scripts
- list all public playlists for any given user, even followed playlists
- list all private playlists for the currently authorized user
- backup all playlists or a selection of playlists by partial name or ID
- download playlist contents as Spotify URIs /
Artists - Track
/ CSV format - convert Spotify track URIs to human readable
Artist - Track
/ CSV format - iterate any command against all playlists - command can be templated with
{playlist}
name or{playlist_id}
which will be auto-populated on each iteration - convert a playlist name to an ID, or an ID to a playlist name
- search for tracks / artists / albums and output in either human readable form or as Spotify URIs for fast loading into the Spotify app or automated chaining with other adjacent tools
- list liked / top tracks / artists in either human readable form or as Spotify URIs
- generate a Spotify API token (used by all other bash scripts)
- query any Spotify API endpoint with authentication (used by all other bash scripts)
spotify-cmd.pl
- Spotify desktop app control from the command line on Mac via AppleScript calls. Useful for automation that Mac HotKeys don't help with such as auto-nexting tracks every N seconds if you want to skip through sampling a playlist
If you want to recover an entire deleted playlist, you can do that quickly in the Spotify web interface -> Account -> Recover Playlists page.
For deleted songs in the desktop app, you can immediately press Control + Shift + Z on Windows or Control + Z on Mac to undo it.
This repo is for everything else - Backups, Conversions from HTTP URIs to readable Artist - Track
format, tracking individual songs removed from playlists over time (if Spotify loses the rights to them they silently disappear and you won't notice if not Git revision controlling them like my repo Spotify Playlists etc.
These programs and their pre-compiled dependencies can be found ready to run on DockerHub.
List all programs:
docker run harisekhon/spotify-tools
Run any given program:
docker run harisekhon/spotify-tools <program> <args>
git clone https://github.com/HariSekhon/Spotify-tools
cd spotify-tools
make
This builds all dependencies after which the programs can be run.
Alternatively see the Manual Setup section instead.
Downloads the list of public playlists to playlists.txt
(names) and spotify/playlists.txt
(IDs + names in TSV format)
For each playlist, downloads the list of playlist tracks to a file of the same name in both human and Spotify usable formats
As it progresses, it outputs the playlist name followed by the progress of the URI download then the human readable download
playlists/
files contain the human readable Artist - Track
format
playlists/spotify/
files contain the Spotify URI format (for restores or copying to new playlists)
$ ./bash-tools/spotify/spotify_backup.sh
================================================================================
Running Spotify Playlists Backup
================================================================================
2020-07-05 01:23:41 Dumping list of Spotify playlists to spotify/playlists.txt
2020-07-05 01:23:43 Stripping spotify playlist IDs from spotify/playlists.txt => playlists.txt
2020-07-05 01:23:44 Backing up Spotify playlists to /Users/hari/github/spotify-tools/playlists
My Shazam Tracks => URIs OK => Tracks OK
Upbeat & Sexual Pop => URIs OK => Tracks OK
Best R&B => URIs OK => Tracks OK
Best Pop => URIs OK => Tracks OK
Best Rock => URIs OK => Tracks OK
Best Motown / Funk / Boogie / Groove / Soul => URIs OK => Tracks OK
Chill => URIs OK => Tracks OK
2019 06-07 Venice & Budapest => URIs OK => Tracks OK
2019 05 - Winchester => URIs OK => Tracks OK
2019 04 April - Bath => URIs OK => Tracks OK
2019 01 Jan - South Woodford => URIs OK => Tracks OK
2018 10 Oct - Dec => URIs OK => Tracks OK
2018 09 Sept - Dec => URIs OK => Tracks OK
2018 09 Sept => URIs OK => Tracks OK
2018 08 - Aug - Vienna => URIs OK => Tracks OK
2018 Gemma => URIs OK => Tracks OK
2018 03 March - July Mix => URIs OK => Tracks OK
2018 03 Driving Rock => URIs OK => Tracks OK
2018 02 Feb Mix - London => URIs OK => Tracks OK
2018 Jan - London - A New Beginning => URIs OK => Tracks OK
2017 12 December Mix - Back in London Baby => URIs OK => Tracks OK
2017 11 November Mix - Copenhagen => URIs OK => Tracks OK
2017 10 October Mix - Copenhagen => URIs OK => Tracks OK
2017 09 September Mix - Copenhagen => URIs OK => Tracks OK
2017 08 August Mix - London & Copenhagen => URIs OK => Tracks OK
2017 07 July Mix - Johannesburg => URIs OK => Tracks OK
2017 06 June Mix - Johannesburg => URIs OK => Tracks OK
...
2020-07-05 01:41:42 Spotify playlists backup finished in 1078 seconds
You can copy and paste the tracks from the Spotify desktop app or web player directly into text files, which puts them in Spotify URI format such as:
http://open.spotify.com/track/61oGXsKgJOI0e3uS2wg1BV
http://open.spotify.com/track/1j6API7GnhE8MRRedK4bda
http://open.spotify.com/track/0RxFoUhB3mAI3qpgLSf7eM
or
spotify:track:61oGXsKgJOI0e3uS2wg1BV
spotify:track:1j6API7GnhE8MRRedK4bda
spotify:track:0RxFoUhB3mAI3qpgLSf7eM
Then convert this to readable Artist - Track
form for saving independently of Spotify but running spotify_uri_to_name.sh
against the file:
$ ./bash-tools/spotify/spotify_uri_to_name.sh Pendulum.txt
Pendulum - Watercolour
Pendulum - Witchcraft
Pendulum - The Island - Pt. I
...
You can also pipe one or more Spotify URIs through standard input in either format that Spotify uses:
$ echo http://open.spotify.com/track/5TOYgNohZAFEPOtnchPhZS | ./bash-tools/spotify/spotify_uri_to_name.sh
Foo Fighters - Arlandria
echo spotify:track:5TOYgNohZAFEPOtnchPhZS | ./bash-tools/spotify/spotify_uri_to_name.sh
Foo Fighters - Arlandria
Give the playlist file full of Spotify URIs (dumped by the spotify_backup*.sh scripts above), you can mark all the songs from your favourite playlists as Liked Songs
which then appear in your Liked Songs
playlist too:
spotify_set_tracks_uri_to_liked.sh playlists/spotify/My_Favourite_Playlist
If you've been using Spotify a long time, you'll remember that marked songs used to be called Starred
, but were replaced by Liked Songs
. Unfortunately Spotify made Starred
a regular playlist and didn't carry them over, but you can easily mark all previously Starred
songs as the newer Liked Songs
:
spotify_set_tracks_uri_to_liked.sh playlists/spotify/Starred
$ ./spotify-cmd.pl --help
Command line interface to Spotify on Mac that leverages AppleScript
Useful for automation that Mac HotKeys don't help with, such as auto skipping
to next track every N secs to sample a playlist while working
usage: spotify-cmd.pl <command>
commands:
play Play
pause / stop Pause
playpause Toggle Play/Pause
previous Previous Track and print previous track information
next [secs] Next Track and print next track information.
Specifying optional secs will skip to next track
every [secs] seconds. Handy for skipping through a playlist
every 60 secs automatically and grabbing the good songs. Prints
track information every time it skips to the next track
status Show current track details
vol up Turn volume up
vol down Turn volume down
vol <1-100> Set volume to number <1-100>
exit / quit Exit Spotify
-q --quiet Quiet mode. Do not print track information or volume after
completing action
-t --timeout Timeout in secs (default: 10)
-v --verbose Verbose mode (-v, -vv, -vvv ...)
-h --help Print description and usage options
-V --version Print version and exit
Enter the directory and run git submodule init and git submodule update to fetch my library repo:
git clone https://github.com/HariSekhon/Spotify-tools
cd spotify-tools
git submodule init
git submodule update
Then you will also need to fetch the following CPAN modules listed in setup/cpan-requirements.txt
and lib/setup/cpan-requirements.txt
:
Running the cpan command followed by the list of modules (as root) will fetch them for you, or you can use this script:
bash-tools/perl/perl_cpanm_install.sh setup/cpan-requirements.txt lib/setup/cpan-requirements.txt
Patches, improvements and even general feedback are welcome in the form of GitHub pull requests and issue tickets.
Run:
make update
This will git pull and then git submodule update which is necessary to pick up corresponding library updates. ndencies.
If you update often and want to just quickly git pull + submodule update but skip rebuilding all those dependencies each
time then run make update-no-recompile
(will miss new library dependencies - do full make update
if you encounter
issues).
The rest of my original source repos are here.
Pre-built Docker images are available on my DockerHub.