Add TV and movie watchlist download tags
This commit is contained in:
@@ -54,6 +54,7 @@ from app_support import (
|
||||
migrate_legacy_state_storage,
|
||||
normalize_season,
|
||||
normalize_config,
|
||||
normalize_media_type,
|
||||
now_iso,
|
||||
sanitize_path_component,
|
||||
thumbnail_file_path,
|
||||
@@ -323,6 +324,10 @@ def watchlist_category_label(value):
|
||||
return WATCHLIST_CATEGORY_LABELS[normalize_watchlist_category(value)]
|
||||
|
||||
|
||||
def media_type_label(value):
|
||||
return "Movie" if normalize_media_type(value) == "movie" else "TV"
|
||||
|
||||
|
||||
def normalize_animeschedule_entry(node):
|
||||
if not isinstance(node, dict):
|
||||
return None
|
||||
@@ -1117,6 +1122,7 @@ class WatchlistStore:
|
||||
"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",
|
||||
"media_type": "tv",
|
||||
}
|
||||
|
||||
def _connect(self):
|
||||
@@ -1190,6 +1196,7 @@ class WatchlistStore:
|
||||
alternative_titles_json TEXT,
|
||||
anidb_aid TEXT,
|
||||
anidb_title TEXT,
|
||||
media_type TEXT NOT NULL DEFAULT 'tv',
|
||||
auto_download_mode TEXT,
|
||||
auto_download_quality TEXT,
|
||||
auto_download_name TEXT,
|
||||
@@ -1218,6 +1225,8 @@ class WatchlistStore:
|
||||
conn.execute("ALTER TABLE watchlist ADD COLUMN anidb_aid TEXT")
|
||||
if "anidb_title" not in columns:
|
||||
conn.execute("ALTER TABLE watchlist ADD COLUMN anidb_title TEXT")
|
||||
if "media_type" not in columns:
|
||||
conn.execute("ALTER TABLE watchlist ADD COLUMN media_type TEXT NOT NULL DEFAULT 'tv'")
|
||||
if "animeschedule_route" not in columns:
|
||||
conn.execute("ALTER TABLE watchlist ADD COLUMN animeschedule_route TEXT")
|
||||
if "animeschedule_title" not in columns:
|
||||
@@ -1245,6 +1254,9 @@ class WatchlistStore:
|
||||
conn.execute(
|
||||
"UPDATE watchlist SET category = 'watching' WHERE category IS NULL OR TRIM(category) = ''"
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE watchlist SET media_type = 'tv' WHERE media_type IS NULL OR TRIM(media_type) = ''"
|
||||
)
|
||||
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)")
|
||||
@@ -1254,6 +1266,8 @@ class WatchlistStore:
|
||||
defaults = self._auto_download_defaults(item.get("title"))
|
||||
item["category"] = normalize_watchlist_category(item.get("category"))
|
||||
item["category_label"] = 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))
|
||||
item["sub_count"] = int(item.get("sub_count") or 0)
|
||||
item["dub_count"] = int(item.get("dub_count") or 0)
|
||||
@@ -1302,11 +1316,11 @@ class WatchlistStore:
|
||||
sub_latest_episode, dub_latest_episode,
|
||||
animeschedule_route, animeschedule_title,
|
||||
anilist_id, anilist_title, anilist_site_url, alternative_titles_json,
|
||||
anidb_aid, anidb_title,
|
||||
anidb_aid, anidb_title, media_type,
|
||||
auto_download_mode, auto_download_quality, auto_download_name, auto_download_series,
|
||||
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,
|
||||
@@ -1329,6 +1343,7 @@ class WatchlistStore:
|
||||
alternative_titles_json = excluded.alternative_titles_json,
|
||||
anidb_aid = excluded.anidb_aid,
|
||||
anidb_title = excluded.anidb_title,
|
||||
media_type = excluded.media_type,
|
||||
auto_download_mode = excluded.auto_download_mode,
|
||||
auto_download_quality = excluded.auto_download_quality,
|
||||
auto_download_name = excluded.auto_download_name,
|
||||
@@ -1362,6 +1377,7 @@ class WatchlistStore:
|
||||
item.get("alternative_titles_json"),
|
||||
item.get("anidb_aid"),
|
||||
item.get("anidb_title"),
|
||||
normalize_media_type(item.get("media_type")),
|
||||
item.get("auto_download_mode"),
|
||||
item.get("auto_download_quality"),
|
||||
item.get("auto_download_name"),
|
||||
@@ -1417,6 +1433,7 @@ class WatchlistStore:
|
||||
"alternative_titles_json": None,
|
||||
"anidb_aid": None,
|
||||
"anidb_title": None,
|
||||
"media_type": "tv",
|
||||
"auto_download_mode": None,
|
||||
"auto_download_quality": None,
|
||||
"auto_download_name": None,
|
||||
@@ -1553,6 +1570,7 @@ class WatchlistStore:
|
||||
"alternative_titles_json": None,
|
||||
"anidb_aid": None,
|
||||
"anidb_title": None,
|
||||
"media_type": normalize_media_type(payload.get("media_type")),
|
||||
"thumbnail_path": None,
|
||||
"thumbnail_checked_at": None,
|
||||
"downloaded_sub_episodes_json": None,
|
||||
@@ -1738,6 +1756,16 @@ class WatchlistStore:
|
||||
)
|
||||
return self.get(show_id)
|
||||
|
||||
def update_media_type(self, show_id, media_type):
|
||||
existing = self.get(show_id)
|
||||
normalized_media_type = normalize_media_type(media_type)
|
||||
with self.lock, self._connect() as conn:
|
||||
conn.execute(
|
||||
"UPDATE watchlist SET media_type = ?, updated_at = ? WHERE show_id = ?",
|
||||
(normalized_media_type, now_iso(), existing["show_id"]),
|
||||
)
|
||||
return self.get(show_id)
|
||||
|
||||
def queue_refresh(self, show_id, status_message="Queued watchlist refresh.", source="manual"):
|
||||
existing = self.get(show_id)
|
||||
now = now_iso()
|
||||
@@ -1851,6 +1879,7 @@ class WatchlistStore:
|
||||
"alternative_titles_json": None,
|
||||
"anidb_aid": None,
|
||||
"anidb_title": None,
|
||||
"media_type": "tv",
|
||||
"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,
|
||||
@@ -2104,8 +2133,9 @@ def download_watchlist_item(show_id, mode):
|
||||
"show_id": item["show_id"],
|
||||
"query": match.get("query") or query,
|
||||
"title": match.get("title") or item["title"],
|
||||
"anime_name": item["title"],
|
||||
"season": "1",
|
||||
"anime_name": item.get("auto_download_name") or item["title"],
|
||||
"media_type": item.get("media_type") or "tv",
|
||||
"season": item.get("auto_download_series") or "1",
|
||||
"index": match.get("index", 1),
|
||||
"mode": normalized_mode,
|
||||
"quality": runtime["config"]["quality"],
|
||||
@@ -2171,6 +2201,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,
|
||||
"media_type": item.get("media_type") or "tv",
|
||||
"season": series,
|
||||
"index": match.get("index", 1),
|
||||
"mode": mode,
|
||||
@@ -2189,6 +2220,12 @@ def update_watchlist_category(show_id, category):
|
||||
return {"message": f"Moved {item['title']} to {item['category_label']}.", "item": item}
|
||||
|
||||
|
||||
def update_watchlist_media_type(show_id, media_type):
|
||||
ensure_runtime()
|
||||
item = WATCHLIST.update_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):
|
||||
ensure_runtime()
|
||||
item = WATCHLIST.update_auto_download_settings(show_id, mode=mode, quality=quality, name=name, series=series)
|
||||
@@ -2440,6 +2477,7 @@ Handler = build_handler_class(
|
||||
update_all_watchlist_statuses=update_all_watchlist_statuses,
|
||||
update_watchlist_auto_download=update_watchlist_auto_download,
|
||||
update_watchlist_category=update_watchlist_category,
|
||||
update_watchlist_media_type=update_watchlist_media_type,
|
||||
update_watchlist_status=update_watchlist_status,
|
||||
upload_watchlist_thumbnail=upload_watchlist_thumbnail,
|
||||
watchlist_html=WATCHLIST_HTML,
|
||||
|
||||
Reference in New Issue
Block a user