spotitag.py is an interactive command-line Spotify metadata helper for local music files. It searches Spotify, previews candidate track metadata, shows album art, writes clean tags to supported audio files, can rename files using Spotify metadata, and can also export Spotify metadata to a plain .txt file when you search by title and artist.
The script is designed for people who maintain local music libraries and want a fast way to match files against Spotify metadata without losing control over what gets written.
The script was originally designed for MacOS but should have no issues running on other systems. If not, feel free to update code to work for you.
NOTE: spotitag.py uses the Spotify developer API to fetch metadata, and therefore requires an active Premium account. Directions below on setup.
This script does NOT download song files. It is only used for metadata.
spotitag.py supports two main workflows:
-
Tag an existing audio file or folder
- Search Spotify using the existing filename.
- Review candidate Spotify matches.
- Accept, skip, go to the next result, skip the file, accept for all files, skip all, or quit.
- Choose exactly what tags get written.
- Optionally exclude fields such as title, artist, album, year, filename, or image.
- Optionally skip album art.
- Rename the file using clean Spotify metadata.
-
Search by title and artist only
- Search Spotify using a title and artist name.
- Review candidate results.
- Save the selected Spotify metadata as a plain
.txtfile.
- Search Spotify for track metadata.
- Works with a single file or a folder of music files.
- Supports command-line arguments and interactive prompts.
- Tags common audio formats:
.mp3.flac.ogg.m4a
- Writes the following metadata fields from Spotify:
- Title
- Artist
- Album
- Album Artist
- Date
- Year
- Track Number
- Disc Number
- Length
- ISRC
- UPC
- All Artists
- Downloads and embeds album art when available.
- Shows album art preview when supported by your system.
- Removes duplicate year/date-style fields where applicable.
- Keeps featured artists out of filenames while preserving them in metadata when appropriate.
- Preserves remix/edit/version/demo-style titles carefully.
- Lets you exclude individual fields before writing tags.
- Exports Spotify metadata to a
.txtfile when searching by title and artist.
Install Python 3. Recommended:
python3 --versionInstall the required packages:
python3 -m pip install spotipy mutagen requests pillowPackage purpose:
| Package | Purpose |
|---|---|
spotipy |
Connects to the Spotify Web API |
mutagen |
Reads and writes audio metadata tags |
requests |
Downloads album art |
pillow |
Displays album art previews when Tkinter is available |
Album art preview uses tkinter plus Pillow when available.
On macOS, Tkinter is often available with the system Python or Python.org installers. If image preview does not work, the tagging and metadata export features can still work.
spotitag.py uses Spotify API credentials through environment variables:
SPOTIPY_CLIENT_IDSPOTIPY_CLIENT_SECRET
These are required before running the script.
- Go to the Spotify Developer Dashboard.
- Log in with your Spotify account.
- Create a new app.
- Select or enable the Web API option if prompted.
- Open the app settings.
- Copy your Client ID.
- Click to view and copy your Client Secret.
You do not need user playlist permissions for this script. It uses Spotify search and public track/album metadata.
Replace the example values with your real Spotify credentials.
export SPOTIPY_CLIENT_ID="your_client_id_here"
export SPOTIPY_CLIENT_SECRET="your_client_secret_here"Then run the script from the same terminal window:
python3 spotitag.pyIf you use zsh, which is the default shell on newer macOS versions:
echo 'export SPOTIPY_CLIENT_ID="your_client_id_here"' >> ~/.zshrc
echo 'export SPOTIPY_CLIENT_SECRET="your_client_secret_here"' >> ~/.zshrc
source ~/.zshrcIf you use bash:
echo 'export SPOTIPY_CLIENT_ID="your_client_id_here"' >> ~/.bashrc
echo 'export SPOTIPY_CLIENT_SECRET="your_client_secret_here"' >> ~/.bashrc
source ~/.bashrcOn some macOS bash setups, use ~/.bash_profile instead:
echo 'export SPOTIPY_CLIENT_ID="your_client_id_here"' >> ~/.bash_profile
echo 'export SPOTIPY_CLIENT_SECRET="your_client_secret_here"' >> ~/.bash_profile
source ~/.bash_profileFor the current PowerShell session only:
$env:SPOTIPY_CLIENT_ID="your_client_id_here"
$env:SPOTIPY_CLIENT_SECRET="your_client_secret_here"To save them permanently for your user account:
[Environment]::SetEnvironmentVariable("SPOTIPY_CLIENT_ID", "your_client_id_here", "User")
[Environment]::SetEnvironmentVariable("SPOTIPY_CLIENT_SECRET", "your_client_secret_here", "User")Close and reopen PowerShell after setting permanent variables.
Clone or download the repository, then place spotitag.py wherever you want to run it.
Example:
git clone https://github.com/Kappa-Kappa/SpotiTag.git
cd SpotiTag
python3 -m pip install spotipy mutagen requests pillowMake sure your Spotify credentials are exported before running the script.
There are two ways to use the script:
- Provide arguments directly when calling the script.
- Run the script with no arguments and enter the path or search terms when prompted.
python3 spotitag.py /Path/To/Song.flacExample (Use " or ' if file name has spaces):
python3 spotitag.py '/Users/John/Music/Party in the USA - Miley Cyrus.flac'The script will:
- Read the file name/tags.
- Pick the likely title and artist.
- Search Spotify.
- Show candidate matches.
- Let you accept, skip, or move through results.
- Ask what should be written.
- Write tags and optionally rename the file.
python3 spotitag.py /Path/To/Music/FolderExample (Use " or ' if folder name has spaces):
python3 spotitag.py '/Users/John/Music Folder'The script scans the folder for supported files:
.mp3, .flac, .ogg, .m4a
It then processes each file interactively.
Run the script with no arguments:
python3 spotitag.pyWhen prompted, enter a file or folder path (Do not use " or ' , even if file/folder name has spaces, or will say file doesn't exist):
Enter file/folder path OR search term ('title' 'artist'): /Path/To/Music/Folder
OR:
Enter file/folder path OR search term ('title' 'artist'): /Path/To/Music/Party in the USA - Miley Cyrus.flac
Use this mode when you do not want to tag an audio file. The script searches Spotify and saves the selected metadata to a .txt file.
(Requires ' or ")
python3 spotitag.py 'Song Title' 'Artist Name'Example:
python3 spotitag.py 'Party in the USA' 'Miley Cyrus'Run:
python3 spotitag.pyThen enter quoted title and artist search terms (Requires ' or "):
Enter file/folder path OR search term ('title' 'artist'): 'Party in the USA' 'Miley Cyrus'
The script will show Spotify results. When you accept one, it saves a metadata .txt file in the current working directory.
The saved text file includes metadata only, for example:
ALBUM: Example Album
ALBUMARTIST: Example Artist
ALL_ARTISTS: Example Artist
ARTIST: Example Artist
DATE: 2024-01-01
DISCNUMBER: 1
ISRC: USXXX0000000
LENGTH: 3:42
TITLE: Example Song
TRACK: 1
YEAR: 2024
SPOTIFY_URL: https://open.spotify.com/track/...
SPOTIFY_ID: ...
When reviewing a Spotify result for an audio file, you will see options like:
[y] accept [n] next [x] skip-file
[a] accept-all [s] skip-all [q] quit
| Option | Meaning |
|---|---|
y |
Accept this Spotify result for the current file |
n |
Show the next Spotify result |
x |
Skip the current file |
a |
Accept this result and continue accepting for later files where applicable |
s |
Skip all remaining files |
q |
Quit the script |
After accepting a result, you will be asked what should be written:
[1] import all tags & image
[2] import tags & choose exclusions
[3] import tags but skip image
[4] go back to search results
| Option | Meaning |
|---|---|
1 |
Write all available metadata and album art |
2 |
Choose fields to exclude before writing |
3 |
Write metadata tags but do not embed album art |
4 |
Go back to the search results without writing this candidate |
When you choose option 2, you can exclude fields from being written.
Example:
Enter exclusions (comma-separated: title, artist, album, year, filename, image, etc.): filename, image, title
Common exclusions:
| Exclusion | Effect |
|---|---|
title |
Do not overwrite the title tag |
artist |
Do not overwrite the artist tag |
album |
Do not overwrite the album tag |
year |
Do not overwrite year/date-style fields |
filename |
Do not rename the file |
image |
Do not embed album art |
track |
Do not overwrite track number |
discnumber |
Do not overwrite disc number |
isrc |
Do not write ISRC |
upc |
Do not write UPC |
length |
Do not write track length |
You can separate exclusions with commas.
When tagging a file, the script may suggest and apply a cleaner filename based on Spotify metadata.
The general format is:
Title - Artist.ext
The script attempts to keep featured artists out of filenames while preserving the proper metadata inside the audio tags.
Example:
Existing Filename: Telephone (feat. Beyonce) - Lady GaGa.flac
Suggested Filename: Telephone - Lady GaGa.flac
To prevent renaming, choose exclusions and include 'filename':
Enter exclusions (comma-separated: title, artist, album, year, filename, image, etc.): filename
python3 spotitag.py '/Users/John/Music/Telephone - Lady GaGa.flac'python3 spotitag.py /Users/John/Musicpython3 spotitag.pyThen enter:
/Users/John/Music/MyLibrary
python3 spotitag.py 'Telephone' 'Lady GaGa'python3 spotitag.pyThen enter:
'Telephone' 'Lady GaGa'
- Accept a result with
y. - Choose option
3.
[3] import tags but skip image
- Accept a result with
y. - Choose option
2. - Enter:
filename
- Accept a result with
y. - Choose option
2. - Enter:
filename, image
Use folder mode to process a directory of files one by one and bring titles, artists, album names, dates, track numbers, and artwork in line with Spotify metadata.
Use single-file mode when a track has missing or incorrect metadata.
Use title/artist mode to save a .txt metadata file for reference, cataloging, or manual use elsewhere.
Use the filename exclusion whenever you want metadata tags updated but want the current file name preserved.
Use option 3 and exclude title, artist, album, year, filename, track, discnumber, isrc, upc, length if you only want embedded artwork.
Your Spotify API credentials are not currently available to the script.
Run:
export SPOTIPY_CLIENT_ID="your_client_id_here"
export SPOTIPY_CLIENT_SECRET="your_client_secret_here"Then try again from the same terminal window.
Try a cleaner title and artist search.
For example, instead of:
python3 spotitag.py "Song Title (Very Specific Remix Version)" "Artist feat Someone"Try:
python3 spotitag.py "Song Title" "Artist"Make sure you are correctly using ' or " around file path. See Usage Mode 1 section above.
The script can still tag files and save metadata. The preview window depends on optional GUI support from Tkinter and Pillow.
Install Pillow:
python3 -m pip install pillowIf Tkinter is unavailable, install a Python distribution that includes Tkinter or continue without preview support.
When accepting a result, choose:
[2] import tags & choose exclusions
Then enter:
filename
- Back up important music files before bulk tagging.
- Test on a small folder first.
- Spotify metadata may not always match your preferred library style.
- Use exclusions when you want to preserve specific existing tags.
- Keep your Spotify Client Secret private. Do not commit it to GitHub.
spotitag/
├── spotitag.py
├── README.md
└── requirements.txt
Optional requirements.txt:
spotipy
mutagen
requests
pillow
Then users can install dependencies with:
python3 -m pip install -r requirements.txtThis tool is not affiliated with Spotify. It uses Spotify metadata through the Spotify Web API. You are responsible for complying with Spotify's Developer Terms and for keeping your API credentials secure.

