Fix cover metadata bugs: concurrency locks and FFmpeg video stream stripping

This commit is contained in:
joel
2026-07-20 17:26:26 +02:00
parent 293aa5a907
commit c2d050ed71
2 changed files with 48 additions and 26 deletions
+26 -24
View File
@@ -51,6 +51,8 @@ def extract_event_from_folder(file_path: Path) -> tuple[str, str]:
return "", ""
from mutagen.id3 import ID3, APIC, TIT2, TPE1, TALB, TRCK, TDRC
def apply_id3_tags(
mp3_path: Path,
title: str,
@@ -58,31 +60,31 @@ def apply_id3_tags(
album: str,
track_number: int,
year: str,
cover_path: Path | None = None,
cover_data: bytes | None = None,
cover_mime: str = "image/jpeg",
) -> None:
"""Schreibt ID3-Metadaten und optional ein Cover in die MP3-Datei."""
audiofile = EasyID3(str(mp3_path))
audiofile["title"] = title
audiofile["artist"] = artist or "Unbekannt"
audiofile["album"] = album or "Unbekanntes Album"
audiofile["tracknumber"] = str(track_number)
audiofile["date"] = year
audiofile.save()
try:
tags = ID3(str(mp3_path))
except Exception:
tags = ID3()
if cover_path and cover_path.exists():
audio_id3 = ID3(str(mp3_path))
mime = "image/jpeg"
suffix = cover_path.suffix.lower()
if suffix == ".png":
mime = "image/png"
with open(cover_path, "rb") as img:
audio_id3.add(
APIC(
encoding=3,
mime=mime,
type=3,
desc="Cover",
data=img.read(),
)
tags.add(TIT2(encoding=3, text=title))
tags.add(TPE1(encoding=3, text=artist or "Unbekannt"))
tags.add(TALB(encoding=3, text=album or "Unbekanntes Album"))
tags.add(TRCK(encoding=3, text=str(track_number)))
if year:
tags.add(TDRC(encoding=3, text=year))
if cover_data:
tags.add(
APIC(
encoding=3,
mime=cover_mime,
type=3,
desc="Cover",
data=cover_data,
)
audio_id3.save()
)
tags.save(str(mp3_path), v2_version=3)