Prepare retried jobs before requeue

This commit is contained in:
Codex
2026-08-01 17:51:59 +02:00
parent edb565d855
commit f417a96811
6 changed files with 153 additions and 19 deletions
+39 -1
View File
@@ -58,6 +58,7 @@ from app_support import (
normalize_config,
normalize_episode_offset,
normalize_media_type,
normalize_result_index,
now_iso,
remote_access_session_fingerprint,
sanitize_path_component,
@@ -74,7 +75,10 @@ from title_matching import (
title_lookup_queries,
title_match_variants,
)
from watchlist_identity import resolve_job_watchlist_identity as resolve_job_watchlist_identity_impl
from watchlist_identity import (
resolve_job_watchlist_identity as resolve_job_watchlist_identity_impl,
titles_confidently_match,
)
from web_templates import CONFIG_HTML, INDEX_HTML, PAGE_LINKS, QUEUE_HTML, WATCHLIST_HTML, render_page_links, render_sidebar_brand
RUNTIME_LOCK = threading.RLock()
@@ -3007,6 +3011,10 @@ def sync_downloaded_job_to_watchlist(job):
def prepare_download_job(job):
config = ensure_runtime()["config"]
if normalize_result_index(job.get("result_index")) is None:
result_index = infer_download_job_result_index(job, config)
if result_index is not None:
job["result_index"] = result_index
show_id, title, reason = resolve_job_watchlist_identity_impl(
job,
search_fn=search_anime,
@@ -3024,6 +3032,36 @@ def prepare_download_job(job):
return job
def infer_download_job_result_index(job, config):
query = str(job.get("query") or job.get("title") or job.get("anime_name") or "").strip()
mode = str(job.get("mode") or config.get("mode") or "sub").strip().lower()
if not query or mode not in MODE_CHOICES:
return None
try:
results = search_anime(query, mode)
except Exception as exc:
debug_log("watchlist.prepare_job.result_index_search_failed", job=job, error=exc)
return None
show_id = str(job.get("show_id") or "").strip()
if show_id:
for position, result in enumerate(results, start=1):
if str(result.get("id") or "").strip() == show_id:
return position
title = str(job.get("title") or job.get("anime_name") or query).strip()
matches = []
for position, result in enumerate(results, start=1):
candidate_title = str(result.get("title") or "").strip()
if titles_confidently_match(title, candidate_title, normalize_identity_title_key, base_title_variants):
matches.append(position)
if len(matches) == 1:
return matches[0]
if len(matches) > 1:
debug_log("watchlist.prepare_job.result_index_ambiguous", job=job, matches=matches)
return None
def get_config_snapshot(fallback=None):
with RUNTIME_LOCK:
source = CONFIG if CONFIG is not None else fallback