Downloads songs from any Spotify playlist or from your "My Music" collection.
I wanted an easy way to grab the songs present in my library so I can download it & use it offline(Spotify still hasn't launched here. Y U NO COME?). spotify_to_mp3 worked well but it relied on grooveshark, which unfortunately is no more.
So I wrote this script which mimics that library, but instead of downloading from grooveshark, it provides you with a file of youtube URLs which you can then plug into youtube-dl
Pre-requisite: You need Python 3+
-
Install using pip
sudo pip3 install spotify_dl(usepipif your distro natively provides Python 3) -
Create your Spotify app & fetch the client id and client secret from Spotify Developer Console. These keys then need to be assigned as
SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRETandSPOTIPY_REDIRECT_URIenvironment variables.You can set environment variables in Linux like so:
export SPOTIPY_CLIENT_ID='your-spotify-client-id' export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret' export SPOTIPY_REDIRECT_URI='your-app-redirect-url'Windows users, check for this question for details on how you can set environment variables.
Note the redirect URL can be a valid URL, just ensure it matches with what you have entered in the developer console & in the environment variable above.
-
Create your YouTube API key & fetch the keys from Google Developer Console. Set the key as
YOUTUBE_DEV_KEYenvironment variable as mentioned above. -
Run the script using
spotify_dl. spotify_dl accepts different parameters, for more details runspotify_dl -h.For most users
spotify_dl -l spotify_playlist_link -o download_directoryshould do wherespotify_playlist_linkis a link to Spotify's playlist. You can get it from the 3-dot menu.
If the Spotify playlist link is skipped then it will download songs from your "My Music" collection
download_directoryis the location where the songs must be downloaded to. If you give a.then it will download to the current directory.
Alternatively,
spotify_dl -p playlist_id -u user_name -o download_directorywill also workplaylist_idis the id of the playlist where songs need to be downloaded. If this is skipped then it will download songs ftom your "My Music" collectionuser_nameis the user name who created the playlist.download_directoryis the location where the songs must be downloaded to.
-
A first time run will require authentication; you will need to click on the URL prompted to authenticate. Once logged in, paste the URL back in.
-
To retrieve download songs as MP3, you will need to install ffmpeg. If you prefer to skip MP3 conversion, pass
-mor--skip_mp3as a parameter when running the script
- Linux users can get them by installing libav-tools by using apt-get (
sudo apt-get install -y libav-tools) or a package manager which comes with your distro - Windows users can download FFMPEG pre-built binaries from here. Extract the file using 7-zip to a foldrer and add the folder to your PATH environment variable
You can set defaults per user by creating a file at ~/.spotify_dl_settings. Create a key with value for every argument you want a default for. Example:
{
"output" : "/home/foo/spotify-dl-output"
, "verbose" : "true"
, "skip_mp3" : "t"
}- rhnvrm for adding in youtube-dl
- mr-karan for adding save to directory
- shantanugoel for adding in User playlist, skip MP3 conversion and Ability to use custom format string support
- sildur for adding any user playlist support and other fixes
- avinassh for being a Rockstar and not teleporting over to my house to kill me when I innundated him with questions
- doulwyi for adding id3 tagging and ability to parse Spotify URI
- Gowtham for create playlist in download directory
- alvierahman90 for config file support and Spotify playlist URL support
- Bibhas for fixing can only concatenate list (not "str") to list error
- Nikhil Nagaraju for fixing support for playlist url with or without userid #58
Feel free to raise any bugs/issues under Github issues. Pull requests are also more than welcome. You can reach me on twitter at @sathyabhat or drop an email sathya@sathyasays.com
