* Refactoring and addition of logzero (#172) * Refactored convert.py and added logging. * Added logging and refactored. * Added logzero to requirements.txt * Added logging to metadata.py * Created a log in misc.py. Updated slugify import. * Some general improvement * Improve message layout * Improve test mechanism * Implement debug level logging * Fix some minor mistakes * Make pytest happy * Remove unimplemented --verbose option * Update ISSUE_TEMPLATE.md * Rename LICENSE * Remove obvious from log.debug() * Show track URL when writing to file (debug)
Spotify-Downloader
-
Downloads songs from YouTube in an MP3 format by using Spotify's HTTP link.
-
Can also download a song by entering its artist and song name (in case if you don't have the Spotify's HTTP link for some song).
-
Automatically fixes song's meta-tags which include:
- Title
- Artist
- Album
- Album art
- Album artist
- Genre
- Track number
- Disc number
- Release date
- And more...
-
Works straight out of the box and does not require to generate or mess with your API keys.
That's how your Music library will look like!
Contributing
-
Search for your problem in the issues section before opening a new ticket. It might be already answered and save us time. 😄
-
Provide as much information possible when opening your ticket.
-
Look up for open issues and see if you can help out there.
-
There's also a web-based application for this tool under (major) work called spotifube. Check it out if you'd like to contribute to it!
Installation & Usage
-
This tool supports only Python 3, Python 2 compatibility was dropped because of the way it deals with unicode. If you need to use Python 2 though, check out the (old)
python2branch. -
Note:
playandlyricscommands have been deprecated in the current branch since they were not of much use and created unnecessary clutter. You can still get them back by usingoldbranch though.
Debian, Ubuntu, Linux & Mac
cd
git clone https://github.com/ritiek/spotify-downloader
cd spotify-downloader
pip install -U -r requirements.txt
Important: if you have installed both Python 2 and 3, the pip command could invoke an installation for Python 2. To see which Python version pip refers to, try pip -V. If it turns out pip is your Python 2 pip, try pip3 install -U -r requirements.txt instead.
You'll also need to install FFmpeg for conversion (use --avconv if you'd like to use that instead):
Linux: sudo apt-get install ffmpeg
Mac: brew install ffmpeg --with-libmp3lame --with-libass --with-opus --with-fdk-aac
If it does not install correctly, you may have to build it from source. For more info see https://trac.ffmpeg.org/wiki/CompilationGuide.
Windows
Assuming you have Python 3 (preferably v3.6 or above to stay away from Unicode errors) already installed and in PATH.
-
Download and extract the zip file from master branch.
-
Download FFmpeg for Windows from here. Copy
ffmpeg.exefromffmpeg-xxx-winxx-static\bin\ffmpeg.exeto PATH (usually C:\Windows\System32) or just place it in the root directory extracted from the above step. -
Open
cmdand typepip install -U -r requirements.txtto install dependencies. The same note aboutpipas for Debian, Ubuntu, Linux & Mac applies.
Instructions for Downloading Songs
Important: as like with pip, there might be no python3 command. This is most likely the case when you have only Python 3 but not 2 installed. In this case try the python command instead of python3, but make sure python -V gives you a Python 3.x.x!
- For all available options, run
python3 spotdl.py --help.
usage: spotdl.py [-h]
(-s SONG | -l LIST | -p PLAYLIST | -b ALBUM | -u USERNAME)
[-m] [-nm] [-a] [-f FOLDER] [-v] [-i INPUT_EXT]
[-o OUTPUT_EXT] [-ll {INFO,WARNING,ERROR,DEBUG}]
Download and convert songs from Spotify, Youtube etc.
optional arguments:
-h, --help show this help message and exit
-s SONG, --song SONG download song by spotify link or name (default: None)
-l LIST, --list LIST download songs from a file (default: None)
-p PLAYLIST, --playlist PLAYLIST
load songs from playlist URL into <playlist_name>.txt
(default: None)
-b ALBUM, --album ALBUM
load songs from album URL into <album_name>.txt
(default: None)
-u USERNAME, --username USERNAME
load songs from user's playlist into
<playlist_name>.txt (default: None)
-m, --manual choose the song to download manually (default: False)
-nm, --no-metadata do not embed metadata in songs (default: False)
-a, --avconv Use avconv for conversion otherwise set defaults to
ffmpeg (default: False)
-f FOLDER, --folder FOLDER
path to folder where files will be stored in (default:
Music/)
-i INPUT_EXT, --input-ext INPUT_EXT
prefered input format .m4a or .webm (Opus) (default:
.m4a)
-o OUTPUT_EXT, --output-ext OUTPUT_EXT
prefered output extension .mp3 or .m4a (AAC) (default:
.mp3)
-ll {INFO,WARNING,ERROR,DEBUG}, --log-level {INFO,WARNING,ERROR,DEBUG}
possible values - ['INFO', 'WARNING', 'ERROR',
'DEBUG'] (default: INFO)
Download by Name
For example
-
We want to download Fade by Alan Walker, simply run
python3 spotdl.py --song "alan walker fade". -
The script will automatically look for the best matching song and download it in the folder
Music/placed in the root directory of the code base. -
It will now convert the song to an mp3 and try to fix meta-tags and album-art by looking up on Spotify.
Download by Spotify Link (Recommended)
For example
-
We want to download the same song (i.e: Fade by Alan Walker) but using Spotify Link this time that looks like
https://open.spotify.com/track/2lfPecqFbH8X4lHSpTxt8l, you can copy it from your Spotify desktop or mobile app by right clicking or long tap on the song and copy HTTP link. -
Run
python3 spotdl.py --song https://open.spotify.com/track/2lfPecqFbH8X4lHSpTxt8l, it should download Fade by Alan Walker. -
Just like before, it will again convert the song to an mp3 but since we used a Spotify HTTP link, the script is guaranteed to fetch the correct meta-tags and album-art.
Download multiple songs at once
For example
- We want to download
Fade by Alan Walker,Sky High by ElektromaniaandFire by Elektromaniajust using a single command.
Let's suppose, we have the Spotify link for only Fade by Alan Walker and Fire by Elektromania.
No problem!
- Just make a
list.txtin the same folder as the script and add all the songs you want to download, in our case it is
(if you are on Windows, just edit list.txt - i.e C:\Python36\spotify-downloader-master\list.txt)
https://open.spotify.com/track/2lfPecqFbH8X4lHSpTxt8l
elektromania sky high
https://open.spotify.com/track/0fbspWuEdaaT9vfmbAZr1C
-
Now pass
--list=list.txtto the script, i.epython3 spotdl.py --list=list.txtand it will start downloading songs mentioned inlist.txt. -
You can stop downloading songs by hitting
ctrl+c, the script will automatically resume from the song where you stopped it the next time you want to download the songs present inlist.txt. -
Songs that are already downloaded will be skipped and not be downloaded again.
Download playlists
- You can copy the Spotify URL of the playlist and pass it in
--playlistoption. Note: This method works for public as well as private playlists.
For example
-
python3 spotdl.py --playlist https://open.spotify.com/user/nocopyrightsounds/playlist/7sZbq8QGyMnhKPcLJvCUFD -
The script will load all the tracks from the playlist into
<playlist_name>.txt -
Then you can simply run
python3 spotdl.py --list=<playlist_name>.txtto download all the tracks.
Download albums
- You can copy the Spotify URL of the album and pass it in
--albumoption.
For example
-
python3 spotdl.py --album https://open.spotify.com/album/499J8bIsEnU7DSrosFDJJg -
The script will load all the tracks from the album into
<album_name>.txt -
Then you can simply run
python3 spotdl.py --list=<album_name>.txtto download all the tracks.
Download playlists by username
-
You can also load songs using Spotify username if you don't have the playlist URL. (Open profile in Spotify, click on the three little dots below name, "Share", "Copy to clipboard", paste last numbers or text into command-line:
https://open.spotify.com/user/0123456790) -
Try running
python3 spotdl.py -u <your_username>, it will (only) show all your public playlists (which excludes collaborative and private playlists). -
Once you select the one you want to download, the script will load all the tracks from the playlist into
<playlist_name>.txt. -
Run
python3 spotdl.py --list=<playlist_name>.txtto download all the tracks.
Specify the target directory
If you don't want to download all the songs to the Music/ folder relative to the spotdl.py script, you can use the -f/--folder option. E.g. python3 spotdl.py -s "adele hello" -f "/home/user/Music/". This works with both relative and absolute paths.
Preserve spaces in file names
Beside some other characters, spaces will be replaced by underscores. There's no option to change this behavior in spotify-downloader itself, but on Unix-based operating systems you can issue the following Bash command after downloading is done:
find . -type f -name "*.mp3" -exec bash -c 'mv "$0" "${0//_/ }"' {} \;
Just make sure your working directory is the one you have the music files in.
Exit codes
0- Success1- Unknown error2- Command line error (e.g. invalid args)-1- KeyboardInterrupt10- Invalid playlist URL11- Playlist not found
Running tests
python3 -m pytest test
Obviously this requires the pytest module to be installed.
Disclaimer
Downloading copyright songs may be illegal in your country. This tool is for educational purposes only and was created only to show how Spotify's API can be exploited to download music from YouTube. Please support the artists by buying their music.
License
The MIT License


