Brings the video modal to parity with music's: - 'Process first everywhere' control (Movies/Shows/Auto) in the topbar — a global setting that pins which kind every worker processes first. enrichment_next takes a priority kind; the worker reads enrichment_priority each loop; GET/POST /api/video/enrichment/priority persists it. Reuses music's .em-global styling. - Needs-matching bar now has a live count, status filter (All unmatched / Not found / Pending) and a debounced search (reusing .em-select / .em-search), matching the music modal. Episode view stays read-only. - Live glow (scoped to #vem-overlay): pulsing running dot, accent glow on the selected worker row + active process-first/kind, and a pulsing 'now processing' chip in the worker accent. Music's shared .em-* styles untouched. Seam tests: priority pins kind in enrichment_next + worker honors the setting, priority endpoint GET/POST + validation, modal feature markup pinned.
139 lines
5.4 KiB
Python
139 lines
5.4 KiB
Python
"""Video enrichment API — mirrors the music enrichment endpoints so the shared
|
|
Manage-Workers modal can drive video workers by pointing at /api/video/...
|
|
|
|
GET /api/video/enrichment/services
|
|
GET /api/video/enrichment/<service>/status
|
|
POST /api/video/enrichment/<service>/pause | /resume
|
|
GET /api/video/enrichment/<service>/breakdown
|
|
GET /api/video/enrichment/<service>/unmatched?kind=&status=&q=&limit=&offset=
|
|
POST /api/video/enrichment/<service>/retry {kind, scope, item_id}
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from flask import jsonify, request
|
|
|
|
from utils.logging_config import get_logger
|
|
|
|
logger = get_logger("video_api.enrichment")
|
|
|
|
|
|
def _int(val, default):
|
|
try:
|
|
return int(val)
|
|
except (TypeError, ValueError):
|
|
return default
|
|
|
|
|
|
def register_routes(bp):
|
|
def engine():
|
|
from core.video.enrichment.engine import get_video_enrichment_engine
|
|
return get_video_enrichment_engine()
|
|
|
|
@bp.route("/enrichment/services", methods=["GET"])
|
|
def video_enrichment_services():
|
|
try:
|
|
return jsonify({"services": engine().services()})
|
|
except Exception:
|
|
logger.exception("video enrichment services failed")
|
|
return jsonify({"services": []})
|
|
|
|
@bp.route("/enrichment/config", methods=["GET"])
|
|
def video_enrichment_config():
|
|
from . import get_video_db
|
|
db = get_video_db()
|
|
return jsonify({
|
|
"tmdb_api_key": db.get_setting("tmdb_api_key") or "",
|
|
"tvdb_api_key": db.get_setting("tvdb_api_key") or "",
|
|
})
|
|
|
|
@bp.route("/enrichment/config", methods=["POST"])
|
|
def video_enrichment_config_save():
|
|
from . import get_video_db
|
|
db = get_video_db()
|
|
body = request.get_json(silent=True) or {}
|
|
if "tmdb_api_key" in body:
|
|
db.set_setting("tmdb_api_key", body.get("tmdb_api_key") or "")
|
|
if "tvdb_api_key" in body:
|
|
db.set_setting("tvdb_api_key", body.get("tvdb_api_key") or "")
|
|
try:
|
|
from core.video.enrichment.engine import rebuild_video_enrichment_engine
|
|
rebuild_video_enrichment_engine()
|
|
except Exception:
|
|
logger.exception("video enrichment: engine rebuild after key change failed")
|
|
return jsonify({"status": "saved"})
|
|
|
|
@bp.route("/enrichment/<service>/status", methods=["GET"])
|
|
def video_enrichment_status(service):
|
|
w = engine().worker(service)
|
|
if not w:
|
|
return jsonify({"error": "unknown service"}), 404
|
|
return jsonify(w.get_stats())
|
|
|
|
@bp.route("/enrichment/<service>/pause", methods=["POST"])
|
|
def video_enrichment_pause(service):
|
|
w = engine().worker(service)
|
|
if not w:
|
|
return jsonify({"error": "unknown service"}), 404
|
|
w.pause()
|
|
return jsonify({"status": "paused"})
|
|
|
|
@bp.route("/enrichment/<service>/resume", methods=["POST"])
|
|
def video_enrichment_resume(service):
|
|
w = engine().worker(service)
|
|
if not w:
|
|
return jsonify({"error": "unknown service"}), 404
|
|
w.resume()
|
|
return jsonify({"status": "running"})
|
|
|
|
@bp.route("/enrichment/priority", methods=["GET", "POST"])
|
|
def video_enrichment_priority():
|
|
from . import get_video_db
|
|
db = get_video_db()
|
|
if request.method == "POST":
|
|
body = request.get_json(silent=True) or {}
|
|
kind = body.get("priority") or ""
|
|
if kind not in ("", "movie", "show"):
|
|
return jsonify({"error": "bad priority"}), 400
|
|
db.set_setting("enrichment_priority", kind)
|
|
return jsonify({"success": True, "priority": kind})
|
|
return jsonify({"priority": db.get_setting("enrichment_priority") or ""})
|
|
|
|
@bp.route("/enrichment/<service>/test", methods=["POST"])
|
|
def video_enrichment_test(service):
|
|
w = engine().worker(service)
|
|
if not w:
|
|
return jsonify({"success": False, "error": "unknown service"}), 404
|
|
try:
|
|
ok, msg = w.client.test()
|
|
return jsonify({"success": bool(ok), "message": msg, "error": None if ok else msg})
|
|
except Exception:
|
|
logger.exception("video enrichment test failed for %s", service)
|
|
return jsonify({"success": False, "error": "Test failed"})
|
|
|
|
@bp.route("/enrichment/<service>/breakdown", methods=["GET"])
|
|
def video_enrichment_breakdown(service):
|
|
from . import get_video_db
|
|
return jsonify({"service": service, "breakdown": get_video_db().enrichment_breakdown(service)})
|
|
|
|
@bp.route("/enrichment/<service>/unmatched", methods=["GET"])
|
|
def video_enrichment_unmatched(service):
|
|
from . import get_video_db
|
|
kind = request.args.get("kind", "movie")
|
|
res = get_video_db().enrichment_unmatched(
|
|
service, kind,
|
|
status=request.args.get("status", "not_found"),
|
|
search=request.args.get("q") or None,
|
|
limit=_int(request.args.get("limit"), 50),
|
|
offset=_int(request.args.get("offset"), 0))
|
|
res.update({"service": service, "kind": kind})
|
|
return jsonify(res)
|
|
|
|
@bp.route("/enrichment/<service>/retry", methods=["POST"])
|
|
def video_enrichment_retry(service):
|
|
from . import get_video_db
|
|
body = request.get_json(silent=True) or {}
|
|
n = get_video_db().enrichment_retry(
|
|
service, body.get("kind", "movie"),
|
|
scope=body.get("scope", "failed"), item_id=body.get("item_id"))
|
|
return jsonify({"success": True, "reset": n})
|