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
+33 -5
View File
@@ -601,7 +601,7 @@ WATCHLIST_HTML = r"""<!doctype html>
<h2>How it works</h2>
<div class="stack muted">
<p>Use Refresh to pull the latest sub and dub episode counts for a single show.</p>
<p>Use Open In Search to jump back to the main page with the title pre-filled.</p>
<p>Use Download all to queue every currently available episode after choosing sub or dub.</p>
<p>Refresh All updates your whole tracked list in one pass.</p>
</div>
</section>
@@ -1007,7 +1007,7 @@ WATCHLIST_HTML = r"""<!doctype html>
<div class="muted card-date"></div>
<div class="card-actions">
<button class="primary" type="button">Refresh</button>
<button class="ghost" type="button">Open</button>
<button class="ghost" type="button">Download all</button>
<button class="danger" type="button">Remove</button>
</div>
`;
@@ -1071,9 +1071,7 @@ WATCHLIST_HTML = r"""<!doctype html>
}
});
refreshBtn.addEventListener("click", () => refreshWatchlistItem(item.show_id));
searchBtn.addEventListener("click", () => {
window.location.href = `/?query=${encodeURIComponent(item.title || item.show_id)}`;
});
searchBtn.addEventListener("click", () => downloadWatchlistItem(item));
removeBtn.addEventListener("click", () => removeWatchlistItem(item.show_id, item.title));
container.appendChild(card);
applyThumbnail(card, item, false);
@@ -1168,6 +1166,36 @@ WATCHLIST_HTML = r"""<!doctype html>
}
}
function chooseWatchlistDownloadMode(item) {
const fallback = item.dub_count > 0 && item.sub_count < 1 ? "dub" : "sub";
const answer = window.prompt(
`Download all available episodes for ${item.title || "this anime"}.\nEnter sub or dub:`,
fallback,
);
if (answer === null) return "";
const mode = String(answer || "").trim().toLowerCase();
if (mode === "sub" || mode === "dub") {
return mode;
}
setNotice("Enter sub or dub to queue a watchlist download.");
return "";
}
async function downloadWatchlistItem(item) {
const mode = chooseWatchlistDownloadMode(item);
if (!mode) return;
setNotice(`Queueing ${item.title || "selected anime"} for ${mode} download...`);
try {
const data = await api("/api/watchlist/download-all", {
method: "POST",
body: JSON.stringify({ show_id: item.show_id, mode })
});
setNotice(data.message || "Added to queue.");
} catch (error) {
setNotice(error.message);
}
}
async function removeWatchlistItem(showId, title) {
if (!window.confirm(`Remove ${title || "this anime"} from the watchlist?`)) {
return;