590 lines
18 KiB
Python
590 lines
18 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""Search page template for ani-cli-web."""
|
|
|
|
from template_helpers import BROWSER_API_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: grid;
|
|
gap: 8px;
|
|
padding: 6px;
|
|
border: 1px solid var(--line);
|
|
border-radius: 18px;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
}
|
|
.page-link {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: flex-start;
|
|
width: 100%;
|
|
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 {
|
|
display: grid;
|
|
gap: 10px;
|
|
min-width: 0;
|
|
}
|
|
.result, .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); }
|
|
.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; }
|
|
}
|
|
</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>
|
|
</main>
|
|
</div>
|
|
|
|
<script>
|
|
const state = {
|
|
config: { mode: "sub", quality: "best", download_dir: "" },
|
|
selected: null,
|
|
episodes: [],
|
|
searchRequestId: 0,
|
|
episodeRequestId: 0
|
|
};
|
|
|
|
const $ = (id) => document.getElementById(id);
|
|
""" + BROWSER_API_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. Open Queue to monitor progress.");
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
}
|
|
|
|
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);
|
|
$("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();
|
|
if (query) await search();
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"""
|