Add watchlist download-all action

This commit is contained in:
Dymas
2026-05-23 14:30:03 +02:00
parent 5bec8713a5
commit 91691244d7
7 changed files with 130 additions and 8 deletions
+42
View File
@@ -1740,6 +1740,47 @@ def update_watchlist_status(show_id, _mode=None):
return {"message": f"Queued refresh for {item['title']}.", "item": item}
def download_watchlist_item(show_id, mode):
runtime = ensure_runtime()
item = runtime["watchlist"].get(show_id)
normalized_mode = str(mode or "").strip().lower()
if normalized_mode not in MODE_CHOICES:
raise ValueError("Mode must be sub or dub")
query = str(item.get("title") or item.get("show_id") or "").strip()
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']}.")
episode_spec = episodes[0] if len(episodes) == 1 else f"{episodes[0]}-{episodes[-1]}"
payload = {
"show_id": item["show_id"],
"query": match.get("query") or query,
"title": match.get("title") or item["title"],
"anime_name": item["title"],
"season": "1",
"index": match.get("index", 1),
"mode": normalized_mode,
"quality": runtime["config"]["quality"],
"episodes": episode_spec,
"download_dir": runtime["config"]["download_dir"],
}
job = runtime["download_queue"].add(payload)
return {
"message": f"Queued {item['title']} for {normalized_mode} download.",
"job": job,
"item": item,
}
def update_watchlist_category(show_id, category):
ensure_runtime()
item = WATCHLIST.update_category(show_id, category)
@@ -1968,6 +2009,7 @@ Handler = build_handler_class(
HandlerContext(
add_to_watchlist=add_to_watchlist,
config_html=CONFIG_HTML,
download_watchlist_item=download_watchlist_item,
ensure_runtime=ensure_runtime,
episode_list=episode_list,
get_config_snapshot=get_config_snapshot,