diff --git a/backend/app/downloads/storage.py b/backend/app/downloads/storage.py index cb405f3b..ec21cf3e 100644 --- a/backend/app/downloads/storage.py +++ b/backend/app/downloads/storage.py @@ -181,16 +181,23 @@ def _nfo_xml(meta: MediaMeta) -> str: return "\n".join(parts) +def _sidecar(media: Path, ext: str) -> Path: + """The sibling sidecar path (`.nfo` / `.jpg`) for a media file. Swaps the extension on the FULL + media path — NOT via `media.with_suffix("")` first: stripping the real extension leaves a stem + whose OWN last dot may be inside the title (e.g. "Sonka Házilag."), which `with_suffix` would + then read as the extension and clobber, orphaning the sidecar under a truncated name.""" + return media.with_suffix(ext) + + def write_sidecars( download_root: str, rel: str, meta: MediaMeta, thumb_src: Path | None ) -> bool: """Write `.nfo` + `.jpg` next to the media file. Returns True if written.""" media = abs_path(download_root, rel) - base = media.with_suffix("") try: - base.with_suffix(".nfo").write_text(_nfo_xml(meta), encoding="utf-8") + _sidecar(media, ".nfo").write_text(_nfo_xml(meta), encoding="utf-8") if thumb_src and thumb_src.exists(): - shutil.copyfile(str(thumb_src), str(base.with_suffix(".jpg"))) + shutil.copyfile(str(thumb_src), str(_sidecar(media, ".jpg"))) return True except OSError: return False @@ -199,8 +206,7 @@ def write_sidecars( def delete_asset_files(download_root: str, rel: str) -> None: """Remove the media file and its sidecars; prune now-empty parent dirs (best effort).""" media = abs_path(download_root, rel) - base = media.with_suffix("") - for p in (media, base.with_suffix(".nfo"), base.with_suffix(".jpg")): + for p in (media, _sidecar(media, ".nfo"), _sidecar(media, ".jpg")): try: p.unlink() except OSError: diff --git a/backend/tests/test_storage.py b/backend/tests/test_storage.py index 29b7fccb..d467e9a4 100644 --- a/backend/tests/test_storage.py +++ b/backend/tests/test_storage.py @@ -147,3 +147,26 @@ def test_nfo_uniqueid_type_reflects_the_source(): base = dict(video_id="v1", title="t", uploader="c", upload_date=None) assert '