From d1fcfd544f4ae35ad0396838a7b29ab186a046ac Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 10 Jul 2026 23:57:28 +0200 Subject: [PATCH] fix: make album tagging best-effort per file Co-Authored-By: Claude Opus 4.8 (1M context) --- worker/lyra_worker/_mutagen.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/worker/lyra_worker/_mutagen.py b/worker/lyra_worker/_mutagen.py index 6390063..96aaffc 100644 --- a/worker/lyra_worker/_mutagen.py +++ b/worker/lyra_worker/_mutagen.py @@ -30,19 +30,23 @@ class MutagenTagger: names = os.listdir(album_dir) for old_name, new_name, title, number in plan_track_names(names, target.tracklist): - path = os.path.join(album_dir, old_name) - audio = mutagen.File(path, easy=True) - if audio is None: # unreadable/unsupported file — leave it untouched - continue - audio["artist"] = target.artist - audio["albumartist"] = target.artist - audio["album"] = target.album - audio["title"] = title - audio["tracknumber"] = str(number) - if target.year: - audio["date"] = str(target.year) - audio.save() + try: + path = os.path.join(album_dir, old_name) + audio = mutagen.File(path, easy=True) + if audio is None: # unreadable/unsupported file — leave it untouched + continue + audio["artist"] = target.artist + audio["albumartist"] = target.artist + audio["album"] = target.album + audio["title"] = title + audio["tracknumber"] = str(number) + if target.year: + audio["date"] = str(target.year) + audio.save() - new_path = os.path.join(album_dir, new_name) - if os.path.abspath(new_path) != os.path.abspath(path) and not os.path.exists(new_path): - os.rename(path, new_path) + new_path = os.path.join(album_dir, new_name) + if os.path.abspath(new_path) != os.path.abspath(path) and not os.path.exists(new_path): + os.rename(path, new_path) + except Exception as e: # best-effort: one bad track must not block the rest of the album + print(f"tagger: failed to tag {old_name} in {album_dir}: {e}", flush=True) + continue