Migrate from Poetry and pyenv to uv
This commit is contained in:
+9
-10
@@ -9,25 +9,25 @@ The classification is deliberately **conservative**: only an exact
|
||||
(diacritics-insensitive) title match with a matching year and a single candidate
|
||||
is ``auto``; everything else is ``ambiguous`` for the user to confirm.
|
||||
"""
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class MatchProposal:
|
||||
"""One movie's proposed TMDb match."""
|
||||
|
||||
file: object # core.file.File
|
||||
file: object # core.file.File
|
||||
current_name: str
|
||||
title: str
|
||||
year: Optional[str]
|
||||
status: str # "auto" | "ambiguous" | "no_match" | "error"
|
||||
chosen: object = None # tmdb.TmdbResult preselected for the user, or None
|
||||
year: str | None
|
||||
status: str # "auto" | "ambiguous" | "no_match" | "error"
|
||||
chosen: object = None # tmdb.TmdbResult preselected for the user, or None
|
||||
candidates: list = field(default_factory=list) # list[tmdb.TmdbResult]
|
||||
error: str = ""
|
||||
note: str = "" # e.g. "přes ČSFD: The Shawshank Redemption (1994)"
|
||||
note: str = "" # e.g. "přes ČSFD: The Shawshank Redemption (1994)"
|
||||
|
||||
|
||||
def normalize(text: str) -> str:
|
||||
@@ -38,13 +38,13 @@ def normalize(text: str) -> str:
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
|
||||
|
||||
def _year_close(a: Optional[str], b: Optional[str]) -> bool:
|
||||
def _year_close(a: str | None, b: str | None) -> bool:
|
||||
if not (a and b and str(a).isdigit() and str(b).isdigit()):
|
||||
return False
|
||||
return abs(int(a) - int(b)) <= 1
|
||||
|
||||
|
||||
def classify(title: str, year: Optional[str], candidates: list) -> tuple[str, object]:
|
||||
def classify(title: str, year: str | None, candidates: list) -> tuple[str, object]:
|
||||
"""Return ``(status, chosen)`` for a title/year against TMDb candidates.
|
||||
|
||||
``auto`` requires an exact normalized-title match, a year within ±1, and that
|
||||
@@ -55,8 +55,7 @@ def classify(title: str, year: Optional[str], candidates: list) -> tuple[str, ob
|
||||
return "no_match", None
|
||||
nt = normalize(title)
|
||||
exact_year = [
|
||||
c for c in candidates
|
||||
if normalize(c.title) == nt and _year_close(c.year, year)
|
||||
c for c in candidates if normalize(c.title) == nt and _year_close(c.year, year)
|
||||
]
|
||||
if len(exact_year) == 1:
|
||||
return "auto", exact_year[0]
|
||||
|
||||
Reference in New Issue
Block a user