Release ani-cli-web 0.26.0
This commit is contained in:
+778
@@ -0,0 +1,778 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""Search page template for ani-cli-web."""
|
||||
|
||||
from template_helpers import BROWSER_API_HELPER, BROWSER_POLL_HELPER, render_page_links, render_sidebar_brand
|
||||
|
||||
|
||||
INDEX_HTML = r"""<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>ani-cli web</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #090611;
|
||||
--bg-2: #140d21;
|
||||
--panel: rgba(25, 18, 41, 0.82);
|
||||
--panel-strong: rgba(18, 13, 31, 0.92);
|
||||
--panel-2: rgba(157, 123, 255, 0.12);
|
||||
--line: rgba(255, 255, 255, 0.08);
|
||||
--line-strong: rgba(157, 123, 255, 0.26);
|
||||
--text: #f6f2ff;
|
||||
--muted: #b8b0cf;
|
||||
--accent: #9d7bff;
|
||||
--accent-strong: #7b5cff;
|
||||
--accent-soft: rgba(157, 123, 255, 0.14);
|
||||
--good: #95e4ba;
|
||||
--warn: #f0c67a;
|
||||
--bad: #ff90a4;
|
||||
--focus: #b296ff;
|
||||
--shadow: 0 24px 60px rgba(5, 2, 15, 0.42);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html { scroll-behavior: smooth; }
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
background:
|
||||
radial-gradient(circle at top left, rgba(157, 123, 255, 0.18), transparent 28%),
|
||||
radial-gradient(circle at top right, rgba(117, 201, 255, 0.12), transparent 24%),
|
||||
linear-gradient(180deg, #120c1d 0%, #0b0813 56%, #07050d 100%);
|
||||
color: var(--text);
|
||||
font: 15px/1.5 "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
}
|
||||
body::before {
|
||||
content: "";
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 24%);
|
||||
opacity: 0.5;
|
||||
}
|
||||
button, input, select {
|
||||
font: inherit;
|
||||
}
|
||||
button {
|
||||
border: 1px solid var(--line);
|
||||
background: var(--panel-2);
|
||||
color: var(--text);
|
||||
min-height: 40px;
|
||||
border-radius: 14px;
|
||||
padding: 0 14px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
|
||||
}
|
||||
button:hover {
|
||||
border-color: var(--line-strong);
|
||||
background: rgba(157, 123, 255, 0.18);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
button.primary {
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-strong));
|
||||
border-color: transparent;
|
||||
color: #fcfaff;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 16px 32px rgba(123, 92, 255, 0.26);
|
||||
}
|
||||
button.ghost {
|
||||
background: transparent;
|
||||
}
|
||||
button.danger {
|
||||
border-color: rgba(255, 144, 164, 0.3);
|
||||
background: rgba(255, 144, 164, 0.12);
|
||||
color: #ffd7df;
|
||||
}
|
||||
button.danger:hover {
|
||||
border-color: rgba(255, 144, 164, 0.48);
|
||||
background: rgba(255, 144, 164, 0.18);
|
||||
}
|
||||
button.danger {
|
||||
border-color: rgba(255, 144, 164, 0.28);
|
||||
color: #ffd7df;
|
||||
}
|
||||
input, select {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(10, 7, 18, 0.82);
|
||||
color: var(--text);
|
||||
padding: 0 13px;
|
||||
outline: none;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
|
||||
}
|
||||
input:focus, select:focus {
|
||||
border-color: var(--focus);
|
||||
box-shadow: 0 0 0 3px rgba(178, 150, 255, 0.12);
|
||||
}
|
||||
label {
|
||||
display: grid;
|
||||
gap: 7px;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
.app {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(320px, 380px) 1fr;
|
||||
min-height: 100vh;
|
||||
}
|
||||
aside, main {
|
||||
padding: 22px;
|
||||
}
|
||||
aside {
|
||||
border-right: 1px solid var(--line);
|
||||
background: linear-gradient(180deg, rgba(25, 18, 41, 0.94), rgba(14, 10, 24, 0.9));
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 20px;
|
||||
backdrop-filter: blur(18px) saturate(170%);
|
||||
}
|
||||
main {
|
||||
display: grid;
|
||||
grid-template-rows: auto auto 1fr;
|
||||
gap: 20px;
|
||||
min-width: 0;
|
||||
}
|
||||
h1, h2, h3, p { margin: 0; }
|
||||
h1 {
|
||||
font-size: 29px;
|
||||
line-height: 1.05;
|
||||
letter-spacing: -0.04em;
|
||||
}
|
||||
h2 {
|
||||
font-size: 17px;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
h3 { font-size: 15px; }
|
||||
.topline, .row, .controls, .toolbar {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
.topline, .toolbar { justify-content: space-between; }
|
||||
.brand-wrap {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
.brand-word {
|
||||
color: var(--accent);
|
||||
}
|
||||
.shell-note {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
max-width: 28ch;
|
||||
}
|
||||
.row > * { flex: 1; }
|
||||
.controls {
|
||||
align-items: end;
|
||||
}
|
||||
.search-box {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 22px;
|
||||
background: linear-gradient(180deg, rgba(31, 24, 50, 0.86), rgba(17, 13, 29, 0.92));
|
||||
box-shadow: var(--shadow);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
.page-links {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
.page-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 40px;
|
||||
border: 0;
|
||||
border-radius: 12px;
|
||||
padding: 0 14px;
|
||||
color: var(--muted);
|
||||
background: transparent;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
|
||||
}
|
||||
.page-link.active {
|
||||
background: var(--accent-soft);
|
||||
color: var(--text);
|
||||
box-shadow: inset 0 0 0 1px rgba(157, 123, 255, 0.22);
|
||||
}
|
||||
.page-link:hover {
|
||||
color: var(--text);
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
.segmented {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
.segmented button {
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
}
|
||||
.segmented button.active {
|
||||
background: var(--accent-soft);
|
||||
color: var(--text);
|
||||
font-weight: 700;
|
||||
}
|
||||
.results, .queue {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
.result, .job, .settings, .episodes-panel, .deps {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 22px;
|
||||
background: linear-gradient(180deg, rgba(29, 22, 47, 0.88), rgba(17, 13, 29, 0.94));
|
||||
box-shadow: var(--shadow);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
.result {
|
||||
padding: 14px;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
text-align: left;
|
||||
transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
|
||||
}
|
||||
.result:hover {
|
||||
border-color: var(--line-strong);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.result.active {
|
||||
border-color: rgba(157, 123, 255, 0.34);
|
||||
background: linear-gradient(180deg, rgba(48, 36, 80, 0.96), rgba(20, 15, 35, 0.96));
|
||||
}
|
||||
.result-title {
|
||||
color: var(--text);
|
||||
font-weight: 700;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
.settings, .episodes-panel, .deps {
|
||||
padding: 18px;
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
}
|
||||
.chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
max-height: 168px;
|
||||
overflow: auto;
|
||||
}
|
||||
.chip, .badge {
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: 999px;
|
||||
padding: 6px 10px;
|
||||
color: var(--muted);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.badge.ok { color: var(--good); border-color: rgba(149, 228, 186, 0.24); }
|
||||
.badge.bad { color: #ffd0da; border-color: rgba(255, 144, 164, 0.22); }
|
||||
.job {
|
||||
padding: 18px;
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
transition: border-color 0.16s ease, transform 0.16s ease;
|
||||
}
|
||||
.job:hover {
|
||||
border-color: var(--line-strong);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.job-head {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
min-width: 0;
|
||||
}
|
||||
.job-title {
|
||||
font-weight: 800;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.status {
|
||||
border-radius: 999px;
|
||||
padding: 6px 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: var(--muted);
|
||||
}
|
||||
.status.running {
|
||||
color: #fcfaff;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-strong));
|
||||
}
|
||||
.status.done { color: #082312; background: var(--good); }
|
||||
.status.failed { color: #2d0910; background: var(--bad); }
|
||||
.status.canceled { color: #2d1c00; background: var(--warn); }
|
||||
pre {
|
||||
margin: 0;
|
||||
max-height: 180px;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
padding: 12px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||
background: rgba(7, 5, 12, 0.86);
|
||||
color: #d6d0e7;
|
||||
font-size: 12px;
|
||||
}
|
||||
.empty {
|
||||
border: 1px dashed rgba(157, 123, 255, 0.22);
|
||||
border-radius: 22px;
|
||||
color: var(--muted);
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
background: rgba(157, 123, 255, 0.06);
|
||||
}
|
||||
.notice {
|
||||
min-height: 20px;
|
||||
color: #ddd0ff;
|
||||
font-size: 13px;
|
||||
}
|
||||
.statline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.app { grid-template-columns: 1fr; }
|
||||
aside { border-right: 0; border-bottom: 1px solid var(--line); }
|
||||
.controls, .row, .toolbar { align-items: stretch; flex-direction: column; }
|
||||
.job-head { grid-template-columns: 1fr; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="app">
|
||||
<aside>
|
||||
""" + render_sidebar_brand(
|
||||
"Tsuki-inspired control center for anime search and download flow.",
|
||||
"Search",
|
||||
badge_id="serverBadge",
|
||||
) + render_page_links("search") + r"""
|
||||
|
||||
<div class="search-box">
|
||||
<label for="search-query">Anime Title / Keyword</label>
|
||||
<input type="text" id="search-query" placeholder="e.g., Attack on Titan">
|
||||
|
||||
<label for="search-mode">Mode</label>
|
||||
<select id="search-mode">
|
||||
<option value="sub">Subtitled (Sub)</option>
|
||||
<option value="dub">Dubbed (Dub)</option>
|
||||
</select>
|
||||
|
||||
<label for="search-quality">Quality</label>
|
||||
<select id="search-quality">
|
||||
<option value="best">Best</option>
|
||||
<option value="1080">1080p</option>
|
||||
<option value="720">720p</option>
|
||||
<option value="480">480p</option>
|
||||
</select>
|
||||
|
||||
<button class="primary" id="searchBtn" type="button">Search</button>
|
||||
</div>
|
||||
<div class="notice" id="notice"></div>
|
||||
<div class="results" id="results"></div>
|
||||
</aside>
|
||||
|
||||
<main>
|
||||
<section class="episodes-panel" id="episodesPanel">
|
||||
<div class="toolbar">
|
||||
<div>
|
||||
<h2 id="selectedTitle">Select a result</h2>
|
||||
<p class="muted" id="selectedMeta">Episodes will appear here.</p>
|
||||
</div>
|
||||
<div class="row" style="flex:0 0 auto">
|
||||
<label style="min-width: 180px;">Watchlist category
|
||||
<select id="trackCategory">
|
||||
<option value="watching">Watching</option>
|
||||
<option value="planned">Planned</option>
|
||||
<option value="finished">Finished</option>
|
||||
<option value="dropped">Dropped</option>
|
||||
</select>
|
||||
</label>
|
||||
<button class="ghost" id="trackBtn" type="button" disabled>Add to watchlist</button>
|
||||
<button class="primary" id="addBtn" type="button" disabled>Add to queue</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Library name
|
||||
<input id="animeNameInput" placeholder="Anime name">
|
||||
</label>
|
||||
<label>Season
|
||||
<input id="seasonInput" inputmode="numeric" pattern="[0-9]*" value="1">
|
||||
</label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Episodes
|
||||
<input id="episodesInput" placeholder="1-12">
|
||||
</label>
|
||||
<label>Download folder
|
||||
<input id="jobFolder" placeholder="/home/me/Downloads/Anime">
|
||||
</label>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<div class="chips" id="episodeChips"></div>
|
||||
<div class="row" style="flex:0 0 auto">
|
||||
<button class="ghost" id="firstEpBtn" type="button">First</button>
|
||||
<button class="ghost" id="latestEpBtn" type="button">Latest</button>
|
||||
<button class="ghost" id="allEpBtn" type="button">All</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<div class="toolbar">
|
||||
<h2>Download queue</h2>
|
||||
<div class="row" style="flex:0 0 auto">
|
||||
<button class="ghost" id="retryFailedBtn" type="button">Retry failed</button>
|
||||
<button class="ghost" id="removeFinishedBtn" type="button">Remove finished</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="queue" id="queue"></div>
|
||||
<div class="toolbar" id="queuePager"></div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const state = {
|
||||
config: { mode: "sub", quality: "best", download_dir: "" },
|
||||
selected: null,
|
||||
episodes: [],
|
||||
queuePage: 1,
|
||||
queuePages: 1,
|
||||
queueTotal: 0,
|
||||
queueTimer: null,
|
||||
queueRequestId: 0,
|
||||
searchRequestId: 0,
|
||||
episodeRequestId: 0
|
||||
};
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
""" + BROWSER_API_HELPER + BROWSER_POLL_HELPER + r"""
|
||||
|
||||
function setNotice(text) {
|
||||
const notice = $("notice");
|
||||
if (notice) notice.textContent = text || "";
|
||||
}
|
||||
|
||||
function setMode(mode) {
|
||||
state.config.mode = mode;
|
||||
$("search-mode").value = mode;
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
const el = $("results");
|
||||
el.innerHTML = "";
|
||||
if (!results.length) {
|
||||
el.innerHTML = '<div class="empty">No matching anime found.</div>';
|
||||
return;
|
||||
}
|
||||
for (const item of results) {
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "result";
|
||||
btn.innerHTML = `
|
||||
<span class="result-title"></span>
|
||||
<span class="muted"></span>
|
||||
`;
|
||||
btn.querySelector(".result-title").textContent = item.title;
|
||||
btn.querySelector(".muted").textContent = `${item.episodes} episodes · result ${item.index}`;
|
||||
btn.addEventListener("click", () => selectResult(item, btn));
|
||||
el.appendChild(btn);
|
||||
}
|
||||
}
|
||||
|
||||
async function selectResult(item, button) {
|
||||
const requestId = ++state.episodeRequestId;
|
||||
document.querySelectorAll(".result").forEach((node) => node.classList.remove("active"));
|
||||
button.classList.add("active");
|
||||
state.selected = item;
|
||||
state.episodes = [];
|
||||
$("selectedTitle").textContent = item.title;
|
||||
$("animeNameInput").value = item.title;
|
||||
$("seasonInput").value = $("seasonInput").value || "1";
|
||||
$("selectedMeta").textContent = "Loading episodes...";
|
||||
$("episodeChips").innerHTML = "";
|
||||
$("addBtn").disabled = true;
|
||||
$("trackBtn").disabled = false;
|
||||
try {
|
||||
const data = await api(`/api/anime/${encodeURIComponent(item.id)}/episodes?mode=${state.config.mode}`);
|
||||
if (requestId !== state.episodeRequestId || state.selected !== item) return;
|
||||
state.episodes = data.episodes;
|
||||
const first = state.episodes[0] || "";
|
||||
const last = state.episodes[state.episodes.length - 1] || "";
|
||||
$("episodesInput").value = first && last ? `${first}-${last}` : "";
|
||||
$("selectedMeta").textContent = `${state.episodes.length} available episodes`;
|
||||
renderEpisodeChips();
|
||||
$("addBtn").disabled = !state.episodes.length;
|
||||
} catch (error) {
|
||||
if (requestId !== state.episodeRequestId || state.selected !== item) return;
|
||||
$("selectedMeta").textContent = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
function renderEpisodeChips() {
|
||||
const el = $("episodeChips");
|
||||
el.innerHTML = "";
|
||||
for (const ep of state.episodes.slice(0, 90)) {
|
||||
const chip = document.createElement("button");
|
||||
chip.type = "button";
|
||||
chip.className = "chip";
|
||||
chip.textContent = ep;
|
||||
chip.addEventListener("click", () => { $("episodesInput").value = ep; });
|
||||
el.appendChild(chip);
|
||||
}
|
||||
}
|
||||
|
||||
async function search() {
|
||||
const requestId = ++state.searchRequestId;
|
||||
const query = $("search-query").value.trim();
|
||||
if (!query) return setNotice("Type a title first.");
|
||||
setMode($("search-mode").value);
|
||||
setNotice("Searching...");
|
||||
state.selected = null;
|
||||
state.episodeRequestId += 1;
|
||||
$("addBtn").disabled = true;
|
||||
$("trackBtn").disabled = true;
|
||||
$("results").innerHTML = "";
|
||||
try {
|
||||
const data = await api(`/api/search?q=${encodeURIComponent(query)}&mode=${state.config.mode}`);
|
||||
if (requestId !== state.searchRequestId) return;
|
||||
renderResults(data.results);
|
||||
setNotice(`${data.results.length} results`);
|
||||
} catch (error) {
|
||||
if (requestId !== state.searchRequestId) return;
|
||||
setNotice(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function addSelectedToWatchlist() {
|
||||
if (!state.selected) {
|
||||
setNotice("Select a search result first.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = await api("/api/watchlist", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
show_id: state.selected.id,
|
||||
title: state.selected.title,
|
||||
category: $("trackCategory").value
|
||||
})
|
||||
});
|
||||
setNotice(data.message || "Added to watchlist.");
|
||||
} catch (error) {
|
||||
setNotice(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function addSelected() {
|
||||
if (!state.selected) return;
|
||||
const payload = {
|
||||
show_id: state.selected.id,
|
||||
query: state.selected.query,
|
||||
title: state.selected.title,
|
||||
anime_name: $("animeNameInput").value || state.selected.title,
|
||||
season: $("seasonInput").value || "1",
|
||||
index: state.selected.index,
|
||||
mode: state.config.mode,
|
||||
quality: $("search-quality").value,
|
||||
episodes: $("episodesInput").value,
|
||||
download_dir: $("jobFolder").value || state.config.download_dir
|
||||
};
|
||||
try {
|
||||
await api("/api/queue", { method: "POST", body: JSON.stringify(payload) });
|
||||
setNotice("Added to queue.");
|
||||
await loadQueue();
|
||||
} catch (error) {
|
||||
setNotice(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
function renderQueue(data) {
|
||||
const jobs = data.jobs || [];
|
||||
state.queuePage = data.page || 1;
|
||||
state.queuePages = data.pages || 1;
|
||||
state.queueTotal = data.total || 0;
|
||||
const el = $("queue");
|
||||
el.innerHTML = "";
|
||||
if (!jobs.length) {
|
||||
el.innerHTML = '<div class="empty">Queue is empty.</div>';
|
||||
renderQueuePager();
|
||||
return;
|
||||
}
|
||||
for (const job of jobs) {
|
||||
const item = document.createElement("article");
|
||||
item.className = "job";
|
||||
const log = (job.log || []).slice(-28).join("\n");
|
||||
item.innerHTML = `
|
||||
<div class="job-head">
|
||||
<div>
|
||||
<div class="job-title"></div>
|
||||
<p class="muted"></p>
|
||||
</div>
|
||||
<span class="status"></span>
|
||||
</div>
|
||||
<pre></pre>
|
||||
<div class="toolbar">
|
||||
<span class="muted"></span>
|
||||
<div class="row" style="flex:0 0 auto"></div>
|
||||
</div>
|
||||
`;
|
||||
item.querySelector(".job-title").textContent = job.title;
|
||||
const libraryName = job.anime_name || job.title;
|
||||
const season = String(job.season || "1").padStart(2, "0");
|
||||
const seasonFolder = `Season ${season}`;
|
||||
const target = job.target_dir || `${job.download_dir}/${libraryName}/${seasonFolder}`;
|
||||
item.querySelector(".job-head .muted").textContent =
|
||||
`${libraryName} · S${season} · ${job.mode} · ${job.quality} · episodes ${job.episodes} · ${target}`;
|
||||
const status = item.querySelector(".status");
|
||||
status.textContent = job.status;
|
||||
status.classList.add(job.status);
|
||||
item.querySelector("pre").textContent = log || "Waiting...";
|
||||
item.querySelector(".toolbar .muted").textContent = job.exit_code === null ? "" : `exit ${job.exit_code}`;
|
||||
const actions = item.querySelector(".row");
|
||||
if (job.status === "running") {
|
||||
actions.append(actionButton("Cancel", () => queueAction(job.id, "cancel"), "danger"));
|
||||
} else if (job.status === "pending") {
|
||||
actions.append(actionButton("Cancel", () => queueAction(job.id, "cancel"), "danger"));
|
||||
} else {
|
||||
actions.append(actionButton("Retry", () => queueAction(job.id, "retry")));
|
||||
actions.append(actionButton("Remove", () => queueAction(job.id, "remove")));
|
||||
}
|
||||
el.appendChild(item);
|
||||
}
|
||||
renderQueuePager();
|
||||
}
|
||||
|
||||
function renderQueuePager() {
|
||||
const el = $("queuePager");
|
||||
const start = state.queueTotal ? ((state.queuePage - 1) * 10) + 1 : 0;
|
||||
const end = Math.min(state.queuePage * 10, state.queueTotal);
|
||||
el.innerHTML = `
|
||||
<span class="muted"></span>
|
||||
<div class="row" style="flex:0 0 auto"></div>
|
||||
`;
|
||||
el.querySelector(".muted").textContent =
|
||||
`${start}-${end} of ${state.queueTotal} · page ${state.queuePage} of ${state.queuePages}`;
|
||||
const controls = el.querySelector(".row");
|
||||
const prev = actionButton("Previous", () => {
|
||||
if (state.queuePage > 1) loadQueue(state.queuePage - 1);
|
||||
});
|
||||
const next = actionButton("Next", () => {
|
||||
if (state.queuePage < state.queuePages) loadQueue(state.queuePage + 1);
|
||||
});
|
||||
prev.disabled = state.queuePage <= 1;
|
||||
next.disabled = state.queuePage >= state.queuePages;
|
||||
controls.append(prev, next);
|
||||
}
|
||||
|
||||
function actionButton(text, handler, extra = "") {
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.textContent = text;
|
||||
btn.className = extra;
|
||||
btn.addEventListener("click", handler);
|
||||
return btn;
|
||||
}
|
||||
|
||||
async function queueAction(id, action) {
|
||||
try {
|
||||
await api(`/api/queue/${id}/${action}`, { method: "POST", body: "{}" });
|
||||
await loadQueue(state.queuePage);
|
||||
} catch (error) {
|
||||
setNotice(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function queueBulkAction(path, message) {
|
||||
try {
|
||||
const data = await api(path, { method: "POST", body: "{}" });
|
||||
setNotice(`${message}: ${data.count || 0}`);
|
||||
await loadQueue(state.queuePage);
|
||||
} catch (error) {
|
||||
setNotice(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadQueue(page = state.queuePage || 1) {
|
||||
const requestId = ++state.queueRequestId;
|
||||
const data = await api(`/api/queue?page=${page}&per_page=10`);
|
||||
if (requestId !== state.queueRequestId) return data;
|
||||
if (data.page > data.pages && data.pages > 0) return loadQueue(data.pages);
|
||||
renderQueue(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
state.config = await api("/api/config");
|
||||
$("jobFolder").value = state.config.download_dir;
|
||||
$("search-quality").value = state.config.quality;
|
||||
setMode(state.config.mode);
|
||||
}
|
||||
|
||||
$("searchBtn").addEventListener("click", search);
|
||||
$("search-query").addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter") search();
|
||||
});
|
||||
$("search-mode").addEventListener("change", (event) => setMode(event.target.value));
|
||||
$("trackBtn").addEventListener("click", addSelectedToWatchlist);
|
||||
$("addBtn").addEventListener("click", addSelected);
|
||||
$("removeFinishedBtn").addEventListener("click", () => queueBulkAction("/api/queue/clear-finished", "Removed finished jobs"));
|
||||
$("retryFailedBtn").addEventListener("click", () => queueBulkAction("/api/queue/retry-failed", "Retried failed jobs"));
|
||||
$("search-quality").addEventListener("change", () => { state.config.quality = $("search-quality").value; });
|
||||
$("firstEpBtn").addEventListener("click", () => { $("episodesInput").value = state.episodes[0] || ""; });
|
||||
$("latestEpBtn").addEventListener("click", () => {
|
||||
$("episodesInput").value = state.episodes[state.episodes.length - 1] || "";
|
||||
});
|
||||
$("allEpBtn").addEventListener("click", () => {
|
||||
const first = state.episodes[0] || "";
|
||||
const last = state.episodes[state.episodes.length - 1] || "";
|
||||
$("episodesInput").value = first && last ? `${first}-${last}` : "";
|
||||
});
|
||||
|
||||
(async function init() {
|
||||
try {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const query = (params.get("query") || "").trim();
|
||||
if (query) $("search-query").value = query;
|
||||
await loadConfig();
|
||||
await loadQueue();
|
||||
if (query) await search();
|
||||
state.queueTimer = startSerialPoll(() => loadQueue(), 2500);
|
||||
} catch (error) {
|
||||
setNotice(error.message);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
Reference in New Issue
Block a user