✨ UI dynamique (couleurs par etat, spinner, terminal de conversion live, restes de conversion, liens MKV), responsive, scan ISO par contenu, retrait Sonarr/Prowlarr/Jellyfin/Seerr
This commit is contained in:
1 parent
078905e944
commit
70ce0b95a8
20 files changed
+793
-1143
No files matched your search
+137
-35
@@ -164,26 +164,40 @@ def test_scan_marks_missing_radarr_files_as_unlinked() -> None:
|
||||
assert movie["status"] == "detected"
|
||||
|
||||
|
||||
class FakePopen:
|
||||
"""Remplace subprocess.Popen pour les tests: sortie en flux + code retour."""
|
||||
|
||||
def __init__(self, lines: list[str], returncode: int) -> None:
|
||||
self.stdout = iter(line if line.endswith("\n") else line + "\n" for line in lines)
|
||||
self._returncode = returncode
|
||||
|
||||
def __enter__(self) -> "FakePopen":
|
||||
return self
|
||||
|
||||
def __exit__(self, *args: object) -> bool:
|
||||
return False
|
||||
|
||||
def wait(self) -> int:
|
||||
return self._returncode
|
||||
|
||||
|
||||
SHAREWARE_OUTPUT = [
|
||||
"This functionality is shareware. You may evaluate it for 30 days "
|
||||
"after what you would need to purchase an activation key.",
|
||||
"Do you want to start evaluation period now?",
|
||||
"Evaluation version, 30 day(s) out of 30 remaining",
|
||||
]
|
||||
|
||||
|
||||
def test_extract_fails_with_activation_error_when_makemkv_unactivated(
|
||||
monkeypatch, tmp_path
|
||||
) -> None:
|
||||
"""Sans cle MakeMKV (message shareware), l'erreur guide vers l'activation."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
monkeypatch.setattr(settings, "simulate_conversion", False)
|
||||
monkeypatch.setattr("app.converter.shutil.which", lambda _: "/usr/bin/makemkvcon")
|
||||
monkeypatch.setattr(
|
||||
"app.converter.subprocess.run",
|
||||
lambda *args, **kwargs: SimpleNamespace(
|
||||
returncode=10,
|
||||
stdout=(
|
||||
"This functionality is shareware. You may evaluate it for 30 days "
|
||||
"after what you would need to purchase an activation key.\n"
|
||||
"Do you want to start evaluation period now?\n"
|
||||
"Evaluation version, 30 day(s) out of 30 remaining"
|
||||
),
|
||||
stderr="",
|
||||
),
|
||||
"app.converter.subprocess.Popen",
|
||||
lambda args, **kwargs: FakePopen(SHAREWARE_OUTPUT, 10),
|
||||
)
|
||||
movie = IsoMovie(
|
||||
radarr_movie_id=1, radarr_movie_file_id=2, title="ISO Movie", path="/x.iso"
|
||||
@@ -199,13 +213,11 @@ def test_extract_fails_with_activation_error_when_makemkv_unactivated(
|
||||
|
||||
def test_extract_reports_signal_kill(monkeypatch, tmp_path) -> None:
|
||||
"""Un processus tue par signal (ex: OOM) est identifie dans l'erreur."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
monkeypatch.setattr(settings, "simulate_conversion", False)
|
||||
monkeypatch.setattr("app.converter.shutil.which", lambda _: "/usr/bin/makemkvcon")
|
||||
monkeypatch.setattr(
|
||||
"app.converter.subprocess.run",
|
||||
lambda *args, **kwargs: SimpleNamespace(returncode=-9, stdout="", stderr=""),
|
||||
"app.converter.subprocess.Popen",
|
||||
lambda args, **kwargs: FakePopen([], -9),
|
||||
)
|
||||
movie = IsoMovie(
|
||||
radarr_movie_id=1, radarr_movie_file_id=2, title="ISO Movie", path="/x.iso"
|
||||
@@ -218,34 +230,124 @@ def test_extract_reports_signal_kill(monkeypatch, tmp_path) -> None:
|
||||
raise AssertionError("RuntimeError attendue")
|
||||
|
||||
|
||||
def test_extract_picks_longest_title(monkeypatch, tmp_path) -> None:
|
||||
"""Le titre extrait est le plus long, pas le numero 0."""
|
||||
from types import SimpleNamespace
|
||||
def test_extract_picks_longest_title_and_streams_log(monkeypatch, tmp_path) -> None:
|
||||
"""Le titre extrait est le plus long, et la sortie est diffusee en flux."""
|
||||
robot_info = [
|
||||
'MSG:1005,0,1,"MakeMKV started"',
|
||||
'TINFO:0,9,0,"0:02:30"',
|
||||
'TINFO:1,9,0,"1:57:00"',
|
||||
'TINFO:2,9,0,"0:24:13"',
|
||||
]
|
||||
seen_lines: list[str] = []
|
||||
|
||||
robot_info = "\n".join(
|
||||
[
|
||||
'MSG:1005,0,1,"MakeMKV started"',
|
||||
'TINFO:0,9,0,"0:02:30"',
|
||||
'TINFO:1,9,0,"1:57:00"',
|
||||
'TINFO:2,9,0,"0:24:13"',
|
||||
]
|
||||
)
|
||||
|
||||
def fake_run(args, **kwargs):
|
||||
def fake_popen(args, **kwargs):
|
||||
if "--robot" in args:
|
||||
return SimpleNamespace(returncode=0, stdout=robot_info, stderr="")
|
||||
# Commande mkv: on verifie le titre choisi et on simule la sortie.
|
||||
return FakePopen(robot_info, 0)
|
||||
assert args[3] == "1", f"titre attendu: 1, commande: {args}"
|
||||
out = tmp_path / "out"
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
(out / "movie.mkv").write_text("mkv")
|
||||
return SimpleNamespace(returncode=0, stdout="", stderr="")
|
||||
return FakePopen(["Saving 1 titles", "1 titles saved"], 0)
|
||||
|
||||
monkeypatch.setattr(settings, "simulate_conversion", False)
|
||||
monkeypatch.setattr("app.converter.shutil.which", lambda _: "/usr/bin/makemkvcon")
|
||||
monkeypatch.setattr("app.converter.subprocess.run", fake_run)
|
||||
monkeypatch.setattr("app.converter.subprocess.Popen", fake_popen)
|
||||
movie = IsoMovie(
|
||||
radarr_movie_id=1, radarr_movie_file_id=2, title="ISO Movie", path="/x.iso"
|
||||
)
|
||||
extract_mkv(movie, tmp_path / "out" / "movie.mkv")
|
||||
extract_mkv(
|
||||
movie, tmp_path / "out" / "movie.mkv", lambda line: seen_lines.append(line)
|
||||
)
|
||||
assert (tmp_path / "out" / "movie.mkv").exists()
|
||||
# Les lignes des deux commandes (info + mkv) ont ete diffusees.
|
||||
assert any("TINFO" in line for line in seen_lines)
|
||||
assert "1 titles saved" in seen_lines
|
||||
|
||||
|
||||
def test_looks_like_iso_rejects_renamed_mkv() -> None:
|
||||
"""Un fichier .iso dont l'en-tete est EBML est un MKV renomme: ecarte."""
|
||||
from app.converter import EBML_MAGIC, looks_like_iso
|
||||
|
||||
iso_file = settings.films_dir / "Dossier"
|
||||
iso_file.mkdir(parents=True, exist_ok=True)
|
||||
real_iso = iso_file / "Film (2025).iso"
|
||||
fake_iso = iso_file / "Renomme (2025).iso"
|
||||
real_iso.write_bytes(b"\x00CD001 fake image")
|
||||
fake_iso.write_bytes(EBML_MAGIC + b"matroska data")
|
||||
|
||||
assert looks_like_iso(str(settings.radarr_films_dir / "Dossier" / "Film (2025).iso"))
|
||||
assert not looks_like_iso(
|
||||
str(settings.radarr_films_dir / "Dossier" / "Renomme (2025).iso")
|
||||
)
|
||||
# Extension non iso: refuse.
|
||||
assert not looks_like_iso("/quelque/chose.mkv")
|
||||
# Fichier illisible mais extension iso: accepte par defaut.
|
||||
assert looks_like_iso(str(settings.radarr_films_dir / "Dossier" / "Absent.iso"))
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_scan_skips_mkv_renamed_as_iso() -> None:
|
||||
"""Le scan n'importe pas les MKV renommes en .iso (contenu EBML)."""
|
||||
reset_state()
|
||||
folder = film_dir()
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
(folder / ISO_NAME).write_bytes(b"\x00CD001 vraie image")
|
||||
(folder / "FAKE.iso").write_bytes(b"\x1aE\xdf\xa3 mkv renomme")
|
||||
movies = [
|
||||
radarr_movie(str(settings.radarr_films_dir / FILM_FOLDER)),
|
||||
{
|
||||
"id": 11,
|
||||
"title": "Renomme",
|
||||
"year": 2024,
|
||||
"path": str(settings.radarr_films_dir / FILM_FOLDER),
|
||||
"movieFile": {"id": 21, "relativePath": "FAKE.iso", "size": 42},
|
||||
},
|
||||
]
|
||||
respx.get("http://radarr:7878/api/v3/movie?includeMovieFile=true").mock(
|
||||
return_value=Response(200, json=movies)
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
configure_radarr(client)
|
||||
scan = client.post("/api/scans")
|
||||
assert scan.json()["iso_files"] == 1
|
||||
titles = [movie["title"] for movie in client.get("/api/movies").json()]
|
||||
assert titles == ["ISO Movie"]
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_convert_blocked_by_workspace_leftovers() -> None:
|
||||
"""Des restes dans le dossier de travail bloquent la conversion jusqu'a
|
||||
confirmation; force=true les supprime et reprend."""
|
||||
reset_state()
|
||||
create_film_folder()
|
||||
mock_radarr(str(settings.radarr_films_dir / FILM_FOLDER))
|
||||
with TestClient(app) as client:
|
||||
configure_radarr(client)
|
||||
client.post("/api/scans")
|
||||
movie_id = client.get("/api/movies").json()[0]["id"]
|
||||
workspace = settings.downloads_dir / "ISO Movie 2025"
|
||||
workspace.mkdir(parents=True, exist_ok=True)
|
||||
(workspace / "ancien_titre.mkv").write_bytes(b"restes")
|
||||
(workspace / "partial.mkv").write_bytes(b"restes")
|
||||
|
||||
blocked = client.post(f"/api/movies/{movie_id}/convert")
|
||||
assert blocked.status_code == 409
|
||||
detail = blocked.json()["detail"]
|
||||
assert detail["code"] == "workspace_not_empty"
|
||||
assert sorted(detail["files"]) == ["ancien_titre.mkv", "partial.mkv"]
|
||||
|
||||
# La fiche detaillee expose aussi l'etat du dossier.
|
||||
fiche = client.get(f"/api/files/{movie_id}").json()
|
||||
assert fiche["workspace_files"] == ["ancien_titre.mkv", "partial.mkv"]
|
||||
|
||||
forced = client.post(f"/api/movies/{movie_id}/convert?force=true")
|
||||
assert forced.status_code == 200
|
||||
assert forced.json()["status"] == "queued"
|
||||
assert workspace_files_dir(workspace) == []
|
||||
|
||||
movie = wait_for_status(client, "validating")
|
||||
assert movie["status"] == "validating"
|
||||
|
||||
|
||||
def workspace_files_dir(folder: Path) -> list[str]:
|
||||
return sorted(entry.name for entry in folder.iterdir())
|
||||
Reference in new issue
Block a user