1458 lines
59 KiB
Python
1458 lines
59 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""Config page template for Kaizoku."""
|
|
|
|
from app_support import DISCORD_WEBHOOK_EVENT_CHOICES, DISCORD_WEBHOOK_EVENT_LABELS
|
|
from template_helpers import BROWSER_API_HELPER, render_page_links, render_sidebar_brand, render_sidebar_logout
|
|
|
|
|
|
WEBHOOK_EVENT_OPTIONS = "\n".join(
|
|
(
|
|
f' <label class="check-item"><input class="webhook-event" type="checkbox" value="{event_name}"> '
|
|
f"<span>{DISCORD_WEBHOOK_EVENT_LABELS[event_name]}</span></label>"
|
|
)
|
|
for event_name in DISCORD_WEBHOOK_EVENT_CHOICES
|
|
)
|
|
|
|
|
|
CONFIG_HTML = r"""<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Kaizoku - config</title>
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.png">
|
|
<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);
|
|
--focus: #b296ff;
|
|
--shadow: 0 24px 60px rgba(5, 2, 15, 0.42);
|
|
}
|
|
* { box-sizing: border-box; }
|
|
[hidden] { display: none !important; }
|
|
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, textarea {
|
|
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);
|
|
}
|
|
input, select, textarea {
|
|
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);
|
|
}
|
|
textarea {
|
|
min-height: 108px;
|
|
padding: 12px 13px;
|
|
resize: vertical;
|
|
}
|
|
input:focus, select:focus, textarea: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: flex;
|
|
flex-direction: column;
|
|
align-self: start;
|
|
position: sticky;
|
|
top: 0;
|
|
height: 100dvh;
|
|
overflow-y: auto;
|
|
gap: 20px;
|
|
backdrop-filter: blur(18px) saturate(170%);
|
|
}
|
|
aside > * { flex-shrink: 0; }
|
|
.sidebar-logout { margin: auto 0 0; padding-top: 20px; text-align: center; }
|
|
main {
|
|
display: grid;
|
|
gap: 20px;
|
|
min-width: 0;
|
|
align-content: start;
|
|
justify-items: stretch;
|
|
}
|
|
h1, h2, p { margin: 0; }
|
|
h1 {
|
|
font-size: 29px;
|
|
line-height: 1.05;
|
|
letter-spacing: -0.04em;
|
|
}
|
|
h2 {
|
|
font-size: 17px;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
.topline, .toolbar, .row {
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
}
|
|
.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; }
|
|
.watchlist-refresh-option {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
width: auto;
|
|
min-height: 0;
|
|
white-space: nowrap;
|
|
}
|
|
.watchlist-refresh-option input { width: auto; flex: none; }
|
|
.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);
|
|
}
|
|
.settings, .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));
|
|
padding: 18px;
|
|
display: grid;
|
|
gap: 14px;
|
|
box-shadow: var(--shadow);
|
|
backdrop-filter: blur(18px);
|
|
}
|
|
.muted {
|
|
color: var(--muted);
|
|
font-size: 13px;
|
|
}
|
|
.notice {
|
|
min-height: 20px;
|
|
color: #ddd0ff;
|
|
font-size: 13px;
|
|
}
|
|
.stack {
|
|
display: grid;
|
|
gap: 10px;
|
|
}
|
|
.wide-button {
|
|
width: 100%;
|
|
}
|
|
.chips {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 6px;
|
|
}
|
|
.badge {
|
|
border: 1px solid var(--line);
|
|
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: #95e4ba; border-color: rgba(149, 228, 186, 0.24); }
|
|
.badge.bad { color: #ffd0da; border-color: rgba(255, 144, 164, 0.22); }
|
|
.badge.warn { color: #ffe6a8; border-color: rgba(255, 217, 118, 0.28); }
|
|
#providerUpdatesPanel {
|
|
min-width: 0;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
.provider-update-list {
|
|
display: grid;
|
|
grid-template-columns: minmax(0, 1fr);
|
|
gap: 8px;
|
|
}
|
|
.provider-update-list .badge {
|
|
min-width: 0;
|
|
white-space: normal;
|
|
}
|
|
.provider-update-list:empty {
|
|
display: none;
|
|
}
|
|
.field-hint {
|
|
color: var(--muted);
|
|
font-size: 12px;
|
|
}
|
|
.path-input {
|
|
display: grid;
|
|
grid-template-columns: minmax(0, 1fr) auto;
|
|
gap: 10px;
|
|
align-items: center;
|
|
}
|
|
.form-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
gap: 12px;
|
|
}
|
|
.check-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
gap: 10px;
|
|
}
|
|
.check-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
min-height: 48px;
|
|
border: 1px solid var(--line);
|
|
border-radius: 16px;
|
|
padding: 10px 12px;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
color: var(--text);
|
|
text-transform: none;
|
|
letter-spacing: 0;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
}
|
|
.check-item input {
|
|
width: 18px;
|
|
min-height: 18px;
|
|
margin: 0;
|
|
accent-color: var(--accent);
|
|
}
|
|
.inline-actions {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
}
|
|
.deps {
|
|
justify-items: center;
|
|
text-align: center;
|
|
}
|
|
.deps .chips {
|
|
justify-content: center;
|
|
}
|
|
.settings-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
gap: 18px;
|
|
align-items: start;
|
|
width: 100%;
|
|
}
|
|
.settings-grid > [hidden] { display: none !important; }
|
|
.config-toolbar { align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
|
|
.config-tabs { display: flex; flex-wrap: wrap; gap: 7px; }
|
|
.config-tabs button.active { background: var(--accent, #8569df); color: white; }
|
|
.settings-main, .deps {
|
|
width: 100%;
|
|
}
|
|
.overlay[hidden] {
|
|
display: none !important;
|
|
}
|
|
.overlay {
|
|
position: fixed;
|
|
inset: 0;
|
|
z-index: 40;
|
|
display: grid;
|
|
place-items: center;
|
|
padding: 22px;
|
|
background: rgba(4, 3, 10, 0.78);
|
|
backdrop-filter: blur(10px);
|
|
}
|
|
.browser-modal {
|
|
width: min(100%, 860px);
|
|
max-height: min(84vh, 760px);
|
|
overflow: hidden;
|
|
border: 1px solid var(--line);
|
|
border-radius: 22px;
|
|
background: linear-gradient(180deg, rgba(29, 22, 47, 0.96), rgba(17, 13, 29, 0.98));
|
|
box-shadow: var(--shadow);
|
|
display: grid;
|
|
grid-template-rows: auto auto auto 1fr auto;
|
|
gap: 12px;
|
|
padding: 18px;
|
|
}
|
|
.browser-header,
|
|
.browser-actions,
|
|
.browser-footer {
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
flex-wrap: wrap;
|
|
}
|
|
.browser-path {
|
|
min-height: 42px;
|
|
border: 1px solid var(--line);
|
|
border-radius: 14px;
|
|
background: rgba(10, 7, 18, 0.82);
|
|
color: var(--text);
|
|
padding: 10px 13px;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
.browser-list {
|
|
overflow: auto;
|
|
border: 1px solid var(--line);
|
|
border-radius: 18px;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
padding: 8px;
|
|
display: grid;
|
|
gap: 8px;
|
|
min-height: 220px;
|
|
}
|
|
.browser-roots {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
padding-bottom: 4px;
|
|
border-bottom: 1px solid var(--line);
|
|
}
|
|
.browser-roots .ghost.active {
|
|
background: rgba(255, 255, 255, 0.08);
|
|
border-color: var(--line-strong);
|
|
color: var(--text);
|
|
}
|
|
.browser-entry {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 10px;
|
|
min-height: 44px;
|
|
padding: 0 14px;
|
|
border: 1px solid var(--line);
|
|
border-radius: 14px;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
color: var(--text);
|
|
text-align: left;
|
|
}
|
|
.browser-entry .muted {
|
|
font-size: 12px;
|
|
}
|
|
.browser-entry-name {
|
|
overflow-wrap: anywhere;
|
|
}
|
|
.changelog-modal {
|
|
width: min(100%, 900px);
|
|
max-height: min(84vh, 820px);
|
|
overflow: hidden;
|
|
border: 1px solid var(--line);
|
|
border-radius: 22px;
|
|
background: linear-gradient(180deg, rgba(29, 22, 47, 0.96), rgba(17, 13, 29, 0.98));
|
|
box-shadow: var(--shadow);
|
|
display: grid;
|
|
grid-template-rows: auto 1fr;
|
|
gap: 12px;
|
|
padding: 18px;
|
|
}
|
|
.changelog-header {
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
.changelog-content {
|
|
overflow: auto;
|
|
border: 1px solid var(--line);
|
|
border-radius: 18px;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
padding: 16px;
|
|
}
|
|
.changelog-content pre {
|
|
margin: 0;
|
|
white-space: pre-wrap;
|
|
overflow-wrap: anywhere;
|
|
color: var(--text);
|
|
font: 13px/1.55 "Cascadia Code", "Fira Code", Consolas, monospace;
|
|
}
|
|
@media (max-width: 900px) {
|
|
.app { grid-template-columns: 1fr; }
|
|
aside { position: static; height: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
|
|
.toolbar, .row { align-items: stretch; flex-direction: column; }
|
|
}
|
|
@media (max-width: 1080px) {
|
|
.settings-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
@media (max-width: 640px) {
|
|
.form-grid, .check-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="app">
|
|
<aside>
|
|
""" + render_sidebar_brand(
|
|
"Saved defaults, access settings, and runtime checks.",
|
|
"Config",
|
|
) + render_page_links("config") + r"""
|
|
|
|
<section class="settings">
|
|
<h2>Saved defaults</h2>
|
|
<div class="stack muted">
|
|
<p>These values preload the Search page and act as the fallback folder for new queue jobs.</p>
|
|
<p>Search uses these saved mode and quality defaults when opening result actions and queueing downloads.</p>
|
|
</div>
|
|
</section>
|
|
<section class="settings">
|
|
<h2>Runtime info</h2>
|
|
<div class="stack muted">
|
|
<p id="versionLine">Loading version...</p>
|
|
<p id="providerLine">Checking provider bridge...</p>
|
|
<p>Saved settings live in `.kaizoku/config.json` inside this project.</p>
|
|
</div>
|
|
<button class="ghost wide-button" id="openChangelogBtn" type="button">Changelog</button>
|
|
</section>
|
|
<section class="settings" id="providerUpdatesPanel">
|
|
<h2>Provider updates</h2>
|
|
<div class="stack muted">
|
|
<p id="providerUpdatesLine">Checking upstream provider files...</p>
|
|
<div class="provider-update-list" id="providerUpdatesList"></div>
|
|
</div>
|
|
</section>
|
|
""" + render_sidebar_logout() + r""" </aside>
|
|
|
|
<main>
|
|
<section class="deps" id="deps"></section>
|
|
<div class="notice" id="notice"></div>
|
|
<div class="toolbar config-toolbar">
|
|
<nav class="config-tabs" aria-label="Config sections">
|
|
<button type="button" class="active" data-tab="general">General</button>
|
|
<button type="button" data-tab="scheduler">Scheduler</button>
|
|
<button type="button" data-tab="handoff">Handoff</button>
|
|
<button type="button" data-tab="watchlist">Watchlist</button>
|
|
<button type="button" data-tab="notifications">Notifications</button>
|
|
<button type="button" data-tab="ai-subtitles">AI Subtitles</button>
|
|
</nav>
|
|
<button class="primary" id="saveConfigBtn" type="button">Save settings</button>
|
|
</div>
|
|
<div class="settings-grid">
|
|
<section class="settings settings-main" data-config-tab="ai-subtitles">
|
|
<div><h2>AI Subtitles</h2><p class="muted">Choose the translation provider and model. OpenAI API usage needs an API key and is billed separately from a ChatGPT subscription.</p></div>
|
|
<label>Translation provider
|
|
<select id="aiSubtitleBackend"><option value="ollama">Ollama</option><option value="openai">OpenAI API</option></select>
|
|
</label>
|
|
<div id="aiOllamaFields" class="settings">
|
|
<label>Ollama URL<input id="aiOllamaUrl" type="url" placeholder="http://192.168.88.15:11434"></label>
|
|
<label>Ollama model<input id="aiOllamaModel" list="aiOllamaModels" placeholder="translategemma:4b"><datalist id="aiOllamaModels"></datalist></label>
|
|
<button id="loadOllamaModels" type="button">Load available Ollama models</button>
|
|
</div>
|
|
<div id="aiOpenaiFields" class="settings" hidden>
|
|
<label>OpenAI API endpoint<input id="aiOpenaiUrl" type="url" placeholder="https://api.openai.com/v1"></label>
|
|
<label>OpenAI API token<input id="aiOpenaiKey" type="password" autocomplete="new-password" placeholder="Leave blank to keep saved token"></label>
|
|
<label class="check-item"><input id="aiOpenaiClearKey" type="checkbox"> Clear saved API token</label>
|
|
<div class="field-hint" id="aiOpenaiKeyStatus"></div>
|
|
<label>OpenAI GPT model<input id="aiOpenaiModel" list="aiOpenaiModels" placeholder="gpt-4.1-mini"><datalist id="aiOpenaiModels"></datalist></label>
|
|
<button id="loadOpenaiModels" type="button">Load available OpenAI models</button>
|
|
</div>
|
|
<div class="muted" id="aiModelsStatus" role="status"></div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="general">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Defaults</h2>
|
|
<p class="muted">Manage the folder, mode, quality, and provider defaults used by Search and new queue jobs.</p>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="stack">
|
|
<label>Public base URL
|
|
<input id="baseUrl" placeholder="https://tools.coreplay.eu/kaizoku">
|
|
</label>
|
|
<p class="muted">Use the full public URL or a path such as /kaizoku. The proxy must forward this path unchanged. KAIZOKU_BASE_URL overrides this setting. Reload at the new URL after saving.</p>
|
|
<label>Login username<input id="authUsername" autocomplete="username" placeholder="Leave blank to keep current username"></label>
|
|
<label>New login password<input id="authPassword" type="password" autocomplete="new-password" placeholder="Leave blank to keep current password"></label>
|
|
<p class="muted">Login protects all clients, including local proxy connections. Environment credentials override saved credentials. Changing credentials signs out existing sessions.</p>
|
|
<label>Default folder
|
|
<div class="path-input">
|
|
<input id="downloadDir" placeholder="/home/me/Downloads/Anime">
|
|
<button class="ghost browse-path-btn" type="button" data-target="downloadDir" data-mode="dir">Browse</button>
|
|
</div>
|
|
</label>
|
|
</div>
|
|
<div class="form-grid">
|
|
<label>Default mode
|
|
<select id="configMode">
|
|
<option value="sub">Subtitled (Sub)</option>
|
|
<option value="dub">Dubbed (Dub)</option>
|
|
</select>
|
|
</label>
|
|
<label>Default quality
|
|
<select id="configQuality">
|
|
<option value="best">Best</option>
|
|
<option value="1080">1080p</option>
|
|
<option value="720">720p</option>
|
|
<option value="480">480p</option>
|
|
</select>
|
|
</label>
|
|
</div>
|
|
<div class="field-hint">Tip: these are the saved defaults only. The active search form can still be adjusted per download.</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="general">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Provider</h2>
|
|
<p class="muted">Choose the default source used for search, watchlist refresh, and auto-downloads.</p>
|
|
</div>
|
|
</div>
|
|
<label>Default provider
|
|
<select id="configProvider">
|
|
<option value="anikoto">Anikoto</option>
|
|
<option value="anineko">AniNeko (retired upstream)</option>
|
|
<option value="pahe">AnimePahe</option>
|
|
</select>
|
|
</label>
|
|
<div class="field-hint">Search results and watchlist entries store their provider in the show ID, so existing tracked anime keep using their original source.</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="scheduler">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Watchlist schedule</h2>
|
|
<p class="muted">Periodically queue a background watchlist refresh to check for newly available episodes.</p>
|
|
</div>
|
|
</div>
|
|
<div class="form-grid">
|
|
<label>Automatic refresh
|
|
<select id="watchlistAutoRefreshEnabled">
|
|
<option value="false">Disabled</option>
|
|
<option value="true">Enabled</option>
|
|
</select>
|
|
</label>
|
|
<label>Refresh period (minutes)
|
|
<input id="watchlistAutoRefreshMinutes" type="number" min="1" max="10080" step="1" value="60">
|
|
</label>
|
|
<label>Delay between series (seconds)
|
|
<input id="watchlistRefreshDelaySeconds" type="number" min="0" max="300" step="1" value="5">
|
|
</label>
|
|
</div>
|
|
<div class="field-hint">When enabled, the server periodically starts the existing background “Refresh All” job using this interval. Bulk refreshes now wait this many seconds between shows to avoid flooding upstream sources.</div>
|
|
<h3>Watchlist backup schedule</h3>
|
|
<div class="form-grid">
|
|
<label>Automatic backups<select id="watchlistBackupEnabled"><option value="true">Enabled</option><option value="false">Disabled</option></select></label>
|
|
<label>Backup interval (minutes)<input id="watchlistBackupMinutes" type="number" min="1" max="10080" step="1" value="1440"></label>
|
|
<label>Keep latest backups<input id="watchlistBackupKeep" type="number" min="1" max="365" step="1" value="14"></label>
|
|
</div>
|
|
<div class="field-hint">A ZIP snapshot is created in /backup when due. The oldest scheduled backups are removed above the retention limit.</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="general">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Auto-download</h2>
|
|
<p class="muted">Automatically queue newly discovered episodes for shows in the `Watching` category after manual or scheduled refreshes.</p>
|
|
</div>
|
|
</div>
|
|
<div class="form-grid">
|
|
<label>Automatic queueing
|
|
<select id="autoDownloadEnabled">
|
|
<option value="false">Disabled</option>
|
|
<option value="true">Enabled</option>
|
|
</select>
|
|
</label>
|
|
<label>Default language
|
|
<select id="autoDownloadMode">
|
|
<option value="dub">Dubbed (Dub)</option>
|
|
<option value="sub">Subtitled (Sub)</option>
|
|
</select>
|
|
</label>
|
|
<label>Default quality
|
|
<select id="autoDownloadQuality">
|
|
<option value="best">Best</option>
|
|
<option value="1080">1080p</option>
|
|
<option value="720">720p</option>
|
|
<option value="480">480p</option>
|
|
</select>
|
|
</label>
|
|
</div>
|
|
<div class="field-hint">Adding a new watchlist entry does not auto-download anything. Auto-download only reacts to later manual refreshes or scheduled refreshes that find new episodes.</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="handoff">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Jellyfin handoff</h2>
|
|
<p class="muted">Move completed TV seasons and movies from the default download area into the folders that Jellyfin scans.</p>
|
|
</div>
|
|
<button id="runJellyfinSyncBtn" type="button">Run now</button>
|
|
</div>
|
|
<div class="form-grid">
|
|
<label>Automatic handoff
|
|
<select id="jellyfinSyncEnabled">
|
|
<option value="false">Disabled</option>
|
|
<option value="true">Enabled</option>
|
|
</select>
|
|
</label>
|
|
<label>Jellyfin TV library
|
|
<div class="path-input">
|
|
<input id="jellyfinTvDir" placeholder="/srv/media/anime-tv">
|
|
<button class="ghost browse-path-btn" type="button" data-target="jellyfinTvDir" data-mode="dir">Browse</button>
|
|
</div>
|
|
</label>
|
|
<label>Jellyfin movie library
|
|
<div class="path-input">
|
|
<input id="jellyfinMovieDir" placeholder="/srv/media/anime-movies">
|
|
<button class="ghost browse-path-btn" type="button" data-target="jellyfinMovieDir" data-mode="dir">Browse</button>
|
|
</div>
|
|
</label>
|
|
<label>Refresh after handoff
|
|
<select id="jellyfinApiRefreshEnabled">
|
|
<option value="false">Disabled</option>
|
|
<option value="true">Enabled</option>
|
|
</select>
|
|
</label>
|
|
<label>Jellyfin server URL
|
|
<input id="jellyfinServerUrl" placeholder="http://jellyfin:8096">
|
|
</label>
|
|
<label>Jellyfin API key
|
|
<input id="jellyfinApiKey" type="password" autocomplete="off" placeholder="API key">
|
|
</label>
|
|
<label>Library name or item ID
|
|
<input id="jellyfinLibrary" placeholder="Anime">
|
|
</label>
|
|
</div>
|
|
<div class="field-hint">Handoff verifies completion metadata for downloaded TV entries in Finished, then checks their expected video files in Downloads. Each completed season moves independently; unfinished seasons stay in Downloads. Missing or incorrect season metadata is repaired when it can be verified. If verification fails, the queue reports the skip so you can retry later. Movie entries move after their video is downloaded. When API refresh is enabled, Kaizoku refreshes only the named Jellyfin library once after a successful handoff batch.</div>
|
|
<div class="muted" id="jellyfinSyncStatus">No recent Jellyfin handoff job.</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="watchlist">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Watchlist filesystem sync</h2>
|
|
<p class="muted">Manually reconcile downloaded episode flags with the files currently present under the download library.</p>
|
|
</div>
|
|
<button id="reconcileWatchlistDownloadsBtn" type="button">Sync now</button>
|
|
</div>
|
|
<div class="field-hint">This scans the configured download library, removes downloaded episode flags for files that no longer exist, and adds flags for episodes already present on disk.</div>
|
|
<div class="muted" id="watchlistReconcileStatus">No watchlist filesystem sync run yet.</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="watchlist">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Watchlist backup</h2>
|
|
<p class="muted">Export or restore a complete watchlist database snapshot, including removed-show records.</p>
|
|
</div>
|
|
<div class="row">
|
|
<button id="exportWatchlistBtn" type="button">Export</button>
|
|
<button id="importWatchlistBtn" type="button">Import</button>
|
|
</div>
|
|
</div>
|
|
<input id="importWatchlistFile" type="file" accept="application/json,.json" hidden>
|
|
<div class="field-hint">Import replaces the current watchlist with the selected backup file.</div>
|
|
<div class="muted" id="watchlistBackupStatus">No watchlist backup action run yet.</div>
|
|
<div class="toolbar"><h3>Saved ZIP backups</h3><button id="createWatchlistBackupBtn" type="button">Create backup now</button></div>
|
|
<div id="watchlistBackupList" class="stack muted">Loading backups…</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="watchlist">
|
|
<div><h2>Watchlist management</h2><p class="muted">Create named watchlists. Watching, Planned, Finished and Dropped are fixed. Deleting a custom watchlist moves its entries to Planned.</p></div>
|
|
<div class="field-hint">Choose which watchlists are included in scheduled refreshes and Refresh All. Watching and Planned are selected by default. Save settings to apply changes. Refreshing one show directly still works from any watchlist.</div>
|
|
<div class="row"><input id="newWatchlistName" maxlength="60" placeholder="New watchlist name"><button id="addWatchlistBtn" type="button">Add watchlist</button></div>
|
|
<div id="watchlistCategoryList" class="stack muted">Loading watchlists…</div>
|
|
</section>
|
|
|
|
<section class="settings settings-main" data-config-tab="notifications">
|
|
<div class="toolbar">
|
|
<div>
|
|
<h2>Discord notifications</h2>
|
|
<p class="muted">Send webhook notifications for refresh discoveries, refresh problems, and unexpected runtime errors.</p>
|
|
</div>
|
|
<button id="testWebhookBtn" type="button">Test webhook</button>
|
|
</div>
|
|
<div class="stack">
|
|
<label>Discord webhook URL
|
|
<textarea id="discordWebhookUrl" placeholder="https://discord.com/api/webhooks/..."></textarea>
|
|
</label>
|
|
<div class="field-hint">The new-episodes notification includes one card per anime, with local cached thumbnails attached to the webhook when available.</div>
|
|
</div>
|
|
<div class="stack">
|
|
<label>Notify for</label>
|
|
<div class="check-grid">
|
|
""" + WEBHOOK_EVENT_OPTIONS + r"""
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<div class="overlay" id="pathBrowserOverlay" hidden>
|
|
<div class="browser-modal" role="dialog" aria-modal="true" aria-labelledby="pathBrowserTitle">
|
|
<div class="browser-header">
|
|
<div>
|
|
<h2 id="pathBrowserTitle">Choose path</h2>
|
|
<p class="muted" id="pathBrowserSubtitle">Browse folders on the host and select the destination path.</p>
|
|
</div>
|
|
<button class="ghost" id="pathBrowserCloseBtn" type="button" aria-label="Close path browser">×</button>
|
|
</div>
|
|
<div class="browser-path" id="pathBrowserCurrentPath"></div>
|
|
<div class="browser-actions">
|
|
<div class="inline-actions">
|
|
<button class="ghost" id="pathBrowserHomeBtn" type="button">Home</button>
|
|
<button class="ghost" id="pathBrowserUpBtn" type="button">Up</button>
|
|
<button class="ghost" id="pathBrowserRefreshBtn" type="button">Refresh</button>
|
|
</div>
|
|
<div class="muted" id="pathBrowserStatus"></div>
|
|
</div>
|
|
<div class="browser-list" id="pathBrowserList"></div>
|
|
<div class="browser-footer">
|
|
<button class="ghost" id="pathBrowserCancelBtn" type="button">Cancel</button>
|
|
<button class="primary" id="pathBrowserSelectBtn" type="button">Use this path</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="overlay" id="changelogOverlay" hidden>
|
|
<div class="changelog-modal" role="dialog" aria-modal="true" aria-labelledby="changelogTitle">
|
|
<div class="changelog-header">
|
|
<div>
|
|
<h2 id="changelogTitle">Changelog</h2>
|
|
<p class="muted">Recent release notes loaded from the project's `CHANGELOG.md` file.</p>
|
|
</div>
|
|
<button class="ghost" id="closeChangelogBtn" type="button" aria-label="Close changelog">×</button>
|
|
</div>
|
|
<div class="changelog-content">
|
|
<pre id="changelogContent">Loading changelog...</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const state = {
|
|
config: {
|
|
mode: "sub",
|
|
quality: "best",
|
|
download_dir: "",
|
|
provider: "anikoto",
|
|
download_methods: ["kaizoku"],
|
|
watchlist_auto_refresh_enabled: false,
|
|
watchlist_auto_refresh_minutes: 60,
|
|
watchlist_refresh_categories: ["watching", "planned"],
|
|
watchlist_backup_enabled: true,
|
|
watchlist_backup_minutes: 1440,
|
|
watchlist_backup_keep: 14,
|
|
watchlist_refresh_delay_seconds: 5,
|
|
auto_download_enabled: false,
|
|
auto_download_mode: "dub",
|
|
auto_download_quality: "best",
|
|
jellyfin_sync_enabled: false,
|
|
jellyfin_tv_dir: "",
|
|
jellyfin_movie_dir: "",
|
|
ai_subtitle_backend: "ollama",
|
|
ai_subtitle_ollama_url: "http://192.168.88.15:11434",
|
|
ai_subtitle_ollama_model: "translategemma:4b",
|
|
ai_subtitle_openai_url: "https://api.openai.com/v1",
|
|
ai_subtitle_openai_model: "gpt-4.1-mini",
|
|
discord_webhook_url: "",
|
|
discord_webhook_events: []
|
|
},
|
|
pathBrowser: {
|
|
targetId: "",
|
|
mode: "dir",
|
|
path: "",
|
|
parent_path: "",
|
|
home_path: ""
|
|
},
|
|
jellyfinSyncRunning: false,
|
|
jellyfinSyncJobId: null,
|
|
watchlistReconcileRunning: false,
|
|
watchlistImportRunning: false
|
|
};
|
|
|
|
const $ = (id) => document.getElementById(id);
|
|
""" + BROWSER_API_HELPER + r"""
|
|
|
|
const pathBrowserOverlay = $("pathBrowserOverlay");
|
|
const pathBrowserCurrentPath = $("pathBrowserCurrentPath");
|
|
const pathBrowserList = $("pathBrowserList");
|
|
const pathBrowserStatus = $("pathBrowserStatus");
|
|
const changelogOverlay = $("changelogOverlay");
|
|
const changelogContent = $("changelogContent");
|
|
|
|
function setNotice(text) {
|
|
$("notice").textContent = text || "";
|
|
}
|
|
|
|
function setJellyfinSyncButton(running) {
|
|
$("runJellyfinSyncBtn").disabled = !!running;
|
|
$("runJellyfinSyncBtn").textContent = running ? "Running..." : "Run now";
|
|
}
|
|
|
|
function setJellyfinSyncStatus(job) {
|
|
const el = $("jellyfinSyncStatus");
|
|
if (!job) {
|
|
el.textContent = "No recent Jellyfin handoff job.";
|
|
return;
|
|
}
|
|
if (job.status === "running") {
|
|
const title = job.current_title ? ` · ${job.current_title}` : "";
|
|
const file = job.current_file ? ` · ${job.current_file}` : "";
|
|
el.textContent = `${job.completed || 0}/${job.total || 0} processed · ${job.moved || 0} moved · ${job.moved_files || 0} files${title}${file}`;
|
|
return;
|
|
}
|
|
el.textContent = job.message || "Jellyfin handoff idle.";
|
|
}
|
|
|
|
function setWatchlistReconcileButton(running) {
|
|
$("reconcileWatchlistDownloadsBtn").disabled = !!running;
|
|
$("reconcileWatchlistDownloadsBtn").textContent = running ? "Syncing..." : "Sync now";
|
|
}
|
|
|
|
function setWatchlistReconcileStatus(text) {
|
|
$("watchlistReconcileStatus").textContent = text || "No watchlist filesystem sync run yet.";
|
|
}
|
|
|
|
function setWatchlistBackupStatus(text) {
|
|
$("watchlistBackupStatus").textContent = text || "No watchlist backup action run yet.";
|
|
}
|
|
|
|
function setWatchlistImportButton(running) {
|
|
$("importWatchlistBtn").disabled = !!running;
|
|
$("importWatchlistBtn").textContent = running ? "Importing..." : "Import";
|
|
}
|
|
|
|
function selectedWebhookEvents() {
|
|
return [...document.querySelectorAll(".webhook-event:checked")].map((input) => input.value);
|
|
}
|
|
|
|
function formConfigPayload() {
|
|
const payload = {
|
|
base_url: $("baseUrl").value,
|
|
download_dir: $("downloadDir").value,
|
|
mode: $("configMode").value,
|
|
quality: $("configQuality").value,
|
|
provider: $("configProvider").value,
|
|
download_methods: ["kaizoku"],
|
|
watchlist_auto_refresh_enabled: $("watchlistAutoRefreshEnabled").value === "true",
|
|
watchlist_auto_refresh_minutes: $("watchlistAutoRefreshMinutes").value,
|
|
watchlist_refresh_categories: document.querySelector(".watchlist-refresh-toggle")
|
|
? [...document.querySelectorAll(".watchlist-refresh-toggle:checked")].map((input) => input.value)
|
|
: (state.config.watchlist_refresh_categories || ["watching", "planned"]),
|
|
watchlist_backup_enabled: $("watchlistBackupEnabled").value === "true",
|
|
watchlist_backup_minutes: $("watchlistBackupMinutes").value,
|
|
watchlist_backup_keep: $("watchlistBackupKeep").value,
|
|
watchlist_refresh_delay_seconds: $("watchlistRefreshDelaySeconds").value,
|
|
auto_download_enabled: $("autoDownloadEnabled").value === "true",
|
|
auto_download_mode: $("autoDownloadMode").value,
|
|
auto_download_quality: $("autoDownloadQuality").value,
|
|
jellyfin_sync_enabled: $("jellyfinSyncEnabled").value === "true",
|
|
jellyfin_tv_dir: $("jellyfinTvDir").value,
|
|
jellyfin_movie_dir: $("jellyfinMovieDir").value,
|
|
jellyfin_api_refresh_enabled: $("jellyfinApiRefreshEnabled").value === "true",
|
|
jellyfin_server_url: $("jellyfinServerUrl").value,
|
|
jellyfin_api_key: $("jellyfinApiKey").value,
|
|
jellyfin_library: $("jellyfinLibrary").value,
|
|
ai_subtitle_backend: $("aiSubtitleBackend").value,
|
|
ai_subtitle_ollama_url: $("aiOllamaUrl").value,
|
|
ai_subtitle_ollama_model: $("aiOllamaModel").value,
|
|
ai_subtitle_openai_url: $("aiOpenaiUrl").value,
|
|
ai_subtitle_openai_model: $("aiOpenaiModel").value,
|
|
discord_webhook_url: $("discordWebhookUrl").value,
|
|
discord_webhook_events: selectedWebhookEvents()
|
|
};
|
|
if ($("authUsername").value.trim()) payload.auth_username = $("authUsername").value.trim();
|
|
if ($("authPassword").value) payload.auth_password = $("authPassword").value;
|
|
if ($("aiOpenaiKey").value.trim()) payload.ai_subtitle_openai_api_key = $("aiOpenaiKey").value.trim();
|
|
else if ($("aiOpenaiClearKey").checked) payload.ai_subtitle_openai_api_key = "";
|
|
return payload;
|
|
}
|
|
|
|
function updateAiProviderFields() {
|
|
const openai = $("aiSubtitleBackend").value === "openai";
|
|
$("aiOllamaFields").hidden = openai;
|
|
$("aiOpenaiFields").hidden = !openai;
|
|
}
|
|
|
|
async function loadAiModels(backend) {
|
|
const status = $("aiModelsStatus");
|
|
status.textContent = "Loading models…";
|
|
try {
|
|
const result = await api("/api/config/ai-subtitles/models", {method:"POST", body:JSON.stringify({
|
|
ai_subtitle_backend: backend,
|
|
ai_subtitle_ollama_url: $("aiOllamaUrl").value,
|
|
ai_subtitle_openai_url: $("aiOpenaiUrl").value,
|
|
ai_subtitle_openai_api_key: $("aiOpenaiKey").value.trim() || undefined
|
|
})});
|
|
const list = $(backend === "openai" ? "aiOpenaiModels" : "aiOllamaModels");
|
|
list.replaceChildren();
|
|
for (const name of result.models) { const option = document.createElement("option"); option.value = name; list.append(option); }
|
|
status.textContent = `${result.models.length} available models loaded. Choose one from the model field or enter a custom name.`;
|
|
} catch (error) { status.textContent = error.message; }
|
|
}
|
|
|
|
function applyConfig(data) {
|
|
state.config = data;
|
|
$("baseUrl").value = data.base_url || "";
|
|
$("authUsername").value = "";
|
|
$("authPassword").value = "";
|
|
$("downloadDir").value = data.download_dir;
|
|
$("configMode").value = data.mode;
|
|
$("configQuality").value = data.quality;
|
|
$("configProvider").value = data.provider || "anikoto";
|
|
$("watchlistAutoRefreshEnabled").value = String(Boolean(data.watchlist_auto_refresh_enabled));
|
|
$("watchlistAutoRefreshMinutes").value = data.watchlist_auto_refresh_minutes;
|
|
state.config.watchlist_refresh_categories = data.watchlist_refresh_categories || ["watching", "planned"];
|
|
$("watchlistBackupEnabled").value = String(Boolean(data.watchlist_backup_enabled));
|
|
$("watchlistBackupMinutes").value = data.watchlist_backup_minutes;
|
|
$("watchlistBackupKeep").value = data.watchlist_backup_keep;
|
|
$("watchlistRefreshDelaySeconds").value = data.watchlist_refresh_delay_seconds;
|
|
$("autoDownloadEnabled").value = String(Boolean(data.auto_download_enabled));
|
|
$("autoDownloadMode").value = data.auto_download_mode;
|
|
$("autoDownloadQuality").value = data.auto_download_quality;
|
|
$("jellyfinSyncEnabled").value = String(Boolean(data.jellyfin_sync_enabled));
|
|
$("jellyfinTvDir").value = data.jellyfin_tv_dir || "";
|
|
$("jellyfinMovieDir").value = data.jellyfin_movie_dir || "";
|
|
$("jellyfinApiRefreshEnabled").value = String(Boolean(data.jellyfin_api_refresh_enabled));
|
|
$("jellyfinServerUrl").value = data.jellyfin_server_url || "";
|
|
$("jellyfinApiKey").value = data.jellyfin_api_key || "";
|
|
$("jellyfinLibrary").value = data.jellyfin_library || "";
|
|
$("aiSubtitleBackend").value = data.ai_subtitle_backend || "ollama";
|
|
$("aiOllamaUrl").value = data.ai_subtitle_ollama_url || "";
|
|
$("aiOllamaModel").value = data.ai_subtitle_ollama_model || "";
|
|
$("aiOpenaiUrl").value = data.ai_subtitle_openai_url || "";
|
|
$("aiOpenaiModel").value = data.ai_subtitle_openai_model || "";
|
|
$("aiOpenaiKey").value = "";
|
|
$("aiOpenaiClearKey").checked = false;
|
|
$("aiOpenaiKeyStatus").textContent = data.ai_subtitle_openai_key_set ? "A token is saved. Leave the field blank to keep it." : "No API token saved.";
|
|
updateAiProviderFields();
|
|
$("discordWebhookUrl").value = data.discord_webhook_url || "";
|
|
const selected = new Set(data.discord_webhook_events || []);
|
|
for (const input of document.querySelectorAll(".webhook-event")) {
|
|
input.checked = selected.has(input.value);
|
|
}
|
|
}
|
|
|
|
async function loadConfig() {
|
|
applyConfig(await api("/api/config"));
|
|
}
|
|
|
|
async function saveConfig() {
|
|
try {
|
|
applyConfig(await api("/api/config", {
|
|
method: "POST",
|
|
body: JSON.stringify(formConfigPayload())
|
|
}));
|
|
setNotice("Settings saved.");
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
}
|
|
|
|
async function testWebhook() {
|
|
try {
|
|
const data = await api("/api/config/webhook/test", {
|
|
method: "POST",
|
|
body: JSON.stringify(formConfigPayload())
|
|
});
|
|
setNotice(data.message || "Discord webhook test notification sent.");
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
}
|
|
|
|
async function pollJellyfinSyncStatus(notifyOnComplete = true) {
|
|
try {
|
|
const data = await api("/api/config/jellyfin/sync-status");
|
|
const job = data.job || null;
|
|
const running = !!data.running && !!job;
|
|
const wasRunning = state.jellyfinSyncRunning;
|
|
state.jellyfinSyncRunning = running;
|
|
state.jellyfinSyncJobId = job ? job.id : null;
|
|
setJellyfinSyncButton(running);
|
|
setJellyfinSyncStatus(job);
|
|
if (running) {
|
|
setNotice(job.message || "Jellyfin handoff running...");
|
|
} else if (job && wasRunning && notifyOnComplete) {
|
|
setNotice(job.message || "Jellyfin handoff completed.");
|
|
}
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
}
|
|
|
|
async function runJellyfinSync() {
|
|
try {
|
|
const data = await api("/api/config/jellyfin/sync", {
|
|
method: "POST",
|
|
body: JSON.stringify(formConfigPayload())
|
|
});
|
|
const job = data.job || null;
|
|
state.jellyfinSyncRunning = !!job && (job.status === "pending" || job.status === "running");
|
|
state.jellyfinSyncJobId = job ? job.id : null;
|
|
setJellyfinSyncButton(state.jellyfinSyncRunning);
|
|
setJellyfinSyncStatus(job);
|
|
setNotice(data.message || "Jellyfin handoff started.");
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
}
|
|
|
|
async function reconcileWatchlistDownloads() {
|
|
state.watchlistReconcileRunning = true;
|
|
setWatchlistReconcileButton(true);
|
|
setWatchlistReconcileStatus("Scanning the download library...");
|
|
try {
|
|
const data = await api("/api/config/watchlist/reconcile-downloads", {
|
|
method: "POST",
|
|
body: JSON.stringify(formConfigPayload())
|
|
});
|
|
const changed = Number(data.changed || 0);
|
|
const total = Number(data.total || 0);
|
|
setWatchlistReconcileStatus(`${changed} updated out of ${total} watchlist entries.`);
|
|
setNotice(data.message || "Watchlist filesystem sync completed.");
|
|
} catch (error) {
|
|
setWatchlistReconcileStatus("Watchlist filesystem sync failed.");
|
|
setNotice(error.message);
|
|
} finally {
|
|
state.watchlistReconcileRunning = false;
|
|
setWatchlistReconcileButton(false);
|
|
}
|
|
}
|
|
|
|
function exportWatchlistBackup() {
|
|
setWatchlistBackupStatus("Preparing watchlist backup download...");
|
|
window.location.href = "/api/config/watchlist/export";
|
|
}
|
|
|
|
function selectConfigTab(tab) {
|
|
for (const section of document.querySelectorAll("[data-config-tab]")) section.hidden = section.dataset.configTab !== tab;
|
|
for (const button of document.querySelectorAll(".config-tabs [data-tab]")) {
|
|
button.classList.toggle("active", button.dataset.tab === tab);
|
|
button.setAttribute("aria-selected", String(button.dataset.tab === tab));
|
|
}
|
|
history.replaceState(null, "", `#${tab}`);
|
|
}
|
|
|
|
async function loadSavedBackups() {
|
|
const container = $("watchlistBackupList");
|
|
try {
|
|
const data = await api("/api/config/watchlist/backups");
|
|
container.replaceChildren();
|
|
if (data.error) { const error = document.createElement("p"); error.textContent = `Backup error: ${data.error}`; container.append(error); }
|
|
if (!data.backups.length) { const empty = document.createElement("p"); empty.textContent = `No ZIP backups in ${data.directory}.`; container.append(empty); }
|
|
for (const backup of data.backups) {
|
|
const row = document.createElement("div"); row.className = "toolbar";
|
|
const label = document.createElement("span"); label.textContent = `${new Date(backup.created_at).toLocaleString()} · ${backup.name} · ${Math.ceil(backup.size / 1024)} KB`;
|
|
const download = document.createElement("a"); download.href = `/api/config/watchlist/backups/download?name=${encodeURIComponent(backup.name)}`; download.textContent = "Download";
|
|
const restore = document.createElement("button"); restore.type = "button"; restore.textContent = "Restore";
|
|
restore.addEventListener("click", async () => {
|
|
if (!confirm(`Restore ${backup.name}? This replaces the current watchlist and category names.`)) return;
|
|
try {
|
|
const result = await api("/api/config/watchlist/backups/restore", {method:"POST", body:JSON.stringify({name:backup.name})});
|
|
setNotice(result.message); await loadWatchlistCategories();
|
|
} catch (error) { setNotice(error.message); }
|
|
});
|
|
row.append(label, download, restore); container.append(row);
|
|
}
|
|
} catch (error) { container.textContent = error.message; }
|
|
}
|
|
|
|
async function loadWatchlistCategories() {
|
|
const container = $("watchlistCategoryList");
|
|
try {
|
|
const data = await api("/api/config/watchlist/categories");
|
|
container.replaceChildren();
|
|
for (const entry of data.categories) {
|
|
const row = document.createElement("div"); row.className = "toolbar";
|
|
const label = document.createElement("strong"); label.textContent = entry.label;
|
|
row.append(label);
|
|
const refreshLabel = document.createElement("label"); refreshLabel.className = "watchlist-refresh-option";
|
|
const refresh = document.createElement("input"); refresh.type = "checkbox"; refresh.className = "watchlist-refresh-toggle";
|
|
refresh.value = entry.category;
|
|
refresh.checked = (state.config.watchlist_refresh_categories || ["watching", "planned"]).includes(entry.category);
|
|
refresh.addEventListener("change", () => {
|
|
state.config.watchlist_refresh_categories = [...document.querySelectorAll(".watchlist-refresh-toggle:checked")].map((input) => input.value);
|
|
});
|
|
refreshLabel.append(refresh, document.createTextNode("Refresh"));
|
|
row.append(refreshLabel);
|
|
if (!entry.fixed) {
|
|
const rename = document.createElement("button"); rename.type = "button"; rename.textContent = "Rename";
|
|
rename.addEventListener("click", async () => {
|
|
const name = prompt("New watchlist name", entry.label);
|
|
if (name === null) return;
|
|
try { await api("/api/config/watchlist/categories", {method:"POST", body:JSON.stringify({action:"rename", category:entry.category, label:name})}); await loadWatchlistCategories(); } catch (error) { setNotice(error.message); }
|
|
});
|
|
const remove = document.createElement("button"); remove.type = "button"; remove.textContent = "Delete";
|
|
remove.addEventListener("click", async () => {
|
|
if (!confirm(`Delete ${entry.label}? Its entries will move to Planned.`)) return;
|
|
try { const result = await api("/api/config/watchlist/categories", {method:"POST", body:JSON.stringify({action:"delete", category:entry.category})}); state.config.watchlist_refresh_categories = (state.config.watchlist_refresh_categories || []).filter((key) => key !== entry.category); setNotice(result.message); await loadWatchlistCategories(); } catch (error) { setNotice(error.message); }
|
|
});
|
|
row.append(rename, remove);
|
|
}
|
|
container.append(row);
|
|
}
|
|
} catch (error) { container.textContent = error.message; }
|
|
}
|
|
|
|
async function importWatchlistBackup(file) {
|
|
if (!file) return;
|
|
state.watchlistImportRunning = true;
|
|
setWatchlistImportButton(true);
|
|
setWatchlistBackupStatus("Reading backup file...");
|
|
try {
|
|
const payload = JSON.parse(await file.text());
|
|
setWatchlistBackupStatus("Importing backup...");
|
|
const data = await api("/api/config/watchlist/import", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload)
|
|
});
|
|
setWatchlistBackupStatus(`${data.imported || 0} watchlist entries imported.`);
|
|
setNotice(data.message || "Watchlist backup imported.");
|
|
} catch (error) {
|
|
setWatchlistBackupStatus("Watchlist backup import failed.");
|
|
setNotice(error.message);
|
|
} finally {
|
|
$("importWatchlistFile").value = "";
|
|
state.watchlistImportRunning = false;
|
|
setWatchlistImportButton(false);
|
|
}
|
|
}
|
|
|
|
function closePathBrowser() {
|
|
state.pathBrowser = {
|
|
targetId: "",
|
|
mode: "dir",
|
|
path: "",
|
|
parent_path: "",
|
|
home_path: "",
|
|
root_paths: []
|
|
};
|
|
pathBrowserOverlay.hidden = true;
|
|
pathBrowserList.innerHTML = "";
|
|
pathBrowserStatus.textContent = "";
|
|
}
|
|
|
|
function closeChangelog() {
|
|
changelogOverlay.hidden = true;
|
|
}
|
|
|
|
function renderPathBrowser(data) {
|
|
state.pathBrowser = {
|
|
...state.pathBrowser,
|
|
...data
|
|
};
|
|
pathBrowserCurrentPath.textContent = data.path || "";
|
|
pathBrowserStatus.textContent = "";
|
|
pathBrowserList.innerHTML = "";
|
|
const roots = Array.isArray(data.root_paths) ? data.root_paths : [];
|
|
if (roots.length > 1) {
|
|
const rootGroup = document.createElement("div");
|
|
rootGroup.className = "browser-roots";
|
|
for (const rootPath of roots) {
|
|
const active = data.path === rootPath || String(data.path || "").startsWith(`${rootPath}/`);
|
|
const button = document.createElement("button");
|
|
button.type = "button";
|
|
button.className = `ghost${active ? " active" : ""}`;
|
|
button.textContent = rootPath;
|
|
button.addEventListener("click", () => loadPathBrowser(rootPath));
|
|
rootGroup.appendChild(button);
|
|
}
|
|
pathBrowserList.appendChild(rootGroup);
|
|
}
|
|
if (!Array.isArray(data.entries) || !data.entries.length) {
|
|
const empty = document.createElement("div");
|
|
empty.className = "muted";
|
|
empty.textContent = "No entries found in this folder.";
|
|
pathBrowserList.appendChild(empty);
|
|
return;
|
|
}
|
|
for (const entry of data.entries) {
|
|
const button = document.createElement("button");
|
|
button.type = "button";
|
|
button.className = "browser-entry";
|
|
button.innerHTML = `
|
|
<span class="browser-entry-name"></span>
|
|
<span class="muted"></span>
|
|
`;
|
|
button.querySelector(".browser-entry-name").textContent = entry.name;
|
|
button.querySelector(".muted").textContent = entry.is_dir ? "Folder" : "File";
|
|
button.addEventListener("click", async () => {
|
|
if (entry.is_dir) {
|
|
await loadPathBrowser(entry.path);
|
|
return;
|
|
}
|
|
state.pathBrowser.path = entry.path;
|
|
pathBrowserCurrentPath.textContent = entry.path;
|
|
});
|
|
pathBrowserList.appendChild(button);
|
|
}
|
|
}
|
|
|
|
async function loadPathBrowser(path = "") {
|
|
try {
|
|
pathBrowserStatus.textContent = "Loading...";
|
|
const data = await api(`/api/fs/browse?path=${encodeURIComponent(path || state.pathBrowser.path || "")}&mode=${encodeURIComponent(state.pathBrowser.mode || "dir")}`);
|
|
renderPathBrowser(data);
|
|
} catch (error) {
|
|
pathBrowserStatus.textContent = error.message;
|
|
}
|
|
}
|
|
|
|
async function openPathBrowser(targetId, mode = "dir") {
|
|
state.pathBrowser = {
|
|
targetId,
|
|
mode,
|
|
path: $(targetId).value.trim() || "",
|
|
parent_path: "",
|
|
home_path: "",
|
|
root_paths: []
|
|
};
|
|
pathBrowserOverlay.hidden = false;
|
|
await loadPathBrowser(state.pathBrowser.path);
|
|
}
|
|
|
|
async function browseParentPath() {
|
|
if (!state.pathBrowser.parent_path) return;
|
|
await loadPathBrowser(state.pathBrowser.parent_path);
|
|
}
|
|
|
|
async function browseHomePath() {
|
|
if (!state.pathBrowser.home_path) return;
|
|
await loadPathBrowser(state.pathBrowser.home_path);
|
|
}
|
|
|
|
function selectCurrentBrowserPath() {
|
|
if (!state.pathBrowser.targetId) return;
|
|
$(state.pathBrowser.targetId).value = state.pathBrowser.path || "";
|
|
closePathBrowser();
|
|
}
|
|
|
|
async function loadDeps() {
|
|
const data = await api("/api/dependencies");
|
|
const el = $("deps");
|
|
el.innerHTML = "<h2>Dependencies</h2>";
|
|
const wrap = document.createElement("div");
|
|
wrap.className = "chips";
|
|
for (const [name, ok] of Object.entries(data)) {
|
|
const span = document.createElement("span");
|
|
span.className = `badge ${ok ? "ok" : "bad"}`;
|
|
span.textContent = `${name} ${ok ? "ok" : "missing"}`;
|
|
wrap.appendChild(span);
|
|
}
|
|
el.appendChild(wrap);
|
|
}
|
|
|
|
async function loadVersion() {
|
|
const data = await api("/api/version");
|
|
$("versionLine").textContent = `${data.name} ${data.version}`;
|
|
$("providerLine").textContent = `Providers: ${(data.providers || []).join(", ") || "Unavailable"}`;
|
|
}
|
|
|
|
function providerUpdateBadgeClass(status) {
|
|
if (status === "up_to_date") return "ok";
|
|
if (status === "local_changes") return "ok";
|
|
if (status === "updates_available") return "warn";
|
|
if (status === "error") return "bad";
|
|
return "";
|
|
}
|
|
|
|
function renderProviderUpdates(data) {
|
|
const line = $("providerUpdatesLine");
|
|
const list = $("providerUpdatesList");
|
|
const status = data.status || "idle";
|
|
const checked = data.checked_files ? `${data.checked_files} checked` : "";
|
|
const checkedAt = data.checked_at ? ` · ${new Date(data.checked_at).toLocaleString()}` : "";
|
|
line.textContent = `${data.message || "Provider update status unavailable."}${checked ? ` · ${checked}` : ""}${checkedAt}`;
|
|
list.innerHTML = "";
|
|
|
|
const files = [
|
|
...(data.updated_files || []).map((item) => item.path),
|
|
...(data.locally_modified_files || []).map((item) => `${item.path} local ${item.local_version || "modified"}`),
|
|
...(data.missing_upstream_files || []),
|
|
...(data.retired_upstream_files || []).map((path) => `${path} retired upstream · compatibility adapter retained`)
|
|
];
|
|
if (!files.length && status !== "checking") {
|
|
const badge = document.createElement("span");
|
|
badge.className = `badge ${providerUpdateBadgeClass(status)}`;
|
|
badge.textContent = status === "up_to_date" ? "up to date" : status.replace(/_/g, " ");
|
|
list.appendChild(badge);
|
|
return;
|
|
}
|
|
for (const path of files) {
|
|
const badge = document.createElement("span");
|
|
badge.className = `badge ${providerUpdateBadgeClass(status)}`;
|
|
badge.textContent = path;
|
|
list.appendChild(badge);
|
|
}
|
|
}
|
|
|
|
async function loadProviderUpdates() {
|
|
try {
|
|
renderProviderUpdates(await api("/api/provider-updates"));
|
|
} catch (error) {
|
|
renderProviderUpdates({
|
|
status: "error",
|
|
message: error.message || "Provider update status unavailable."
|
|
});
|
|
}
|
|
}
|
|
|
|
async function openChangelog() {
|
|
try {
|
|
changelogContent.textContent = "Loading changelog...";
|
|
changelogOverlay.hidden = false;
|
|
const data = await api("/api/changelog");
|
|
changelogContent.textContent = data.content || "Changelog unavailable.";
|
|
} catch (error) {
|
|
changelogContent.textContent = error.message || "Changelog unavailable.";
|
|
}
|
|
}
|
|
|
|
$("saveConfigBtn").addEventListener("click", saveConfig);
|
|
for (const button of document.querySelectorAll(".config-tabs [data-tab]")) button.addEventListener("click", () => selectConfigTab(button.dataset.tab));
|
|
selectConfigTab(["general", "scheduler", "handoff", "watchlist", "notifications", "ai-subtitles"].includes(location.hash.slice(1)) ? location.hash.slice(1) : "general");
|
|
$("createWatchlistBackupBtn").addEventListener("click", async () => {
|
|
try { const result = await api("/api/config/watchlist/backups/create", {method:"POST", body:"{}"}); setNotice(result.message); await loadSavedBackups(); } catch (error) { setNotice(error.message); }
|
|
});
|
|
$("addWatchlistBtn").addEventListener("click", async () => {
|
|
try {
|
|
await api("/api/config/watchlist/categories", {method:"POST", body:JSON.stringify({action:"create", label:$("newWatchlistName").value})});
|
|
$("newWatchlistName").value = ""; await loadWatchlistCategories();
|
|
} catch (error) { setNotice(error.message); }
|
|
});
|
|
$("aiSubtitleBackend").addEventListener("change", updateAiProviderFields);
|
|
$("loadOllamaModels").addEventListener("click", () => loadAiModels("ollama"));
|
|
$("loadOpenaiModels").addEventListener("click", () => loadAiModels("openai"));
|
|
$("testWebhookBtn").addEventListener("click", testWebhook);
|
|
$("runJellyfinSyncBtn").addEventListener("click", runJellyfinSync);
|
|
$("reconcileWatchlistDownloadsBtn").addEventListener("click", reconcileWatchlistDownloads);
|
|
$("exportWatchlistBtn").addEventListener("click", exportWatchlistBackup);
|
|
$("importWatchlistBtn").addEventListener("click", () => $("importWatchlistFile").click());
|
|
$("importWatchlistFile").addEventListener("change", (event) => importWatchlistBackup((event.target.files || [])[0]));
|
|
$("openChangelogBtn").addEventListener("click", openChangelog);
|
|
$("closeChangelogBtn").addEventListener("click", closeChangelog);
|
|
$("pathBrowserCloseBtn").addEventListener("click", closePathBrowser);
|
|
$("pathBrowserCancelBtn").addEventListener("click", closePathBrowser);
|
|
$("pathBrowserSelectBtn").addEventListener("click", selectCurrentBrowserPath);
|
|
$("pathBrowserUpBtn").addEventListener("click", browseParentPath);
|
|
$("pathBrowserHomeBtn").addEventListener("click", browseHomePath);
|
|
$("pathBrowserRefreshBtn").addEventListener("click", () => loadPathBrowser());
|
|
for (const button of document.querySelectorAll(".browse-path-btn")) {
|
|
button.addEventListener("click", () => openPathBrowser(button.dataset.target || "", button.dataset.mode || "dir"));
|
|
}
|
|
|
|
(async function init() {
|
|
try {
|
|
await loadConfig();
|
|
await Promise.all([loadSavedBackups(), loadWatchlistCategories()]);
|
|
await pollJellyfinSyncStatus(false);
|
|
await loadDeps();
|
|
await loadVersion();
|
|
await loadProviderUpdates();
|
|
window.setInterval(() => {
|
|
pollJellyfinSyncStatus();
|
|
}, 2500);
|
|
window.setInterval(loadProviderUpdates, 10000);
|
|
} catch (error) {
|
|
setNotice(error.message);
|
|
}
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"""
|