diff --git a/importarr/main.py b/importarr/main.py index 486bd37..3c9cef7 100644 --- a/importarr/main.py +++ b/importarr/main.py @@ -275,6 +275,10 @@ def queue_item_action(item_id: int, payload: QueueItemActionRequest, _: None = D if payload.action == "retry": retry_state = "manual_batch" if item["source_type"] == "manual" else "ready" state.mark_queue_item(item["source_type"], item["source_id"], retry_state, "retry requested") + elif payload.action == "run-now": + imported = _import_queue_item(item, Importer(settings.movies_root, settings.tv_root)) + updated = state.get_queue_item(item_id) + return {"status": "imported" if imported else "updated", "imported": imported, "item": serialize_queue_item(updated or item)} elif payload.action == "ignore": state.mark_queue_item(item["source_type"], item["source_id"], "skipped", "ignored by user") elif payload.action == "remove": @@ -446,6 +450,32 @@ async def _import_ready_sab_jobs(importer: Importer, force: bool = False) -> int return imported +def _import_queue_item(item: dict[str, object], importer: Importer) -> int: + if item["source_type"] not in {"sab", "manual"} or item["state"] not in {"ready", "manual_batch", "failed"}: + return 0 + source_path = item.get("source_path") + if not source_path: + state.mark_queue_item(str(item["source_type"]), str(item["source_id"]), "failed", "missing source path") + return 0 + source = Path(str(source_path)) + set_current_job(str(source)) + try: + result = importer.import_file(source, should_cancel=consume_cancel_request) + state.add_history(result.source, result.target, "imported", result.bytes) + state.mark_queue_item(str(item["source_type"]), str(item["source_id"]), "imported") + return 1 + except ImportCancelled: + state.add_history(source, source, "cancelled", 0, "cancelled") + state.mark_queue_item(str(item["source_type"]), str(item["source_id"]), "skipped", "cancelled") + return 0 + except Exception as exc: + state.add_history(source, source, "failed", 0, exc.__class__.__name__) + state.mark_queue_item(str(item["source_type"]), str(item["source_id"]), "failed", exc.__class__.__name__) + return 0 + finally: + set_current_job(None) + + def _import_manual_batches(importer: Importer) -> int: if queue_accepting_new_jobs(): sync_manual_queue() diff --git a/importarr/templates/index.html b/importarr/templates/index.html index 53c0f13..eba2eb5 100644 --- a/importarr/templates/index.html +++ b/importarr/templates/index.html @@ -95,7 +95,7 @@