Auto-fill ČSFD links on import, rename in pool, multi-country tags, Filmotéka layout

This commit is contained in:
2026-06-15 17:31:52 +02:00
parent 86c689b9f1
commit b3a61f9e86
18 changed files with 1407 additions and 168 deletions
+35 -5
View File
@@ -3,7 +3,8 @@ import json
from .tag import Tag
# Bump this when the csfd_cache schema changes to force re-fetch on next open.
CSFD_CACHE_VERSION = 1
# v2: country (str) → countries (list[str]) for co-productions.
CSFD_CACHE_VERSION = 2
class File:
@@ -109,6 +110,22 @@ class File:
elif self.metadata_filename.exists():
self.metadata_filename.unlink()
def relocate(self, new_path: Path) -> None:
"""Point this File at a new path, moving its metadata along.
The physical file must already have been moved/renamed by the caller.
Drops the metadata under the old path (index key or sidecar) and rebinds
to the new path; call ``save_metadata()`` afterwards to write it back.
"""
old_metadata_filename = self.metadata_filename
if self.index is not None:
self.index.delete(self.file_path)
self.file_path = Path(new_path)
self.filename = self.file_path.name
self.metadata_filename = self.file_path.parent / f".{self.filename}.!tag"
if self.index is None and old_metadata_filename.exists():
old_metadata_filename.rename(self.metadata_filename)
def set_date(self, date_str: str | None):
"""Nastaví datum (např. '2025-09-25') nebo None pro smazání."""
if date_str is None or date_str == "":
@@ -137,9 +154,18 @@ class File:
return None
def apply_csfd_tags(
self, add_genres: bool = True, add_year: bool = True, add_country: bool = True
self,
add_genres: bool = True,
add_year: bool = True,
add_country: bool = True,
add_rating: bool = True,
) -> dict:
"""Načte informace z CSFD a přiřadí tagy (Žánr, Rok, Země původu); cachuje data.
"""Načte informace z CSFD a přiřadí tagy; cachuje data.
Tagy: Žánr, Rok, Země původu a Hodnocení (procenta zařazená do desítkového
pásma, např. ``80–89 %``). Režie a herci se z ČSFD **stahují a cachují**
(``csfd_cache``), ale záměrně se z nich netvoří tagy ani složky — bylo by
jich příliš mnoho.
Returns:
dict s klíči 'success', 'movie'/'error', 'tags_added'
@@ -169,8 +195,12 @@ class File:
_add("Žánr", genre)
if add_year and movie.year:
_add("Rok", str(movie.year))
if add_country and movie.country:
_add("Země původu", movie.country)
if add_country:
for country in movie.countries:
_add("Země původu", country)
if add_rating and movie.rating is not None:
from .csfd import rating_band
_add("Hodnocení", rating_band(movie.rating))
# Use the CSFD title if we don't have one yet
if movie.title and not self.title: