I have maintained a curated collection of songs since around 15 years now. I don't trust my songs and mixes to always stay available on youtube, spotify etc.
I grade songs depending on how "fast" they make me feel from 0 to 4. And I rename the mp3 file based on that grade
Example - <grade>-<song title>
I want this naming system to show up on all my music players.
So, to get proper song titles on my phone, I need to copy the mp3's filename into the mp3's metadata's title field.
There are apps like EzTag etc to do this in bulk. But you have to manually open the app, select songs, and then make it copy filenames into tags. It is still a manual step. And I don't like repeating manual work.
Again, python to the rescue. As always.
Here is the script. It is dead simple.
from pathlib import Path
from mutagen.easyid3 import EasyID3
mp3_files = list(Path(".").rglob("*.mp3"))
for mp3_file in mp3_files:
metadata = EasyID3(mp3_file)
metadata['title']=mp3_file.stem
print(metadata['title'])
metadata.save()
Here is the makefile
SHELL = /bin/bash
set-tags:
source ~/venv/mp3tagger/bin/activate && python3 main.py
create-venv:
( \
mkdir -p ~/venv/;\
python3.10 -m venv ~/venv/mp3tagger;\
source ~/venv/mp3tagger/bin/activate;\
pip install -r requirements.txt\
)
A cron job automatically runs make set-tags
in this directory everyday, and my mp3's titles are always set - fresh and perfect.