A simple Python script that fetches metadata (artist, album, track title, and cover art) from a Spotify track URL and embeds it into an existing MP3 file. The file is then renamed using the format:
Artist - Track Name.mp3
- Fetches track metadata from Spotify (artist, album, title).
- Embeds album cover art into the MP3 file.
- Automatically renames the file for proper organization.
- Easy to run directly from the command line.
- Python 3.7+
- Spotify API credentials (Client ID & Secret)
Clone the repository and install dependencies:
git clone https://github.com/blazturk/spotify-metadata-to-mp3.git
cd spotify-metadata-to-mp3
# (Optional) create a virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtDependencies used in the script:
- spotipy – Spotify Web API client
- eyed3 – MP3 tag editor
- python-dotenv – Loads Spotify API credentials from
.env
Create a .env file in the project root with your Spotify API credentials:
SPOTIPY_CLIENT_ID=your_client_id_here
SPOTIPY_CLIENT_SECRET=your_client_secret_here
SPOTIPY_REDIRECT_URI=http://localhost:8888/callback
Get these credentials from the Spotify Developer Dashboard.
Run the script with:
python app.pyYou’ll be prompted for:
- Spotify track URL
Example:Enter Spotify track URL : https://open.spotify.com/track/123456789 - Path to your MP3 file
Example:Enter path to audio file : ./music/mysong.mp3
The script will:
- Fetch metadata from Spotify.
- Embed artist, album, title, and cover art into the MP3.
- Rename the file to:
Artist - Track Name.mp3
Enter Spotify track URL : https://open.spotify.com/track/3n3Ppam7vgaVa1iaRUc9Lp
Enter path to audio file : ./downloads/test.mp3After running, the file will be updated and renamed to:
Daft Punk - Harder, Better, Faster, Stronger.mp3
This project is licensed under the MIT License – see the LICENSE file for details.