A robust Python script designed to automatically download every track from a specified Spotify playlist and convert it to a high-quality MP3 file. It uses the Spotify API to read the tracklist and the YouTube Data API/yt-dlp for finding and downloading the best matching audio source.
Batch Processing: Downloads all tracks from any public Spotify playlist.
Smart Skipping: Automatically checks for and skips tracks that have already been downloaded to prevent redundant work and save API quota.
Robust Input: Handles both clean Spotify URIs and full web URLs (including sharing links with query parameters).
MP3 Conversion: Uses FFmpeg for reliable audio extraction and conversion to a standard MP3 format.
Before running the script, you must have the following installed and configured:
1. Python 3.x
Ensure you have Python 3.x installed on your system.
2. FFmpeg
This is crucial for converting the downloaded YouTube audio stream into the final MP3 file.
Download FFmpeg from their official website.
Extract the ZIP file and locate the bin folder.
Copy the two executable files, ffmpeg.exe and ffprobe.exe, into the same directory where your main.py script is located.
3. API Keys
You need credentials for both Spotify and Google/YouTube. These keys are already configured in the provided main.py script, but you should know where they come from if you need to generate new ones.
YOUTUBE_API_KEY = "Youtube_API_Key_Here"
SPOTIPY_CLIENT_ID = "spotipy_client_id_here"
SPOTIPY_CLIENT_SECRET = "spotipy_client_secret_here"```
Step 1: Install Python Dependencies
Open your terminal or command prompt in the directory containing main.py and run the following command to install the necessary Python libraries:
py -m pip install spotipy google-api-python-client yt-dlp pyinstaller
Step 2: Configure API Keys
You must edit the main.py file and replace the placeholder values for these three variables with your own credentials:
# --- CONFIGURATION (UPDATE THESE VALUES) ---
YOUTUBE_API_KEY = "YOUR_YOUTUBE_API_KEY_HERE"
SPOTIPY_CLIENT_ID = "YOUR_SPOTIPY_CLIENT_ID_HERE"
SPOTIPY_CLIENT_SECRET = "YOUR_SPOTIPY_CLIENT_SECRET_HERE"
# ---------------------------------------------
Running the Python Script
Ensure you have completed the prerequisites (Python dependencies and FFmpeg executables in the script directory).
Run the script from your terminal:
python main.py
The script will prompt you to "Enter the Spotify Playlist URL or URI:"
Paste the full URL (e.g., https://open.spotify.com/playlist/YOUR_ID...) and press Enter.
The script will process each track, search YouTube, download, and convert the audio.
You can compile the script into a single executable file using PyInstaller (which you installed in Step 1):
Run the PyInstaller command in your terminal:
# Use 'py -m pyinstaller' if the 'pyinstaller' command is not recognized
py -m pyinstaller --onefile main.py
The final executable will be located in the newly created dist folder (e.g., dist/main.exe).
Note for sharing: If you share the main.exe file, the recipient must still place ffmpeg.exe and ffprobe.exe in the same folder as the executable for the conversion process to work.