Make the codebase mypy-clean, drop dead media_utils and Pillow, rewrite README
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ GLOBAL_CONFIG_FILE = Path(__file__).parent.parent.parent / ".Curator.!gtag"
|
||||
# folders (Dle …, Tipy dne, Nově přidané) before the genre folders at the root.
|
||||
# This lives in the code as the default; the effective schema is stored per-pool
|
||||
# in the index (``PoolIndex.settings["tag_schema"]``).
|
||||
DEFAULT_TAG_SCHEMA = [
|
||||
DEFAULT_TAG_SCHEMA: list[dict] = [
|
||||
{
|
||||
"category": "Žánr",
|
||||
"csfd_field": "genres",
|
||||
|
||||
@@ -112,7 +112,9 @@ class FileManager:
|
||||
def __init__(self, tagmanager: TagManager):
|
||||
self.filelist: list[File] = []
|
||||
self.tagmanager = tagmanager
|
||||
self.on_files_changed = None # callback do GUI
|
||||
self.on_files_changed: Callable[[list[File]], None] | None = (
|
||||
None # callback do GUI
|
||||
)
|
||||
self.global_config = load_global_config()
|
||||
self.index: PoolIndex | None = None # unified pool metadata + settings
|
||||
|
||||
@@ -689,7 +691,7 @@ class FileManager:
|
||||
total_size = 0
|
||||
with_nfo = 0
|
||||
untagged = 0
|
||||
ratings: list[int] = []
|
||||
ratings: list[float] = []
|
||||
categories: dict[str, Counter] = {}
|
||||
|
||||
for f in files:
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
# Module header
|
||||
import sys
|
||||
|
||||
from .file import File
|
||||
from .tag_manager import TagManager
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit("This module is not intended to be executed as the main program.")
|
||||
|
||||
# Imports
|
||||
import subprocess
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
|
||||
# Functions
|
||||
def load_icon(path) -> ImageTk.PhotoImage:
|
||||
img = Image.open(path)
|
||||
img = img.resize((16, 16), Image.Resampling.LANCZOS)
|
||||
return ImageTk.PhotoImage(img)
|
||||
|
||||
|
||||
def add_video_resolution_tag(file_obj: File, tagmanager: TagManager):
|
||||
"""
|
||||
Zjistí vertikální rozlišení videa a přiřadí tag Rozlišení/{výška}p.
|
||||
Vyžaduje ffprobe (FFmpeg).
|
||||
"""
|
||||
path = str(file_obj.file_path)
|
||||
try:
|
||||
# ffprobe vrátí width a height ve formátu JSON
|
||||
result = subprocess.run(
|
||||
[
|
||||
"ffprobe",
|
||||
"-v",
|
||||
"error",
|
||||
"-select_streams",
|
||||
"v:0",
|
||||
"-show_entries",
|
||||
"stream=width,height",
|
||||
"-of",
|
||||
"csv=p=0:s=x",
|
||||
path,
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
res = result.stdout.strip() # např. "1920x1080"
|
||||
if "x" not in res:
|
||||
return
|
||||
_width, height = map(int, res.split("x"))
|
||||
tag_name = f"Rozlišení/{height}p"
|
||||
tag_obj = tagmanager.add_tag("Rozlišení", f"{height}p")
|
||||
file_obj.add_tag(tag_obj)
|
||||
print(f"Přiřazen tag {tag_name} k {file_obj.filename}")
|
||||
except (OSError, subprocess.SubprocessError, ValueError) as e:
|
||||
print(f"Chyba při získávání rozlišení videa {file_obj.filename}: {e}")
|
||||
@@ -6,6 +6,7 @@ value (e.g. rating 87 → tag "Hodnocení/87"), while the folder groups it
|
||||
"""
|
||||
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
|
||||
|
||||
def rating_band(rating: int) -> str:
|
||||
@@ -18,14 +19,14 @@ def rating_band(rating: int) -> str:
|
||||
return f"{low}–{high} %"
|
||||
|
||||
|
||||
def _decade_band(value) -> str:
|
||||
def _decade_band(value: str) -> str:
|
||||
"""``decade_band`` transform: pull the leading integer and bucket it."""
|
||||
match = re.search(r"\d+", str(value))
|
||||
return rating_band(int(match.group())) if match else str(value)
|
||||
|
||||
|
||||
# Named value transforms usable from the tag schema (config-driven, extensible).
|
||||
TAG_TRANSFORMS = {
|
||||
TAG_TRANSFORMS: dict[str | None, Callable[[str], str]] = {
|
||||
None: str,
|
||||
"identity": str,
|
||||
"decade_band": _decade_band,
|
||||
|
||||
Reference in New Issue
Block a user