From 863757e344213bb5db4536d7f4aee6863ae85d22 Mon Sep 17 00:00:00 2001 From: Dymas Date: Wed, 14 Oct 2026 09:31:40 +0200 Subject: [PATCH] Organize config and add scheduled watchlist backups and custom lists --- .gitignore | 1 + CHANGELOG.md | 7 ++ README.md | 9 ++- VERSION | 2 +- app.py | 155 ++++++++++++++++++++++++++++++++++++++----- app_support.py | 11 +++ config_page.py | 134 ++++++++++++++++++++++++++++++++++--- docker-compose.yaml | 2 + docker-entrypoint.sh | 4 +- http_handler.py | 26 ++++++++ search_page.py | 11 +++ test_app.py | 45 ++++++++++++- watchlist_backup.py | 123 ++++++++++++++++++++++++++++++++++ watchlist_page.py | 5 +- 14 files changed, 499 insertions(+), 36 deletions(-) create mode 100644 watchlist_backup.py diff --git a/.gitignore b/.gitignore index 4b90629..7dd6c0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .kaizoku/ downloads/ +backup/ node_modules/ __pycache__/ **/__pycache__/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 381218a..8713655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.54.12 - 2026-10-14 + +- Organized Config into General, Scheduler, Handoff, Watchlist, Notifications and AI Subtitles tabs. Existing settings retain their saved values. +- Added automatic watchlist ZIP snapshots in `/backup`, with a 1440-minute default interval, 14-file retention, manual creation, download and restore. Docker Compose mounts a host backup folder. +- Added custom named watchlists to Config, Watchlist and Search. The four built-in lists remain fixed; deleting a custom list moves its shows to Planned. Category definitions are included in new backups; older JSON backups remain importable. +- Checked all anime providers against upstream; versions are current and bundled Anikoto/AnimePahe local patches remain in place. + ## 0.54.11 - 2026-10-14 - Added Watchlist title search that filters across all pages before pagination, with an **All categories** tab for searching every watchlist. Search also matches provider titles and custom library names while keeping category counts and totals intact. diff --git a/README.md b/README.md index ef64bfe..b8f522d 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,13 @@ Kaizoku is a local web app for searching, tracking, and downloading anime from A - Save files with Jellyfin-friendly layout: `TV/Series Name/Season 01/Series Name - S01E01.mp4`, including Season 00 for specials. - Save English external subtitles when the provider exposes usable subtitle tracks. - Backfill missing English subtitle sidecars for existing watchlist videos with **Download all → Subtitles only**, without downloading the video again. -- Manage focused watchlists for `Watching`, `Planned`, `Finished`, and `Dropped`, with an All categories view, title search across every page, provider source tags, and title links back to the original provider page. +- Manage fixed `Watching`, `Planned`, `Finished`, and `Dropped` watchlists plus custom named watchlists from **Config → Watchlist**. The All categories view, title search, provider source tags and title links remain available. Deleting a custom watchlist moves its entries to Planned. - Periodically refresh selected watchlists with a single visible advancing progress bar and auto-download newly available episodes. - Sync watchlist download flags from completed video files on the filesystem; subtitles, metadata, and partial downloads do not count as downloaded episodes or movies. - Hand completed TV seasons or movie folders to Jellyfin, then optionally request a scan of only the configured Jellyfin library. - Catalog Jellyfin SRT/VTT subtitles and existing Czech ASS/SSA/SUB/TTML sidecars, including `cs`/`cz` language suffixes. Queue English-to-Czech SRT/VTT translations for individual files, seasons or full series from **AI Subtitles**; existing Czech sidecars are shown and skipped. - Choose Ollama or the OpenAI API in Config → AI Subtitles, enter a custom endpoint/model, and load available models from the selected service. Ollama defaults to `http://192.168.88.15:11434` with `translategemma:4b`; OpenAI defaults to `https://api.openai.com/v1` with `gpt-4.1-mini`. An OpenAI API key is required for OpenAI translation and is kept out of public config responses. OpenAI API billing is separate from ChatGPT subscriptions. -- Export/import watchlist backups. +- Export/import watchlist JSON backups, or create, download and restore scheduled ZIP backups from **Config → Watchlist**. **Config → Scheduler** controls the backup interval (default 1440 minutes), enable switch and retention (default 14); only the oldest scheduled ZIPs are pruned. - Send unified Discord notifications for downloads, refreshes, Jellyfin handoff, and runtime errors. - Check bundled provider JavaScript against upstream `TheYogMehta/extensions` from the Config page. - Store configuration, queue state, and watchlist data in SQLite under `.kaizoku/`. @@ -54,6 +54,8 @@ Then open: http://127.0.0.1:8421/ ``` +Local runs store scheduled watchlist ZIPs in `./backup`; Docker uses the `/backup` mount. Set `KAIZOKU_BACKUP_DIR` to use another backup directory outside Docker. + For Uptime Kuma or another HTTP availability monitor, use `http://IP:PORT/status`. `GET` returns HTTP 200 with `OK`; `HEAD` also returns HTTP 200. The endpoint needs no authentication and reports whether Kaizoku's HTTP server is responding. It does not check provider or download health. For a monitor on another machine, bind Kaizoku to a reachable address and set `KAIZOKU_ALLOW_REMOTE=1`; the normal app and API routes still require configured credentials for remote clients. For a dashboard, request `GET /api/watchlist/homepage?include_downloads=1`. The usual `watchlist`, `planned`, `finished`, `dropped`, and `total` counts remain, and `downloads` adds `total`, `running`, `pending`, `failed`, and a `jobs` array. `downloads.total` counts the jobs in these three states. Each job includes `id`, `name`, `title`, `status`, `episodes`, `mode`, `provider`, and available `progress` fields such as `percent`, `episode`, and `message`. `name` is the task name, with `title` retained for existing dashboard clients. The array lists running, pending, and failed downloads in that order, including live progress for the current job; completed and canceled jobs and Jellyfin handoffs are excluded. Without the query option, the response has the original counts only. This route always requires HTTP Basic auth, even for local requests. It uses the `KAIZOKU_AUTH_USERNAME` and `KAIZOKU_AUTH_PASSWORD` supplied to Docker Compose; set both before starting the container. A missing or invalid Basic header receives HTTP 401 with a `WWW-Authenticate` challenge. @@ -94,6 +96,7 @@ The compose file builds the local checkout and runs Kaizoku on port `8421` by de - `${JELLYFIN_TV_DIR:-./jellyfin/tv}` to `/jellyfin/tv` - `${JELLYFIN_MOVIE_DIR:-./jellyfin/movies}` to `/jellyfin/movies` - `./.kaizoku` to `/app/.kaizoku` +- `${KAIZOKU_BACKUP_HOST_DIR:-./backup}` to `/backup` for watchlist ZIP backups Use `/jellyfin/tv` for the Jellyfin TV directory and `/jellyfin/movies` for the Jellyfin movie directory inside the Config page. Override `JELLYFIN_TV_DIR` and `JELLYFIN_MOVIE_DIR` to point those container paths at your real host Jellyfin library folders. @@ -111,7 +114,7 @@ KAIZOKU_ALLOW_REMOTE=1 KAIZOKU_AUTH_USERNAME=admin KAIZOKU_AUTH_PASSWORD='change USER_UID=$(id -u) USER_GID=$(id -g) docker compose up -d ``` -When `USER_UID` and `USER_GID` are set, the entrypoint attempts to adjust ownership for `/downloads`, `/jellyfin/tv`, `/jellyfin/movies`, and Kaizoku state paths. Ownership changes are best-effort so policy-managed or read-only Jellyfin mounts can still be browsed and used when their existing permissions allow it. +When `USER_UID` and `USER_GID` are set, the entrypoint attempts to adjust ownership for `/downloads`, `/jellyfin/tv`, `/jellyfin/movies`, `/backup`, and Kaizoku state paths. Ownership changes are best-effort so policy-managed or read-only Jellyfin mounts can still be browsed and used when their existing permissions allow it. Keep `./.kaizoku` mounted for production instances. That directory contains the SQLite database, configuration, queue history, watchlist data, thumbnail cache, remote sessions, and temporary staging files. Removing the mount starts Kaizoku with a fresh empty state. diff --git a/VERSION b/VERSION index b587baa..1300cfb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.54.11 +0.54.12 diff --git a/app.py b/app.py index 81c207b..8c92a95 100644 --- a/app.py +++ b/app.py @@ -9,6 +9,7 @@ import shutil import sqlite3 import threading import time +import uuid import urllib.error import urllib.request import xml.etree.ElementTree as ET @@ -79,6 +80,7 @@ from watchlist_identity import ( titles_confidently_match, ) from web_templates import CONFIG_HTML, INDEX_HTML, QUEUE_HTML, WATCHLIST_HTML +from watchlist_backup import WatchlistBackupScheduler RUNTIME_LOCK = threading.RLock() @@ -97,7 +99,7 @@ WATCHLIST_REFRESH = None WATCHLIST_AUTO_REFRESH = None WATCHLIST_JELLYFIN_SYNC = None AI_SUBTITLES = None -WATCHLIST_BACKUP_FORMAT_VERSION = 1 +WATCHLIST_BACKUP_FORMAT_VERSION = 2 PROVIDER_UPDATE_STATUS = provider_updates.default_status() PROVIDER_UPDATE_CHECK_THREAD = None @@ -322,11 +324,12 @@ def normalize_watchlist_category(value, default="watching"): "finished": "finished", "dropped": "dropped", } - return aliases.get(text, default) + return aliases.get(text, text if re.fullmatch(r"custom-[0-9a-f]{12}", text) else default) def watchlist_category_label(value): - return WATCHLIST_CATEGORY_LABELS[normalize_watchlist_category(value)] + category = normalize_watchlist_category(value) + return WATCHLIST_CATEGORY_LABELS.get(category, category) def media_type_label(value): @@ -964,7 +967,7 @@ def search_anime(query, mode, provider=None): "index": index, "query": query, "watchlist_category": tracked_category, - "watchlist_category_label": watchlist_category_label(tracked_category) if tracked_category else "", + "watchlist_category_label": WATCHLIST.category_labels.get(tracked_category, watchlist_category_label(tracked_category)) if tracked_category and WATCHLIST else "", "mode": mode, "provider": show.get("provider") or provider, "alternative_titles": alternative_titles, @@ -1507,8 +1510,10 @@ class WatchlistStore: self.refresh_worker = None self.worker_enabled = bool(start_worker) self._init_db() + self._load_categories() self._migrate_legacy_json() self._restore_queued_refreshes() + self.backup_scheduler = WatchlistBackupScheduler(self.export_backup, self.import_backup, self.config_getter, start_worker=start_worker) if start_worker: self.ensure_worker() @@ -1516,11 +1521,13 @@ class WatchlistStore: if not self.worker_enabled: return with self.lock: - if self.refresh_worker is not None and self.refresh_worker.is_alive(): - return - self.refresh_stop_event.clear() - self.refresh_worker = threading.Thread(target=self._refresh_loop, daemon=True) - self.refresh_worker.start() + if self.refresh_worker is None or not self.refresh_worker.is_alive(): + self.refresh_stop_event.clear() + self.refresh_worker = threading.Thread(target=self._refresh_loop, daemon=True) + self.refresh_worker.start() + if hasattr(self, "backup_scheduler"): + self.backup_scheduler.worker_enabled = True + self.backup_scheduler.ensure_worker() def shutdown(self, wait=False): self.refresh_stop_event.set() @@ -1528,7 +1535,8 @@ class WatchlistStore: worker = self.refresh_worker if wait and worker is not None and worker.is_alive(): worker.join(timeout=WORKER_SHUTDOWN_TIMEOUT_SECONDS) - return worker is None or not worker.is_alive() + backup_stopped = self.backup_scheduler.shutdown(wait=wait) if hasattr(self, "backup_scheduler") else True + return (worker is None or not worker.is_alive()) and backup_stopped def _refresh_request_timeout(self): return WATCHLIST_REFRESH_REQUEST_TIMEOUT_SECONDS @@ -1778,6 +1786,9 @@ class WatchlistStore: conn.execute("CREATE INDEX IF NOT EXISTS idx_watchlist_title ON watchlist(title)") conn.execute("CREATE INDEX IF NOT EXISTS idx_watchlist_category ON watchlist(category)") conn.execute("CREATE INDEX IF NOT EXISTS idx_watchlist_updated_at ON watchlist(updated_at DESC)") + conn.execute("CREATE TABLE IF NOT EXISTS watchlist_categories (category TEXT PRIMARY KEY, label TEXT NOT NULL, fixed INTEGER NOT NULL DEFAULT 0)") + for category, label in WATCHLIST_CATEGORY_LABELS.items(): + conn.execute("INSERT OR IGNORE INTO watchlist_categories (category, label, fixed) VALUES (?, ?, 1)", (category, label)) conn.execute( """ CREATE TABLE IF NOT EXISTS watchlist_removals ( @@ -1788,6 +1799,56 @@ class WatchlistStore: """ ) + def _load_categories(self): + with self.lock, self._connect() as conn: + self.category_labels = {row["category"]: row["label"] for row in conn.execute("SELECT category, label FROM watchlist_categories")} + + def categories(self): + with self.lock, self._connect() as conn: + return [dict(row) for row in conn.execute("SELECT category, label, fixed FROM watchlist_categories ORDER BY fixed DESC, CASE category WHEN 'watching' THEN 0 WHEN 'planned' THEN 1 WHEN 'finished' THEN 2 ELSE 3 END, label COLLATE NOCASE")] + + def _valid_category(self, category): + category = normalize_watchlist_category(category) + if category not in self.category_labels: + raise ValueError("Watchlist category does not exist.") + return category + + def create_category(self, label): + label = str(label or "").strip() + if not label or len(label) > 60: + raise ValueError("Watchlist name must be 1–60 characters.") + with self.lock, self._connect() as conn: + if conn.execute("SELECT 1 FROM watchlist_categories WHERE label = ? COLLATE NOCASE", (label,)).fetchone(): + raise ValueError("A watchlist with that name already exists.") + category = "custom-" + uuid.uuid4().hex[:12] + conn.execute("INSERT INTO watchlist_categories VALUES (?, ?, 0)", (category, label)) + self._load_categories() + return {"category": category, "label": label, "fixed": 0} + + def rename_category(self, category, label): + label = str(label or "").strip() + if not label or len(label) > 60: + raise ValueError("Watchlist name must be 1–60 characters.") + with self.lock, self._connect() as conn: + row = conn.execute("SELECT fixed FROM watchlist_categories WHERE category = ?", (category,)).fetchone() + if row is None or row["fixed"]: + raise ValueError("Only custom watchlists can be renamed.") + if conn.execute("SELECT 1 FROM watchlist_categories WHERE label = ? COLLATE NOCASE AND category != ?", (label, category)).fetchone(): + raise ValueError("A watchlist with that name already exists.") + conn.execute("UPDATE watchlist_categories SET label = ? WHERE category = ?", (label, category)) + self._load_categories() + return {"category": category, "label": label} + + def delete_category(self, category): + with self.lock, self._connect() as conn: + row = conn.execute("SELECT fixed FROM watchlist_categories WHERE category = ?", (category,)).fetchone() + if row is None or row["fixed"]: + raise ValueError("Only custom watchlists can be deleted.") + moved = conn.execute("UPDATE watchlist SET category = 'planned', updated_at = ? WHERE category = ?", (now_iso(), category)).rowcount + conn.execute("DELETE FROM watchlist_categories WHERE category = ?", (category,)) + self._load_categories() + return {"moved": moved, "message": f"Watchlist deleted. {moved} entries moved to Planned."} + def _remember_removal_conn(self, conn, show_id, title): conn.execute( """ @@ -1817,7 +1878,7 @@ class WatchlistStore: item["provider"] = normalize_provider(item.get("provider"), parsed_provider) item["provider_label"] = provider_label(item["provider"]) item["category"] = normalize_watchlist_category(item.get("category")) - item["category_label"] = watchlist_category_label(item["category"]) + item["category_label"] = self.category_labels.get(item["category"], watchlist_category_label(item["category"])) item["media_type"] = normalize_media_type(item.get("media_type")) item["media_type_label"] = media_type_label(item["media_type"]) item["downloaded"] = bool(int(item.get("downloaded") or 0)) @@ -2026,7 +2087,7 @@ class WatchlistStore: def list(self, page=1, per_page=30, category=None, search=None): page = max(1, int(page or 1)) per_page = min(60, max(1, int(per_page or 30))) - active_category = normalize_watchlist_category(category) if category else None + active_category = self._valid_category(category) if category else None search = str(search or "").strip()[:200] filters = [] parameters = [] @@ -2061,7 +2122,7 @@ class WatchlistStore: (*parameters, per_page, offset), ).fetchall() items = [self._row_to_item(row) for row in rows] - category_counts = {key: 0 for key in WATCHLIST_CATEGORY_CHOICES} + category_counts = {key: 0 for key in self.category_labels} for row in category_rows: category_counts[normalize_watchlist_category(row["category"])] = int(row["count"] or 0) return { @@ -2071,9 +2132,10 @@ class WatchlistStore: "pages": pages, "per_page": per_page, "active_category": active_category, - "active_category_label": watchlist_category_label(active_category) if active_category else "", + "active_category_label": self.category_labels.get(active_category, "") if active_category else "", "search": search, "categories": category_counts, + "category_definitions": self.categories(), "queued_count": int(queued_total or 0), "summary": { "shows": int(overall_total or 0), @@ -2142,7 +2204,7 @@ class WatchlistStore: "show_id": show_id, "provider": provider, "title": title, - "category": normalize_watchlist_category(payload.get("category")), + "category": self._valid_category(payload.get("category")), "downloaded": False, "status": "queued", "status_message": "Queued initial watchlist refresh.", @@ -2364,7 +2426,7 @@ class WatchlistStore: with self.lock, self._connect() as conn: conn.execute( "UPDATE watchlist SET category = ?, updated_at = ? WHERE show_id = ?", - (normalize_watchlist_category(category), now, existing["show_id"]), + (self._valid_category(category), now, existing["show_id"]), ) return self.get(show_id) @@ -2470,6 +2532,7 @@ class WatchlistStore: with self.lock, self._connect() as conn: watchlist_columns = self._table_columns_conn(conn, "watchlist") removal_columns = self._table_columns_conn(conn, "watchlist_removals") + category_columns = self._table_columns_conn(conn, "watchlist_categories") watchlist_rows = [ {column: row[column] for column in watchlist_columns} for row in conn.execute("SELECT * FROM watchlist ORDER BY title COLLATE NOCASE ASC").fetchall() @@ -2478,6 +2541,7 @@ class WatchlistStore: {column: row[column] for column in removal_columns} for row in conn.execute("SELECT * FROM watchlist_removals ORDER BY removed_at DESC").fetchall() ] + category_rows = [{column: row[column] for column in category_columns} for row in conn.execute("SELECT * FROM watchlist_categories ORDER BY category")] return { "format": "kaizoku-watchlist-backup", "format_version": WATCHLIST_BACKUP_FORMAT_VERSION, @@ -2492,6 +2556,7 @@ class WatchlistStore: "columns": removal_columns, "rows": removal_rows, }, + "watchlist_categories": {"columns": category_columns, "rows": category_rows}, }, } @@ -2519,12 +2584,30 @@ class WatchlistStore: raise ValueError("Backup is missing watchlist rows.") if not isinstance(removal_rows, list): raise ValueError("Backup removal rows must be an array.") + category_rows = ((tables.get("watchlist_categories") or {}).get("rows") if format_version >= 2 else []) + if not isinstance(category_rows, list): + raise ValueError("Backup category rows must be an array.") now = now_iso() with self.lock, self._connect() as conn: watchlist_columns = self._table_columns_conn(conn, "watchlist") removal_columns = self._table_columns_conn(conn, "watchlist_removals") + for row in category_rows: + if not isinstance(row, dict): + raise ValueError("Backup category rows must be JSON objects.") + category = str(row.get("category") or "") + label = str(row.get("label") or "").strip() + if category not in WATCHLIST_CATEGORY_LABELS and (not re.fullmatch(r"custom-[0-9a-f]{12}", category) or not label or len(label) > 60): + raise ValueError("Backup contains an invalid watchlist category.") + backup_category_ids = {row["category"] for row in category_rows} | set(WATCHLIST_CATEGORY_LABELS) + for row in watchlist_rows: + if isinstance(row, dict) and normalize_watchlist_category(row.get("category")) not in backup_category_ids: + raise ValueError("Backup references a missing watchlist category.") conn.execute("DELETE FROM watchlist") conn.execute("DELETE FROM watchlist_removals") + conn.execute("DELETE FROM watchlist_categories WHERE fixed = 0") + for row in category_rows: + if row["category"] not in WATCHLIST_CATEGORY_LABELS: + conn.execute("INSERT INTO watchlist_categories (category, label, fixed) VALUES (?, ?, 0)", (row["category"], row["label"])) imported_watchlist = 0 for row in watchlist_rows: if not isinstance(row, dict): @@ -2571,6 +2654,7 @@ class WatchlistStore: [values.get(column) for column in removal_columns], ) imported_removals += 1 + self._load_categories() return { "message": f"Imported {imported_watchlist} watchlist entr{'y' if imported_watchlist == 1 else 'ies'} from backup.", "imported": imported_watchlist, @@ -3170,6 +3254,37 @@ def import_watchlist_backup(payload): return runtime["watchlist"].import_backup(payload) +def list_watchlist_categories(): + return ensure_runtime()["watchlist"].categories() + + +def manage_watchlist_category(action, payload): + store = ensure_runtime()["watchlist"] + if action == "create": + return store.create_category(payload.get("label")) + if action == "rename": + return store.rename_category(payload.get("category"), payload.get("label")) + if action == "delete": + return store.delete_category(payload.get("category")) + raise ValueError("Unknown watchlist action.") + + +def list_watchlist_backups(): + return ensure_runtime()["watchlist"].backup_scheduler.list() + + +def create_watchlist_backup(): + return ensure_runtime()["watchlist"].backup_scheduler.create() + + +def download_watchlist_backup(name): + return ensure_runtime()["watchlist"].backup_scheduler.download(name) + + +def restore_watchlist_backup(name): + return ensure_runtime()["watchlist"].backup_scheduler.restore(name) + + def reconcile_watchlist_downloaded_files(config=None): runtime = ensure_runtime() active_config = normalize_config(config or runtime["config"] or {}) @@ -3343,6 +3458,8 @@ def save_runtime_config(config): clear_remote_access_sessions({"fingerprint": previous_fingerprint}) if scheduler is not None: scheduler.notify_config_changed() + if WATCHLIST is not None: + WATCHLIST.backup_scheduler.notify_config_changed() return dict(CONFIG) @@ -3555,6 +3672,12 @@ Handler = build_handler_class( ensure_runtime=ensure_runtime, episode_list=episode_list, export_watchlist_backup=export_watchlist_backup, + list_watchlist_backups=list_watchlist_backups, + create_watchlist_backup=create_watchlist_backup, + download_watchlist_backup=download_watchlist_backup, + restore_watchlist_backup=restore_watchlist_backup, + list_watchlist_categories=list_watchlist_categories, + manage_watchlist_category=manage_watchlist_category, get_config_snapshot=get_config_snapshot, get_provider_update_status=get_provider_update_status, get_watchlist_homepage_summary=get_watchlist_homepage_summary, diff --git a/app_support.py b/app_support.py index d6ce5a6..9a4053b 100644 --- a/app_support.py +++ b/app_support.py @@ -309,6 +309,9 @@ DEFAULT_CONFIG = { "provider": "anikoto", "watchlist_auto_refresh_enabled": False, "watchlist_auto_refresh_minutes": WATCHLIST_AUTO_REFRESH_DEFAULT_MINUTES, + "watchlist_backup_enabled": True, + "watchlist_backup_minutes": 1440, + "watchlist_backup_keep": 14, "watchlist_refresh_delay_seconds": WATCHLIST_REFRESH_DELAY_DEFAULT_SECONDS, "auto_download_enabled": False, "auto_download_mode": "dub", @@ -482,6 +485,14 @@ def normalize_config(data): config["provider"] = provider if provider in PROVIDER_CHOICES else "anikoto" config["watchlist_auto_refresh_enabled"] = auto_refresh_enabled config["watchlist_auto_refresh_minutes"] = auto_refresh_minutes + backup_enabled = config.get("watchlist_backup_enabled") + config["watchlist_backup_enabled"] = backup_enabled.strip().lower() in {"1", "true", "yes", "on"} if isinstance(backup_enabled, str) else bool(backup_enabled) + for key, default, minimum, maximum in (("watchlist_backup_minutes", 1440, 1, 10080), ("watchlist_backup_keep", 14, 1, 365)): + try: + value = int(config.get(key)) + except (TypeError, ValueError): + value = default + config[key] = max(minimum, min(maximum, value)) config["watchlist_refresh_delay_seconds"] = refresh_delay_seconds config["auto_download_enabled"] = auto_download_enabled config["auto_download_mode"] = auto_download_mode if auto_download_mode in MODE_CHOICES else "dub" diff --git a/config_page.py b/config_page.py index 8e20375..b574a66 100644 --- a/config_page.py +++ b/config_page.py @@ -313,6 +313,10 @@ CONFIG_HTML = r""" 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%; } @@ -487,8 +491,19 @@ CONFIG_HTML = r"""
+
+ + +
-
+

AI Subtitles

Choose the translation provider and model. OpenAI API usage needs an API key and is billed separately from a ChatGPT subscription.

-
+

Defaults

Manage the folder, mode, quality, and provider defaults used by Search and new queue jobs.

- +
-
+

Provider

@@ -561,7 +576,7 @@ CONFIG_HTML = r"""
Search results and watchlist entries store their provider in the show ID, so existing tracked anime keep using their original source.
-
+

Watchlist schedule

@@ -583,9 +598,16 @@ CONFIG_HTML = r"""
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.
+

Watchlist backup schedule

+
+ + + +
+
A ZIP snapshot is created in /backup when due. The oldest scheduled backups are removed above the retention limit.
-
+

Auto-download

@@ -617,7 +639,7 @@ CONFIG_HTML = r"""
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.
-
+

Jellyfin handoff

@@ -664,7 +686,7 @@ CONFIG_HTML = r"""
No recent Jellyfin handoff job.
-
+

Watchlist filesystem sync

@@ -676,7 +698,7 @@ CONFIG_HTML = r"""
No watchlist filesystem sync run yet.
-
+

Watchlist backup

@@ -690,9 +712,17 @@ CONFIG_HTML = r"""
Import replaces the current watchlist with the selected backup file.
No watchlist backup action run yet.
+

Saved ZIP backups

+
Loading backups…
-
+
+

Watchlist management

Create named watchlists. Watching, Planned, Finished and Dropped are fixed. Deleting a custom watchlist moves its entries to Planned.

+
+
Loading watchlists…
+
+ +

Discord notifications

@@ -768,6 +798,9 @@ CONFIG_HTML = r""" download_methods: ["kaizoku"], watchlist_auto_refresh_enabled: false, watchlist_auto_refresh_minutes: 60, + 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", @@ -861,6 +894,9 @@ CONFIG_HTML = r""" download_methods: ["kaizoku"], watchlist_auto_refresh_enabled: $("watchlistAutoRefreshEnabled").value === "true", watchlist_auto_refresh_minutes: $("watchlistAutoRefreshMinutes").value, + 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, @@ -916,6 +952,9 @@ CONFIG_HTML = r""" $("configProvider").value = data.provider || "anikoto"; $("watchlistAutoRefreshEnabled").value = String(Boolean(data.watchlist_auto_refresh_enabled)); $("watchlistAutoRefreshMinutes").value = data.watchlist_auto_refresh_minutes; + $("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; @@ -953,7 +992,7 @@ CONFIG_HTML = r""" method: "POST", body: JSON.stringify(formConfigPayload()) })); - setNotice("Defaults saved."); + setNotice("Settings saved."); } catch (error) { setNotice(error.message); } @@ -1035,6 +1074,67 @@ CONFIG_HTML = r""" 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); + 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})}); 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; @@ -1249,6 +1349,17 @@ CONFIG_HTML = r""" } $("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")); @@ -1291,6 +1402,7 @@ CONFIG_HTML = r""" (async function init() { try { await loadConfig(); + await Promise.all([loadSavedBackups(), loadWatchlistCategories()]); await pollJellyfinSyncStatus(false); await loadDeps(); await loadVersion(); diff --git a/docker-compose.yaml b/docker-compose.yaml index 49321a5..b551375 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -20,6 +20,7 @@ services: KAIZOKU_REMOTE_PATH_ROOTS: ${KAIZOKU_REMOTE_PATH_ROOTS:-/downloads,/jellyfin/tv,/jellyfin/movies} KAIZOKU_DOWNLOAD_DIR: /downloads KAIZOKU_STATE_ROOT: /app/.kaizoku + KAIZOKU_BACKUP_DIR: /backup KAIZOKU_OLLAMA_URL: ${KAIZOKU_OLLAMA_URL:-http://192.168.88.15:11434} KAIZOKU_SUBTITLE_MODEL: ${KAIZOKU_SUBTITLE_MODEL:-translategemma:4b} volumes: @@ -27,3 +28,4 @@ services: - ${JELLYFIN_TV_DIR:-./jellyfin/tv}:/jellyfin/tv - ${JELLYFIN_MOVIE_DIR:-./jellyfin/movies}:/jellyfin/movies - ./.kaizoku:/app/.kaizoku + - ${KAIZOKU_BACKUP_HOST_DIR:-./backup}:/backup diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c1f2a4b..d8cdd58 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -35,7 +35,7 @@ run_as_requested_user() { fi mkdir -p /app/.kaizoku/home - for path in /downloads /jellyfin/tv /jellyfin/movies /app/.kaizoku /app/.kaizoku/home; do + for path in /downloads /jellyfin/tv /jellyfin/movies /backup /app/.kaizoku /app/.kaizoku/home; do chown_path "$uid:$gid" "$path" done @@ -47,7 +47,7 @@ run_as_requested_user() { env HOME=/app/.kaizoku/home python3 /app/app.py "$@" } -mkdir -p /downloads /jellyfin/tv /jellyfin/movies /app/.kaizoku +mkdir -p /downloads /jellyfin/tv /jellyfin/movies /backup /app/.kaizoku run_as_requested_user "$@" || true diff --git a/http_handler.py b/http_handler.py index ca1c370..0dc3840 100644 --- a/http_handler.py +++ b/http_handler.py @@ -57,6 +57,12 @@ class HandlerContext: ensure_runtime: object episode_list: object export_watchlist_backup: object + list_watchlist_backups: object + create_watchlist_backup: object + download_watchlist_backup: object + restore_watchlist_backup: object + list_watchlist_categories: object + manage_watchlist_category: object get_config_snapshot: object get_jellyfin_sync_status: object get_provider_update_status: object @@ -779,6 +785,18 @@ class Handler(BaseHTTPRequestHandler): Handler._context(self).export_watchlist_backup(), "kaizoku-watchlist-backup.json", ) + elif parsed.path == "/api/config/watchlist/backups": + self.json(Handler._context(self).list_watchlist_backups()) + elif parsed.path == "/api/config/watchlist/backups/download": + name = (parse_qs(parsed.query).get("name") or [""])[0] + data = Handler._context(self).download_watchlist_backup(name) + self.write_response_bytes(data, HTTPStatus.OK, { + "Content-Type": "application/zip", + "Content-Disposition": f'attachment; filename="{name}"', + "Cache-Control": "no-store", + }) + elif parsed.path == "/api/config/watchlist/categories": + self.json({"categories": Handler._context(self).list_watchlist_categories()}) else: self.error(HTTPStatus.NOT_FOUND, "Not found") except Exception as exc: @@ -875,6 +893,14 @@ class Handler(BaseHTTPRequestHandler): elif parsed.path == "/api/config/watchlist/import": payload = Handler.require_json_object(self, self.body_json()) self.json(Handler._context(self).import_watchlist_backup(payload)) + elif parsed.path == "/api/config/watchlist/backups/create": + self.json(Handler._context(self).create_watchlist_backup()) + elif parsed.path == "/api/config/watchlist/backups/restore": + payload = Handler.require_fields(self, self.body_json(), "name") + self.json(Handler._context(self).restore_watchlist_backup(payload["name"])) + elif parsed.path == "/api/config/watchlist/categories": + payload = Handler.require_fields(self, self.body_json(), "action") + self.json(Handler._context(self).manage_watchlist_category(payload["action"], payload)) elif parsed.path == "/api/config/webhook/test": payload = Handler.require_json_object(self, self.body_json()) validate_discord_webhook_url(payload.get("discord_webhook_url")) diff --git a/search_page.py b/search_page.py index 4a90b20..db238c5 100644 --- a/search_page.py +++ b/search_page.py @@ -852,6 +852,17 @@ INDEX_HTML = r""" async function loadConfig() { state.config = await api("/api/config"); + try { + const categories = await api("/api/config/watchlist/categories"); + const select = $("trackCategory"); + select.replaceChildren(); + for (const entry of categories.categories || []) { + const option = document.createElement("option"); + option.value = entry.category; + option.textContent = entry.label; + select.append(option); + } + } catch (error) { setNotice(error.message); } $("jobFolder").value = state.config.download_dir; $("searchProvider").value = state.config.provider || "anikoto"; state.config.mode = state.config.mode === "dub" ? "dub" : "sub"; diff --git a/test_app.py b/test_app.py index a92786d..e789c08 100644 --- a/test_app.py +++ b/test_app.py @@ -12,6 +12,7 @@ import sys import tempfile import threading import unittest +import zipfile import urllib.error from http import HTTPStatus from pathlib import Path @@ -36,6 +37,7 @@ import provider_bridge import provider_downloader import provider_updates import template_helpers +from watchlist_backup import WatchlistBackupScheduler SPEC = importlib.util.spec_from_file_location("kaizoku_app", MODULE_PATH) APP = importlib.util.module_from_spec(SPEC) @@ -3295,6 +3297,8 @@ class WatchlistBackupTests(unittest.TestCase): with APP.WATCHLIST._connect() as conn: conn.execute("DELETE FROM watchlist") conn.execute("DELETE FROM watchlist_removals") + conn.execute("DELETE FROM watchlist_categories WHERE fixed = 0") + APP.WATCHLIST._load_categories() def seed_watchlist_item(self, **overrides): now = APP.now_iso() @@ -3345,7 +3349,8 @@ class WatchlistBackupTests(unittest.TestCase): backup = APP.export_watchlist_backup() self.assertEqual(backup["format"], "kaizoku-watchlist-backup") - self.assertEqual(backup["format_version"], 1) + self.assertEqual(backup["format_version"], 2) + self.assertEqual(len(backup["tables"]["watchlist_categories"]["rows"]), 4) self.assertEqual(backup["tables"]["watchlist"]["rows"][0]["show_id"], "show-backup-1") self.assertEqual(backup["tables"]["watchlist"]["rows"][0]["downloaded_dub_episodes_json"], APP.encode_episode_values(["1", "2"])) self.assertEqual(backup["tables"]["watchlist_removals"]["rows"][0]["show_id"], "removed-show") @@ -3375,6 +3380,42 @@ class WatchlistBackupTests(unittest.TestCase): with self.assertRaises(ValueError): APP.import_watchlist_backup({"format": "not-this-app", "format_version": 1, "tables": {}}) + def test_custom_categories_survive_backup_and_deletion_keeps_entries(self): + category = APP.WATCHLIST.create_category("Favorites")["category"] + self.seed_watchlist_item(category=category) + self.assertEqual(APP.WATCHLIST.get("show-backup-1")["category_label"], "Favorites") + listing = APP.WATCHLIST.list(category=category) + self.assertEqual(listing["total"], 1) + self.assertEqual(listing["categories"][category], 1) + self.assertIn(category, [entry["category"] for entry in listing["category_definitions"]]) + APP.WATCHLIST.rename_category(category, "Keepers") + snapshot = APP.export_watchlist_backup() + APP.WATCHLIST.delete_category(category) + self.assertEqual(APP.WATCHLIST.get("show-backup-1")["category"], "planned") + APP.import_watchlist_backup(snapshot) + self.assertEqual(APP.WATCHLIST.get("show-backup-1")["category_label"], "Keepers") + with self.assertRaises(ValueError): + APP.WATCHLIST.delete_category("watching") + + def test_scheduled_zip_backup_retention_and_restore(self): + self.seed_watchlist_item() + with tempfile.TemporaryDirectory() as directory: + scheduler = WatchlistBackupScheduler(APP.export_watchlist_backup, APP.import_watchlist_backup, + lambda: {"watchlist_backup_keep": 2}, backup_dir=directory, start_worker=False) + names = [] + for _ in range(3): + names.append(scheduler.create()["name"]) + self.assertEqual(len(scheduler.list()["backups"]), 2) + self.assertNotIn(names[0], [item["name"] for item in scheduler.list()["backups"]]) + with zipfile.ZipFile(Path(directory) / names[2]) as archive: + self.assertEqual(archive.namelist(), ["watchlist.json"]) + with APP.WATCHLIST._connect() as conn: + conn.execute("DELETE FROM watchlist") + scheduler.restore(names[2]) + self.assertEqual(APP.WATCHLIST.get("show-backup-1")["title"], "Backup Show") + with self.assertRaises(ValueError): + scheduler.download("../watchlist.json") + class WatchlistQueuedRefreshRecoveryTests(unittest.TestCase): def setUp(self): @@ -5233,7 +5274,7 @@ class TemplateHelperTests(unittest.TestCase): self.assertIn("mkdir -p /downloads /jellyfin/tv /jellyfin/movies /app/.kaizoku", dockerfile) self.assertIn("chown_path()", entrypoint) self.assertIn("Warning: could not change ownership", entrypoint) - self.assertIn("for path in /downloads /jellyfin/tv /jellyfin/movies /app/.kaizoku /app/.kaizoku/home", entrypoint) + self.assertIn("for path in /downloads /jellyfin/tv /jellyfin/movies /backup /app/.kaizoku /app/.kaizoku/home", entrypoint) def test_active_code_does_not_reference_retired_metadata_source(self): active_files = ("app.py", "app_support.py", "http_handler.py", "provider_bridge.py", "provider_downloader.py") diff --git a/watchlist_backup.py b/watchlist_backup.py new file mode 100644 index 0000000..9dfae22 --- /dev/null +++ b/watchlist_backup.py @@ -0,0 +1,123 @@ +"""Scheduled, downloadable ZIP snapshots of the watchlist database export.""" + +import io +import json +import os +import re +import tempfile +import threading +import time +import zipfile +from datetime import datetime, timezone +from pathlib import Path + + +BACKUP_NAME = re.compile(r"^kaizoku-watchlist-\d{8}T\d{6}Z(?:-\d+)?\.zip$") +ARCHIVE_MEMBER = "watchlist.json" + + +class WatchlistBackupScheduler: + def __init__(self, export_fn, import_fn, config_getter, backup_dir=None, start_worker=True): + self.export_fn = export_fn + self.import_fn = import_fn + self.config_getter = config_getter + self.backup_dir = Path(backup_dir or os.environ.get("KAIZOKU_BACKUP_DIR") or (Path(__file__).resolve().parent / "backup")) + self.lock = threading.RLock() + self.wakeup = threading.Event() + self.stop_event = threading.Event() + self.worker = None + self.worker_enabled = bool(start_worker) + self.last_error = "" + if start_worker: + self.ensure_worker() + + def ensure_worker(self): + if not self.worker_enabled: + return + with self.lock: + if self.worker and self.worker.is_alive(): + return + self.stop_event.clear() + self.worker = threading.Thread(target=self._loop, name="watchlist-backup", daemon=True) + self.worker.start() + + def shutdown(self, wait=False): + self.stop_event.set() + self.wakeup.set() + if wait and self.worker and self.worker.is_alive(): + self.worker.join(timeout=10) + return not (self.worker and self.worker.is_alive()) + + def notify_config_changed(self): + self.wakeup.set() + + def _paths(self): + if not self.backup_dir.exists(): + return [] + return sorted((path for path in self.backup_dir.iterdir() if path.is_file() and BACKUP_NAME.fullmatch(path.name)), key=lambda path: (path.stat().st_mtime, path.name), reverse=True) + + def list(self): + with self.lock: + return {"backups": [{"name": path.name, "size": path.stat().st_size, "created_at": datetime.fromtimestamp(path.stat().st_mtime, timezone.utc).isoformat()} for path in self._paths()], "directory": str(self.backup_dir), "error": self.last_error} + + def _path(self, name): + if not isinstance(name, str) or not BACKUP_NAME.fullmatch(name): + raise ValueError("Invalid backup filename.") + path = self.backup_dir / name + if not path.is_file() or path.is_symlink(): + raise ValueError("Backup not found.") + return path + + def download(self, name): + with self.lock: + return self._path(name).read_bytes() + + def create(self): + with self.lock: + self.backup_dir.mkdir(parents=True, exist_ok=True) + snapshot = self.export_fn() + stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ") + name = f"kaizoku-watchlist-{stamp}.zip" + counter = 1 + while (self.backup_dir / name).exists(): + name = f"kaizoku-watchlist-{stamp}-{counter}.zip" + counter += 1 + descriptor, temporary = tempfile.mkstemp(prefix=".watchlist-", suffix=".tmp", dir=self.backup_dir) + try: + with os.fdopen(descriptor, "wb") as output: + with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_DEFLATED) as archive: + archive.writestr(ARCHIVE_MEMBER, json.dumps(snapshot, indent=2, sort_keys=True)) + os.replace(temporary, self.backup_dir / name) + finally: + if os.path.exists(temporary): + os.unlink(temporary) + keep = int(self.config_getter().get("watchlist_backup_keep", 14)) + for stale in self._paths()[max(1, keep):]: + stale.unlink() + self.last_error = "" + return {"name": name, "message": "Watchlist backup created."} + + def restore(self, name): + with self.lock: + payload = self._path(name).read_bytes() + with zipfile.ZipFile(io.BytesIO(payload)) as archive: + members = archive.infolist() + if len(members) != 1 or members[0].filename != ARCHIVE_MEMBER or members[0].file_size > 50_000_000: + raise ValueError("Backup archive must contain one watchlist.json file under 50 MB.") + snapshot = json.loads(archive.read(ARCHIVE_MEMBER)) + return self.import_fn(snapshot) + + def _loop(self): + while not self.stop_event.is_set(): + config = self.config_getter() + if config.get("watchlist_backup_enabled", True): + try: + with self.lock: + paths = self._paths() + due = not paths or time.time() - paths[0].stat().st_mtime >= int(config.get("watchlist_backup_minutes", 1440)) * 60 + if due: + self.create() + except Exception as exc: + self.last_error = str(exc) + self.wakeup.wait(timeout=60) + self.wakeup.clear() diff --git a/watchlist_page.py b/watchlist_page.py index 1c1e2e7..2dc528d 100644 --- a/watchlist_page.py +++ b/watchlist_page.py @@ -1009,7 +1009,8 @@ WATCHLIST_HTML = r""" function categoryOptions(selected) { return Object.entries(categoryLabels) - .map(([value, label]) => ``) + .filter(([value]) => value !== "all") + .map(([value, label]) => ``) .join(""); } @@ -1388,6 +1389,8 @@ WATCHLIST_HTML = r""" } function renderWatchlist(data) { + for (const key of Object.keys(categoryLabels)) if (key.startsWith("custom-")) delete categoryLabels[key]; + for (const entry of data.category_definitions || []) categoryLabels[entry.category] = entry.label; const items = data.items || []; state.watchlistPage = data.page || 1; state.watchlistPages = data.pages || 1;