Harden queue identity and Jellyfin move checks
This commit is contained in:
+27
-10
@@ -45,10 +45,14 @@ def resolve_job_watchlist_identity(
|
||||
title = str(job.get("title") or job.get("anime_name") or "").strip()
|
||||
if show_id:
|
||||
return _resolution_result(show_id, title, "", return_reason)
|
||||
try:
|
||||
index = max(1, int(job.get("result_index") or 1))
|
||||
except (TypeError, ValueError):
|
||||
return _resolution_result("", title, "invalid queued result index", return_reason)
|
||||
raw_index = job.get("result_index")
|
||||
if raw_index in (None, ""):
|
||||
index = None
|
||||
else:
|
||||
try:
|
||||
index = max(1, int(raw_index))
|
||||
except (TypeError, ValueError):
|
||||
return _resolution_result("", title, "invalid queued result index", return_reason)
|
||||
query = str(job.get("query") or title).strip()
|
||||
if not query or not title:
|
||||
return _resolution_result("", title, "missing queued search query or title", return_reason)
|
||||
@@ -56,13 +60,26 @@ def resolve_job_watchlist_identity(
|
||||
results = search_fn(query, job.get("mode") or default_mode)
|
||||
except Exception as exc:
|
||||
return _resolution_result("", title, f"search fallback failed: {exc}", return_reason)
|
||||
if index > len(results):
|
||||
return _resolution_result("", title, "queued result index no longer exists in search results", return_reason)
|
||||
result = results[index - 1]
|
||||
candidate_title = str(result.get("title") or "").strip()
|
||||
if not titles_confidently_match(title, candidate_title, normalize_title_key_fn, base_title_variants_fn):
|
||||
matches = []
|
||||
for position, result in enumerate(results, start=1):
|
||||
candidate_title = str(result.get("title") or "").strip()
|
||||
if not titles_confidently_match(title, candidate_title, normalize_title_key_fn, base_title_variants_fn):
|
||||
continue
|
||||
resolved_show_id = str(result.get("id") or "").strip()
|
||||
if not resolved_show_id:
|
||||
continue
|
||||
matches.append((position, result, candidate_title, resolved_show_id))
|
||||
if not matches:
|
||||
candidate_title = str((results[0].get("title") if results else "") or "").strip()
|
||||
return _resolution_result("", title, f"title mismatch with fallback search result: {candidate_title or 'unknown'}", return_reason)
|
||||
resolved_show_id = str(result.get("id") or "").strip()
|
||||
if index is not None:
|
||||
indexed = next((match for match in matches if match[0] == index), None)
|
||||
if indexed is not None:
|
||||
_position, result, candidate_title, resolved_show_id = indexed
|
||||
return _resolution_result(resolved_show_id, candidate_title or title, "", return_reason)
|
||||
if len(matches) != 1:
|
||||
return _resolution_result("", title, "ambiguous fallback search results", return_reason)
|
||||
_position, result, candidate_title, resolved_show_id = matches[0]
|
||||
if not resolved_show_id:
|
||||
return _resolution_result("", title, "fallback search result did not include a show_id", return_reason)
|
||||
return _resolution_result(resolved_show_id, candidate_title or title, "", return_reason)
|
||||
|
||||
Reference in New Issue
Block a user