Add watchlist source name override for ani-cli queries

This commit is contained in:
Dymas
2026-06-13 16:52:11 +02:00
parent ef00ff20a9
commit 6403c98b7d
7 changed files with 70 additions and 21 deletions
+35 -9
View File
@@ -1338,10 +1338,12 @@ class WatchlistStore:
def _auto_download_defaults(self, title):
config = self.config_getter() or {}
normalized_title = str(title or "").strip() or "Anime"
return {
"auto_download_mode": str(config.get("auto_download_mode") or "dub").strip().lower() or "dub",
"auto_download_quality": str(config.get("auto_download_quality") or "best").strip().lower() or "best",
"auto_download_name": sanitize_path_component(title, "Anime"),
"auto_download_name": sanitize_path_component(normalized_title, "Anime"),
"auto_download_source_name": normalized_title,
"auto_download_series": "1",
"auto_download_offset": None,
"media_type": "tv",
@@ -1422,6 +1424,7 @@ class WatchlistStore:
auto_download_mode TEXT,
auto_download_quality TEXT,
auto_download_name TEXT,
auto_download_source_name TEXT,
auto_download_series TEXT,
auto_download_offset TEXT,
downloaded_sub_episodes_json TEXT,
@@ -1468,6 +1471,8 @@ class WatchlistStore:
conn.execute("ALTER TABLE watchlist ADD COLUMN auto_download_quality TEXT")
if "auto_download_name" not in columns:
conn.execute("ALTER TABLE watchlist ADD COLUMN auto_download_name TEXT")
if "auto_download_source_name" not in columns:
conn.execute("ALTER TABLE watchlist ADD COLUMN auto_download_source_name TEXT")
if "auto_download_series" not in columns:
conn.execute("ALTER TABLE watchlist ADD COLUMN auto_download_series TEXT")
if "auto_download_offset" not in columns:
@@ -1548,6 +1553,7 @@ class WatchlistStore:
item["auto_download_mode"] = mode if mode in MODE_CHOICES else defaults["auto_download_mode"]
item["auto_download_quality"] = quality if quality in QUALITY_CHOICES else defaults["auto_download_quality"]
item["auto_download_name"] = sanitize_path_component(item.get("auto_download_name") or defaults["auto_download_name"], defaults["auto_download_name"])
item["auto_download_source_name"] = str(item.get("auto_download_source_name") or defaults["auto_download_source_name"]).strip() or defaults["auto_download_source_name"]
item["auto_download_series"] = normalize_season(item.get("auto_download_series") or defaults["auto_download_series"])
item["auto_download_offset"] = normalize_episode_offset(item.get("auto_download_offset"))
item["downloaded_sub_episodes"] = decode_episode_values(item.get("downloaded_sub_episodes_json"))
@@ -1574,10 +1580,10 @@ class WatchlistStore:
animeschedule_route, animeschedule_title,
anilist_id, anilist_title, anilist_site_url, alternative_titles_json,
anidb_aid, anidb_title, media_type,
auto_download_mode, auto_download_quality, auto_download_name, auto_download_series, auto_download_offset,
auto_download_mode, auto_download_quality, auto_download_name, auto_download_source_name, auto_download_series, auto_download_offset,
downloaded_sub_episodes_json, downloaded_dub_episodes_json,
thumbnail_path, thumbnail_checked_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(show_id) DO UPDATE SET
title = excluded.title,
category = excluded.category,
@@ -1604,6 +1610,7 @@ class WatchlistStore:
auto_download_mode = excluded.auto_download_mode,
auto_download_quality = excluded.auto_download_quality,
auto_download_name = excluded.auto_download_name,
auto_download_source_name = excluded.auto_download_source_name,
auto_download_series = excluded.auto_download_series,
auto_download_offset = excluded.auto_download_offset,
downloaded_sub_episodes_json = excluded.downloaded_sub_episodes_json,
@@ -1639,6 +1646,7 @@ class WatchlistStore:
item.get("auto_download_mode"),
item.get("auto_download_quality"),
item.get("auto_download_name"),
str(item.get("auto_download_source_name") or "").strip() or str(item["title"]).strip(),
item.get("auto_download_series"),
normalize_episode_offset(item.get("auto_download_offset")),
item.get("downloaded_sub_episodes_json"),
@@ -1696,6 +1704,7 @@ class WatchlistStore:
"auto_download_mode": None,
"auto_download_quality": None,
"auto_download_name": None,
"auto_download_source_name": None,
"auto_download_series": None,
"auto_download_offset": None,
"downloaded_sub_episodes_json": None,
@@ -1867,6 +1876,9 @@ class WatchlistStore:
}
item["auto_download_series"] = normalize_season(payload.get("auto_download_series") or item.get("auto_download_series") or "1")
item["auto_download_offset"] = normalize_episode_offset(payload.get("auto_download_offset"))
item["auto_download_source_name"] = (
str(payload.get("auto_download_source_name") or item.get("auto_download_source_name") or title).strip() or title
)
self._upsert_conn(conn, item)
self._clear_removal_conn(conn, show_id)
@@ -2196,6 +2208,7 @@ class WatchlistStore:
"anidb_aid": None,
"anidb_title": None,
"media_type": normalized_media_type,
"auto_download_source_name": None,
"auto_download_series": None,
"downloaded_sub_episodes_json": encode_episode_values(downloaded_episode_values) if normalized_mode == "sub" else None,
"downloaded_dub_episodes_json": encode_episode_values(downloaded_episode_values) if normalized_mode == "dub" else None,
@@ -2206,7 +2219,7 @@ class WatchlistStore:
self.schedule_refresh(normalized_show_id, source="sync")
return self.get(normalized_show_id)
def update_auto_download_settings(self, show_id, mode=None, quality=None, name=None, series=None, episode_offset=None):
def update_auto_download_settings(self, show_id, mode=None, quality=None, name=None, source_name=None, series=None, episode_offset=None):
existing = self.get(show_id)
defaults = self._auto_download_defaults(existing["title"])
normalized_mode = str(mode or defaults["auto_download_mode"]).strip().lower()
@@ -2216,6 +2229,9 @@ class WatchlistStore:
if normalized_quality not in QUALITY_CHOICES:
raise ValueError("Unknown auto-download quality.")
normalized_name = sanitize_path_component(name or defaults["auto_download_name"], defaults["auto_download_name"])
normalized_source_name = str(source_name or existing.get("auto_download_source_name") or defaults["auto_download_source_name"]).strip()
if not normalized_source_name:
normalized_source_name = defaults["auto_download_source_name"]
normalized_series = normalize_season(series or existing.get("auto_download_series") or defaults["auto_download_series"])
normalized_offset = (
normalize_episode_offset(existing.get("auto_download_offset"))
@@ -2226,10 +2242,19 @@ class WatchlistStore:
conn.execute(
"""
UPDATE watchlist
SET auto_download_mode = ?, auto_download_quality = ?, auto_download_name = ?, auto_download_series = ?, auto_download_offset = ?, updated_at = ?
SET auto_download_mode = ?, auto_download_quality = ?, auto_download_name = ?, auto_download_source_name = ?, auto_download_series = ?, auto_download_offset = ?, updated_at = ?
WHERE show_id = ?
""",
(normalized_mode, normalized_quality, normalized_name, normalized_series, normalized_offset, now_iso(), existing["show_id"]),
(
normalized_mode,
normalized_quality,
normalized_name,
normalized_source_name,
normalized_series,
normalized_offset,
now_iso(),
existing["show_id"],
),
)
return self.get(show_id)
@@ -2442,7 +2467,7 @@ def download_watchlist_item(show_id, mode):
if normalized_mode not in MODE_CHOICES:
raise ValueError("Mode must be sub or dub")
query = str(item.get("title") or item.get("show_id") or "").strip()
query = str(item.get("auto_download_source_name") or item.get("title") or item.get("show_id") or "").strip()
if not query:
raise ValueError("Watchlist item is missing a searchable title.")
@@ -2502,7 +2527,7 @@ def queue_watchlist_auto_download(item, refresh_source="manual"):
if not specs:
return {"queued": False, "reason": "nothing_missing"}
query = str(item.get("title") or item.get("show_id") or "").strip()
query = str(item.get("auto_download_source_name") or item.get("title") or item.get("show_id") or "").strip()
if not query:
return {"queued": False, "reason": "missing_title"}
@@ -2619,13 +2644,14 @@ def update_watchlist_media_type(show_id, media_type):
return {"message": f"Saved {item['title']} as {item['media_type_label']}.", "item": item}
def update_watchlist_auto_download(show_id, mode=None, quality=None, name=None, series=None, episode_offset=None):
def update_watchlist_auto_download(show_id, mode=None, quality=None, name=None, source_name=None, series=None, episode_offset=None):
ensure_runtime()
item = WATCHLIST.update_auto_download_settings(
show_id,
mode=mode,
quality=quality,
name=name,
source_name=source_name,
series=series,
episode_offset=episode_offset,
)