Harden queue matching and retry behavior

This commit is contained in:
Dymas
2026-05-26 00:02:02 +02:00
parent 1ceb773f99
commit b72d93268c
8 changed files with 114 additions and 40 deletions
+6 -15
View File
@@ -2328,11 +2328,6 @@ def download_watchlist_item(show_id, mode):
if not query:
raise ValueError("Watchlist item is missing a searchable title.")
results = search_anime(query, normalized_mode)
match = next((candidate for candidate in results if str(candidate.get("id") or "").strip() == item["show_id"]), None)
if match is None:
raise ValueError(f"Could not match {item['title']} in {normalized_mode} search results.")
episodes = episode_list(item["show_id"], normalized_mode)
if not episodes:
raise ValueError(f"No {normalized_mode} episodes are currently available for {item['title']}.")
@@ -2340,8 +2335,8 @@ def download_watchlist_item(show_id, mode):
payload = {
"show_id": item["show_id"],
"query": match.get("query") or query,
"title": match.get("title") or item["title"],
"query": query,
"title": item["title"],
"anime_name": item.get("auto_download_name") or item["title"],
"media_type": item.get("media_type") or "tv",
"season": item.get("auto_download_series") or "1",
@@ -2392,14 +2387,10 @@ def queue_watchlist_auto_download(item, refresh_source="manual"):
query = str(item.get("title") or item.get("show_id") or "").strip()
if not query:
return {"queued": False, "reason": "missing_title"}
results = search_anime(query, mode)
match = next((candidate for candidate in results if str(candidate.get("id") or "").strip() == str(item.get("show_id") or "").strip()), None)
if match is None:
return {"queued": False, "reason": f"search_match_missing:{mode}"}
anime_name = sanitize_path_component(
item.get("auto_download_name") or item.get("title") or match.get("title") or "Anime",
sanitize_path_component(item.get("title") or match.get("title") or "Anime", "Anime"),
item.get("auto_download_name") or item.get("title") or "Anime",
sanitize_path_component(item.get("title") or "Anime", "Anime"),
)
series = normalize_season(item.get("auto_download_series") or "1")
episode_offset = normalize_episode_offset(item.get("auto_download_offset"))
@@ -2408,8 +2399,8 @@ def queue_watchlist_auto_download(item, refresh_source="manual"):
job = runtime["download_queue"].add(
{
"show_id": item["show_id"],
"query": match.get("query") or query,
"title": match.get("title") or item["title"],
"query": query,
"title": item["title"],
"anime_name": anime_name,
"media_type": item.get("media_type") or "tv",
"season": series,