Improve auto-download title and series controls
This commit is contained in:
@@ -52,6 +52,7 @@ from app_support import (
|
||||
debug_log,
|
||||
load_json,
|
||||
migrate_legacy_state_storage,
|
||||
normalize_season,
|
||||
normalize_config,
|
||||
now_iso,
|
||||
sanitize_path_component,
|
||||
@@ -1060,6 +1061,7 @@ class WatchlistStore:
|
||||
"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_series": "1",
|
||||
}
|
||||
|
||||
def _connect(self):
|
||||
@@ -1136,6 +1138,7 @@ class WatchlistStore:
|
||||
auto_download_mode TEXT,
|
||||
auto_download_quality TEXT,
|
||||
auto_download_name TEXT,
|
||||
auto_download_series TEXT,
|
||||
thumbnail_path TEXT,
|
||||
thumbnail_checked_at TEXT
|
||||
)
|
||||
@@ -1176,6 +1179,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_series" not in columns:
|
||||
conn.execute("ALTER TABLE watchlist ADD COLUMN auto_download_series TEXT")
|
||||
conn.execute(
|
||||
"UPDATE watchlist SET category = 'watching' WHERE category IS NULL OR TRIM(category) = ''"
|
||||
)
|
||||
@@ -1212,6 +1217,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_series"] = normalize_season(item.get("auto_download_series") or defaults["auto_download_series"])
|
||||
if item.get("animeschedule_route"):
|
||||
title = str(item.get("animeschedule_title") or item.get("title") or "").strip() or "unknown title"
|
||||
item["thumbnail_debug"] = f"AnimeSchedule: {item['animeschedule_route']} - {title}"
|
||||
@@ -1234,9 +1240,9 @@ class WatchlistStore:
|
||||
animeschedule_route, animeschedule_title,
|
||||
anilist_id, anilist_title, anilist_site_url, alternative_titles_json,
|
||||
anidb_aid, anidb_title,
|
||||
auto_download_mode, auto_download_quality, auto_download_name,
|
||||
auto_download_mode, auto_download_quality, auto_download_name, auto_download_series,
|
||||
thumbnail_path, thumbnail_checked_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(show_id) DO UPDATE SET
|
||||
title = excluded.title,
|
||||
category = excluded.category,
|
||||
@@ -1262,6 +1268,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_series = excluded.auto_download_series,
|
||||
thumbnail_path = excluded.thumbnail_path,
|
||||
thumbnail_checked_at = excluded.thumbnail_checked_at
|
||||
""",
|
||||
@@ -1292,6 +1299,7 @@ class WatchlistStore:
|
||||
item.get("auto_download_mode"),
|
||||
item.get("auto_download_quality"),
|
||||
item.get("auto_download_name"),
|
||||
item.get("auto_download_series"),
|
||||
item.get("thumbnail_path"),
|
||||
item.get("thumbnail_checked_at"),
|
||||
),
|
||||
@@ -1344,6 +1352,7 @@ class WatchlistStore:
|
||||
"auto_download_mode": None,
|
||||
"auto_download_quality": None,
|
||||
"auto_download_name": None,
|
||||
"auto_download_series": None,
|
||||
"thumbnail_path": None,
|
||||
"thumbnail_checked_at": None,
|
||||
},
|
||||
@@ -1741,6 +1750,7 @@ class WatchlistStore:
|
||||
"alternative_titles_json": None,
|
||||
"anidb_aid": None,
|
||||
"anidb_title": None,
|
||||
"auto_download_series": None,
|
||||
"thumbnail_path": None,
|
||||
"thumbnail_checked_at": None,
|
||||
}
|
||||
@@ -1748,7 +1758,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):
|
||||
def update_auto_download_settings(self, show_id, mode=None, quality=None, name=None, series=None):
|
||||
existing = self.get(show_id)
|
||||
defaults = self._auto_download_defaults(existing["title"])
|
||||
normalized_mode = str(mode or defaults["auto_download_mode"]).strip().lower()
|
||||
@@ -1758,14 +1768,15 @@ 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_series = normalize_season(series or existing.get("auto_download_series") or defaults["auto_download_series"])
|
||||
with self.lock, self._connect() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE watchlist
|
||||
SET auto_download_mode = ?, auto_download_quality = ?, auto_download_name = ?, updated_at = ?
|
||||
SET auto_download_mode = ?, auto_download_quality = ?, auto_download_name = ?, auto_download_series = ?, updated_at = ?
|
||||
WHERE show_id = ?
|
||||
""",
|
||||
(normalized_mode, normalized_quality, normalized_name, now_iso(), existing["show_id"]),
|
||||
(normalized_mode, normalized_quality, normalized_name, normalized_series, now_iso(), existing["show_id"]),
|
||||
)
|
||||
return self.get(show_id)
|
||||
|
||||
@@ -2051,6 +2062,7 @@ def queue_watchlist_auto_download(item, refresh_source="manual"):
|
||||
item.get("auto_download_name") or item.get("title") or match.get("title") or "Anime",
|
||||
sanitize_path_component(item.get("title") or match.get("title") or "Anime", "Anime"),
|
||||
)
|
||||
series = normalize_season(item.get("auto_download_series") or "1")
|
||||
jobs = []
|
||||
for episode_spec in specs:
|
||||
job = runtime["download_queue"].add(
|
||||
@@ -2059,7 +2071,7 @@ def queue_watchlist_auto_download(item, refresh_source="manual"):
|
||||
"query": match.get("query") or query,
|
||||
"title": match.get("title") or item["title"],
|
||||
"anime_name": anime_name,
|
||||
"season": "1",
|
||||
"season": series,
|
||||
"index": match.get("index", 1),
|
||||
"mode": mode,
|
||||
"quality": quality,
|
||||
@@ -2077,9 +2089,9 @@ def update_watchlist_category(show_id, category):
|
||||
return {"message": f"Moved {item['title']} to {item['category_label']}.", "item": item}
|
||||
|
||||
|
||||
def update_watchlist_auto_download(show_id, mode=None, quality=None, name=None):
|
||||
def update_watchlist_auto_download(show_id, mode=None, quality=None, name=None, series=None):
|
||||
ensure_runtime()
|
||||
item = WATCHLIST.update_auto_download_settings(show_id, mode=mode, quality=quality, name=name)
|
||||
item = WATCHLIST.update_auto_download_settings(show_id, mode=mode, quality=quality, name=name, series=series)
|
||||
return {"message": f"Saved auto-download settings for {item['title']}.", "item": item}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user