Save downloaded covers as folder.jpg (Jellyfin standard), PNG→JPEG on download

- download_cover() now writes folder.jpg instead of _cover_download{ext}
- PNG responses are converted to JPEG via PIL during download (avoids PNG
  in the album directory entirely)
- find_local_cover() priority: folder > front > cover > album (folder.jpg
  is now the canonical name for both downloaded and manually placed covers)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-04-29 08:26:33 +02:00
commit 7516de439f

View file

@ -47,7 +47,7 @@ def _image_ok(path: Path) -> bool:
def find_local_cover(image_files: List[Path]) -> Optional[Path]: def find_local_cover(image_files: List[Path]) -> Optional[Path]:
priority = ("front", "folder", "cover", "album") priority = ("folder", "front", "cover", "album")
# Sort by priority keyword, then size descending # Sort by priority keyword, then size descending
def key(p: Path): def key(p: Path):
name = p.name.lower() name = p.name.lower()
@ -80,20 +80,27 @@ def download_cover(release_mbid: Optional[str], dest_dir: Path) -> Optional[Path
url = _mb_cover_url(release_mbid) url = _mb_cover_url(release_mbid)
if not url: if not url:
return None return None
dest = dest_dir / "folder.jpg"
try: try:
r = requests.get(url, timeout=15) r = requests.get(url, timeout=15)
if r.status_code == 200: if r.status_code != 200:
ext = ".jpg" return None
ct = r.headers.get("content-type", "") ct = r.headers.get("content-type", "")
if "png" in ct: if "png" in ct and HAS_PIL:
ext = ".png" # PNG → JPEG konvertieren
dest = dest_dir / f"_cover_download{ext}" import io
with Image.open(io.BytesIO(r.content)) as img:
buf = io.BytesIO()
img.convert("RGB").save(buf, format="JPEG", quality=92)
dest.write_bytes(buf.getvalue())
else:
dest.write_bytes(r.content) dest.write_bytes(r.content)
if _image_ok(dest): if _image_ok(dest):
return dest return dest
dest.unlink(missing_ok=True) dest.unlink(missing_ok=True)
except Exception as e: except Exception as e:
print(f" ⚠️ Cover-Download-Fehler: {e}", file=sys.stderr) print(f" ⚠️ Cover-Download-Fehler: {e}", file=sys.stderr)
dest.unlink(missing_ok=True)
return None return None