Utilizing the Spotify Web API and yt-dlp video downloader to convert any public Spotify playlist to a local MP3 file.
This script scrapes specified Spotify playlists for track information, feeds search parameters to YouTube, and returns video links to be downloaded as MP3s by yt-dlp. The intention is to provide a permanent, automated solution, to make your favorite songs available offline.
- Using a Spotify account, log into the developer portal and create an app. You can follow this quickstart guide for further instructions. Keep note of the
Client ID
andClient Secret
. - Download the latest release of
yt-dlp.exe
and store it for use in the application installation. - Download the latest release of FFmpeg. This should leave you with one folder containing
ffmpeg.exe, ffplay.exe, and ffprobe.exe
. - Download the release of ChromeDriver that matches your systems version of Chrome for further use. Selenium requires ChromeDriver to operate.
- Install the python library dependencies found in requirements.txt.
You can install python_to_mp3 locally via this method:
- Clone the directory to a location of your choice. Ensure all files are located within the same file directory.
- Run
main.py
to establish the necessary file directory. - Within the folder
ytdl
, place the previously downloadedyt-dlp.exe
. - Within the folder
chromedriver
, place the previously downloadedchromedriver.exe
. - Edit the file
command.bat
:- In line 1, replace
#PATH TO YT-DL.EXE#
with the path toyt-dlp.exe
. - In line 2, replace
#FFMPEG PATH#
with the path to the folder containing FFmpeg. - In line 2, replace
#OUTPUT PATH#
with the desired output location for the downloaded MP3 files. Recommended path is thetracks
folder within the working directory.
- In line 1, replace
- Open
main.py
to edit. Set the variablesCLIENT_ID
andCLIENT_SECRET
to the ID and Secret of your Spotify API application. - In
main.py
set the variableURI
to the Spotify URI of the playlist you wish to download. You can learn more about Spotify URI's here. NOTE: Ensure that playlist privacy is set to public otherwise an error will be thrown.
- Once installation and configuration have been completed, insert the desired URI into the script and run it. The program will begin sourcing data from Spotify, then YouTube via Selenium, and finally download the appropriate MP3s.
- Upon completion, you can find the downloaded tracks in the directory you specified.
- The time it takes to complete this process varies based on the total number and length of songs. The largest batch successfully run is near 500 songs, but it can go higher.
- Be aware of songs that could result in high runtime videos. For example, if your playlist includes sleep sounds, YouTube has a tendency to return 10-hour loops which will immensely bog down the program.