Migrate from Poetry and pyenv to uv
This commit is contained in:
+17
-13
@@ -8,12 +8,12 @@ recover its **ČSFD link** (and title / year) from that sidecar — or from an o
|
||||
|
||||
This is read-only recovery for the import dialog; nothing here writes.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path, PurePosixPath
|
||||
from typing import Optional
|
||||
|
||||
from .pool_index import INDEX_FILENAME
|
||||
|
||||
@@ -25,13 +25,13 @@ _MAX_INDEX_WALK_UP = 4
|
||||
class LegacyMeta:
|
||||
"""What an old sidecar / index record can still tell us about a movie."""
|
||||
|
||||
csfd_url: Optional[str] = None
|
||||
title: Optional[str] = None
|
||||
year: Optional[str] = None # four-digit string
|
||||
source: str = "" # "sidecar" | "index"
|
||||
csfd_url: str | None = None
|
||||
title: str | None = None
|
||||
year: str | None = None # four-digit string
|
||||
source: str = "" # "sidecar" | "index"
|
||||
|
||||
|
||||
def _record_to_meta(record: object, source: str) -> Optional[LegacyMeta]:
|
||||
def _record_to_meta(record: object, source: str) -> LegacyMeta | None:
|
||||
"""Pull the useful fields out of a stored movie record (any schema version)."""
|
||||
if not isinstance(record, dict):
|
||||
return None
|
||||
@@ -42,24 +42,28 @@ def _record_to_meta(record: object, source: str) -> Optional[LegacyMeta]:
|
||||
cache_raw = record.get("csfd_cache")
|
||||
cache = cache_raw if isinstance(cache_raw, dict) else {}
|
||||
raw_year = meta.get("year") or cache.get("year")
|
||||
year = str(raw_year).strip() if raw_year is not None and str(raw_year).strip().isdigit() else None
|
||||
year = (
|
||||
str(raw_year).strip()
|
||||
if raw_year is not None and str(raw_year).strip().isdigit()
|
||||
else None
|
||||
)
|
||||
if not (csfd or title or year):
|
||||
return None
|
||||
return LegacyMeta(csfd_url=csfd or None, title=title, year=year, source=source)
|
||||
|
||||
|
||||
def _from_sidecar(video_path: Path) -> Optional[LegacyMeta]:
|
||||
def _from_sidecar(video_path: Path) -> LegacyMeta | None:
|
||||
sidecar = video_path.parent / f".{video_path.name}{SIDECAR_SUFFIX}"
|
||||
if not sidecar.is_file():
|
||||
return None
|
||||
try:
|
||||
record = json.loads(sidecar.read_text(encoding="utf-8"))
|
||||
except (json.JSONDecodeError, OSError, ValueError):
|
||||
except json.JSONDecodeError, OSError, ValueError:
|
||||
return None
|
||||
return _record_to_meta(record, "sidecar")
|
||||
|
||||
|
||||
def _lookup_in_index(movies: dict, video_path: Path, index_dir: Path) -> Optional[dict]:
|
||||
def _lookup_in_index(movies: dict, video_path: Path, index_dir: Path) -> dict | None:
|
||||
"""Find the record for ``video_path`` in an index's ``movies`` map.
|
||||
|
||||
Tries the exact pool-relative key first, then falls back to a unique
|
||||
@@ -76,14 +80,14 @@ def _lookup_in_index(movies: dict, video_path: Path, index_dir: Path) -> Optiona
|
||||
return matches[0] if len(matches) == 1 else None
|
||||
|
||||
|
||||
def _from_legacy_index(video_path: Path) -> Optional[LegacyMeta]:
|
||||
def _from_legacy_index(video_path: Path) -> LegacyMeta | None:
|
||||
directory = video_path.parent
|
||||
for _ in range(_MAX_INDEX_WALK_UP + 1):
|
||||
index_path = directory / INDEX_FILENAME
|
||||
if index_path.is_file():
|
||||
try:
|
||||
data = json.loads(index_path.read_text(encoding="utf-8"))
|
||||
except (json.JSONDecodeError, OSError, ValueError):
|
||||
except json.JSONDecodeError, OSError, ValueError:
|
||||
return None
|
||||
movies = data.get("movies", data) if isinstance(data, dict) else None
|
||||
if not isinstance(movies, dict):
|
||||
@@ -96,7 +100,7 @@ def _from_legacy_index(video_path: Path) -> Optional[LegacyMeta]:
|
||||
return None
|
||||
|
||||
|
||||
def read_legacy_meta(video_path: Path) -> Optional[LegacyMeta]:
|
||||
def read_legacy_meta(video_path: Path) -> LegacyMeta | None:
|
||||
"""Recover ČSFD link / title / year from a pre-index layout, or ``None``.
|
||||
|
||||
Order: a per-file ``.{name}.!tag`` sidecar next to the video, then a
|
||||
|
||||
Reference in New Issue
Block a user