diff --git a/api/video/scan.py b/api/video/scan.py index 99e83984..06c3eb58 100644 --- a/api/video/scan.py +++ b/api/video/scan.py @@ -24,8 +24,11 @@ def register_routes(bp): from core.video.sources import get_active_video_source body = request.get_json(silent=True) or {} mode = body.get("mode", "full") + # Which library to scan — movies and TV are independent libraries, so the + # UI can target one or both. The scanner normalizes/validates it. + media_type = body.get("media_type", "all") scanner = get_video_scanner(get_video_db()) - return jsonify(scanner.request_scan(get_active_video_source, mode)) + return jsonify(scanner.request_scan(get_active_video_source, mode, media_type)) @bp.route("/scan/status", methods=["GET"]) def video_scan_status(): diff --git a/tests/test_video_api.py b/tests/test_video_api.py index 8b302829..72c89cc6 100644 --- a/tests/test_video_api.py +++ b/tests/test_video_api.py @@ -62,6 +62,38 @@ def test_blueprint_exposes_dashboard_route(): assert "/api/video/discover/trailer" in rules +def test_scan_request_threads_mode_and_media_type(tmp_path, monkeypatch): + # The Tools-page scan can target one library (movies / TV) or both. The + # endpoint must pass BOTH mode and media_type through to the scanner — movies + # and TV are independent, so a TV scan must never touch movies. + client, _ = _make_client(tmp_path) + calls = {} + + class _FakeScanner: + def request_scan(self, source_factory, mode="full", media_type="all"): + calls["mode"] = mode + calls["media_type"] = media_type + return {"status": "started", "mode": mode, "media_type": media_type} + + import core.video.scanner as scanner_mod + import core.video.sources as sources_mod + monkeypatch.setattr(scanner_mod, "get_video_scanner", lambda db: _FakeScanner()) + monkeypatch.setattr(sources_mod, "get_active_video_source", lambda: None) + + # default body → both libraries, full + assert client.post("/api/video/scan/request", json={}).get_json()["media_type"] == "all" + assert calls == {"mode": "full", "media_type": "all"} + + # explicit movies-only deep scan + r = client.post("/api/video/scan/request", json={"mode": "deep", "media_type": "movie"}) + assert calls == {"mode": "deep", "media_type": "movie"} + assert r.get_json() == {"status": "started", "mode": "deep", "media_type": "movie"} + + # TV-only + client.post("/api/video/scan/request", json={"media_type": "show"}) + assert calls["media_type"] == "show" + + def test_discover_trailer_returns_key(tmp_path, monkeypatch): client, _ = _make_client(tmp_path) import core.video.enrichment.engine as eng_mod diff --git a/webui/index.html b/webui/index.html index 9ae5ee89..0d416577 100644 --- a/webui/index.html +++ b/webui/index.html @@ -1616,7 +1616,12 @@