Automatically download your Spotify playlists locally (for free)
Here's a script to download your Spotify playlists and individual songs from YouTube.
All code can be found on my GitHub in this Gist:
Download Spotify Songs - GitHub Gist
Background
I've had a Spotify account since 2013. For many years I was fine with a free account, but a few years ago I started paying for a Spotify premium account so that I could listen to my playlists on my phone without the auto-shuffle limitation of the free account. I've gotten tired of paying $10 a month to Spotify, a giant faceless multinational corporation. As a Spotify premium user you do NOT own the songs, you CANNOT share them with friends who don't have Spotify, and you let Spotify harvest and sell your data to 3rd parties, all the while paying them for the "privilege!" To remediate the above gripes I have with Spotify, I wrote this script to download my Spotify playlists locally, as well as some songs that I can find on YouTube but not Spotify. I now have all my songs on my computer and on my phone, I can listen to them while I'm offline, and I no longer need to pay for Spotify!
Setup
This script makes use of some open-source software that you will need before running it.
spotDL
This is the program that the script uses to download the Spotify playlists. Please make sure to install the prerequisites listed on the repository README, such as Python and FFmpeg. The script makes use of pipx to run spotdl. There is a section of the README discussing how to install and run spotDL with pipx.
youtube-dl
This is the program that the script uses to download songs from YouTube. The download page for youtube-dl has instructions for installing it on your Linux distro.
Downloading Spotify playlists with the script
To use the script to download you Spotify playlists, first specify a directory where all your playlists sub-directories will be kept. You can do this by modifying the PLAYLISTS_DIR
variable
Once PLAYLIST_DIR
is updated, now you can specify the playlists you would like to download. Modify the PLAYLISTS
associative array to contain a playlist_directory/spotify_playlist_url key pair.
NOTE: If you only want to download Spotify playlists (i.e. NOT download any YouTube songs), please comment out download_youtube_songs
function in main
. You can now run the script to download your playlists!
Downloading YouTube songs with the script
To download individual songs from YouTube, create an array similar to STARRED_SONGS
in the sample script. This array should contain:
- 1st entry – the playlist output directory
- following entries – the YouTube songs you want to download
Once this is done, please update the download_youtube_songs
function to contain a call similar to the one in the sample script, but with the name of the array you created from above.
Now you can run the script and download songs from YouTube in addition to your Spotify playlists!
Tagging your songs
By default, the script sets the genre of the downloaded .mp3 song files to the name of the playlist sub directory. For instance in the picture below, the songs downloaded to "${PLAYLISTS_DIR}/lofi_beats"
will be set to have the genre "lofi_beats"
The script does this because I noticed there could be dozens of different genres for the songs in a given playlist when they are downloaded. Tagging the songs in a given playlist with the same genre helps me organize my songs into playlists on the Android music player app I use, Vinyl Music Player.
If you would like to keep the original genre tags for the songs, you can comment out the tag_mp3s_in_playlists
function in main
.