Adopt "Title (YYYY)" pool naming and clean Filmotéka link names

This commit is contained in:
2026-07-27 20:51:31 +02:00
parent 4c4180f28c
commit 1c78ca9013
13 changed files with 784 additions and 145 deletions
+63
View File
@@ -409,6 +409,69 @@ class TestPoolManagement:
with pytest.raises(ValueError):
file_manager.rename_movie(movie, " ")
def test_import_movie_with_year_uses_convention(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
source = tmp_path / "raw.mkv"
source.write_bytes(b"x" * 10)
movie = file_manager.import_movie(source, "Matrix", year=1999)
assert movie.file_path.name == "Matrix (1999).mkv"
assert movie.title == "Matrix" # clean title, no year
def test_import_movie_rejects_invalid_year(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "a.mkv").write_bytes(b"a")
with pytest.raises(ValueError):
file_manager.import_movie(tmp_path / "a.mkv", "Matrix", year="99")
def test_import_same_title_different_year_coexist(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", "Solaris", year=1972)
second = file_manager.import_movie(tmp_path / "b.mkv", "Solaris", year=2002)
assert first.file_path.name == "Solaris (1972).mkv"
assert second.file_path.name == "Solaris (2002).mkv" # no collision/suffix
def test_rename_to_canonical_from_csfd_year(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "raw.mkv").write_bytes(b"x")
movie = file_manager.import_movie(tmp_path / "raw.mkv", "Matrix") # plain
assert movie.file_path.name == "Matrix.mkv"
movie.csfd_cache = {"year": 1999}
renamed = file_manager.rename_to_canonical(movie)
assert renamed is not None
assert movie.file_path.name == "Matrix (1999).mkv"
assert movie.title == "Matrix"
def test_rename_to_canonical_skips_without_year(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
(tmp_path / "raw.mkv").write_bytes(b"x")
movie = file_manager.import_movie(tmp_path / "raw.mkv", "Unknown")
assert file_manager.rename_to_canonical(movie) is None
assert movie.file_path.name == "Unknown.mkv" # untouched
def test_rename_all_to_canonical_reports(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
for n in ("a.mkv", "b.mkv", "c.mkv"):
(tmp_path / n).write_bytes(b"x")
with_year = file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
with_year.csfd_cache = {"year": 1999}
already = file_manager.import_movie(tmp_path / "b.mkv", "Solaris", year=1972)
_no_year = file_manager.import_movie(tmp_path / "c.mkv", "Mystery")
result = file_manager.rename_all_to_canonical(file_manager.filelist)
assert result["renamed"] == [("Matrix.mkv", "Matrix (1999).mkv")]
assert result["unchanged"] == 1 # Solaris (1972) already canonical
assert result["skipped_no_year"] == ["Mystery.mkv"]
assert already.file_path.name == "Solaris (1972).mkv"
def test_load_pool_movies_reads_from_index(self, file_manager, tmp_path):
file_manager.set_pool_dir(tmp_path / "pool")
source = tmp_path / "raw.mkv"