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) names = os.listdir(album_dir)
for old_name, new_name, title, number in plan_track_names(names, target.tracklist): for old_name, new_name, title, number in plan_track_names(names, target.tracklist):
path = os.path.join(album_dir, old_name) try:
audio = mutagen.File(path, easy=True) path = os.path.join(album_dir, old_name)
if audio is None: # unreadable/unsupported file — leave it untouched audio = mutagen.File(path, easy=True)
continue if audio is None: # unreadable/unsupported file — leave it untouched
audio["artist"] = target.artist continue
audio["albumartist"] = target.artist audio["artist"] = target.artist
audio["album"] = target.album audio["albumartist"] = target.artist
audio["title"] = title audio["album"] = target.album
audio["tracknumber"] = str(number) audio["title"] = title
if target.year: audio["tracknumber"] = str(number)
audio["date"] = str(target.year) if target.year:
audio.save() audio["date"] = str(target.year)
audio.save()
new_path = os.path.join(album_dir, new_name) 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): if os.path.abspath(new_path) != os.path.abspath(path) and not os.path.exists(new_path):
os.rename(path, 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