Add per-movie attributes and per-category filename templates

This commit is contained in:
2026-06-16 17:39:39 +02:00
parent b3a61f9e86
commit a71b209539
19 changed files with 1064 additions and 111 deletions
+64
View File
@@ -603,6 +603,70 @@ class TestPoolManagement:
assert movie.file_path.exists()
assert not source.exists() # moved, not copied
def test_filmoteka_category_roots_from_schema(self, file_manager):
file_manager.set_tag_schema([
{"category": "Žánr", "csfd_field": "genres", "transform": None, "filmoteka_root": ""},
{"category": "Rok", "csfd_field": "year", "transform": None, "filmoteka_root": "Dle roku"},
{"category": "Herec", "csfd_field": "actors", "transform": None, "filmoteka_root": None},
])
roots = file_manager.filmoteka_category_roots()
assert roots == {"Žánr": "", "Rok": "Dle roku"} # None-root excluded
assert "Herec" not in roots
def test_import_movie_suffix_keeps_both(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "a.mkv").write_bytes(b"a")
(tmp_path / "b.mkv").write_bytes(b"b")
first = file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
second = file_manager.import_movie(tmp_path / "b.mkv", "Matrix") # default suffix
assert first.file_path.name == "Matrix.mkv"
assert second.file_path.name == "Matrix_1.mkv"
assert len(file_manager.filelist) == 2
def test_import_movie_replace_evicts_existing(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "a.mkv").write_bytes(b"a")
(tmp_path / "b.mkv").write_bytes(b"bb")
first = file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
first.add_tag("Žánr/Akční")
old_path = first.file_path
second = file_manager.import_movie(
tmp_path / "b.mkv", "Matrix", csfd_link="x", on_conflict="replace")
assert second.file_path.name == "Matrix.mkv"
assert second.file_path == old_path # same name reused
assert second.file_path.read_bytes() == b"bb" # new content in place
assert [f.file_path.name for f in file_manager.filelist] == ["Matrix.mkv"]
# index record reflects the new import (fresh metadata, old tags dropped)
record = file_manager.index.get(second.file_path)
assert record is not None
assert record["csfd_link"] == "x"
assert record["tags"] == []
assert second.tags == []
def test_import_movie_replace_across_extensions(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "a.mkv").write_bytes(b"a")
(tmp_path / "b.mp4").write_bytes(b"b")
file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
file_manager.import_movie(tmp_path / "b.mp4", "Matrix", on_conflict="replace")
names = [f.file_path.name for f in file_manager.filelist]
assert names == ["Matrix.mp4"]
assert not (tmp_path / "pool" / "Filmy" / "Matrix.mkv").exists()
def test_import_movie_skip_returns_none(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "a.mkv").write_bytes(b"a")
(tmp_path / "b.mkv").write_bytes(b"b")
file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
result = file_manager.import_movie(tmp_path / "b.mkv", "Matrix", on_conflict="skip")
assert result is None
assert len(file_manager.filelist) == 1
def test_rename_movie_renames_file_and_reindexes(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
source = tmp_path / "raw.mkv"