fix: make album tagging best-effort per file

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-10 23:57:28 +02:00
parent 32deac65a6
commit d1fcfd544f
+19 -15
View File
@@ -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