Keep removed watchlist shows from reappearing
This commit is contained in:
@@ -1431,6 +1431,37 @@ 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_removals (
|
||||
show_id TEXT PRIMARY KEY,
|
||||
title TEXT,
|
||||
removed_at TEXT NOT NULL
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
def _remember_removal_conn(self, conn, show_id, title):
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO watchlist_removals (show_id, title, removed_at)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT(show_id) DO UPDATE SET
|
||||
title = excluded.title,
|
||||
removed_at = excluded.removed_at
|
||||
""",
|
||||
(str(show_id or "").strip(), str(title or "").strip(), now_iso()),
|
||||
)
|
||||
|
||||
def _clear_removal_conn(self, conn, show_id):
|
||||
conn.execute("DELETE FROM watchlist_removals WHERE show_id = ?", (str(show_id or "").strip(),))
|
||||
|
||||
def _was_removed_conn(self, conn, show_id):
|
||||
row = conn.execute(
|
||||
"SELECT 1 FROM watchlist_removals WHERE show_id = ? LIMIT 1",
|
||||
(str(show_id or "").strip(),),
|
||||
).fetchone()
|
||||
return row is not None
|
||||
|
||||
def _row_to_item(self, row):
|
||||
item = dict(row)
|
||||
@@ -1766,6 +1797,7 @@ 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"))
|
||||
self._upsert_conn(conn, item)
|
||||
self._clear_removal_conn(conn, show_id)
|
||||
|
||||
queued = self.schedule_refresh(show_id, source="initial")
|
||||
return {"message": f"Added {queued['title']} to the watchlist. Refresh queued.", "item": queued, "created": True}
|
||||
@@ -2010,6 +2042,8 @@ class WatchlistStore:
|
||||
(target_category, "Queued refresh after successful download.", now, sub_payload, dub_payload, normalized_show_id),
|
||||
)
|
||||
else:
|
||||
if self._was_removed_conn(conn, normalized_show_id):
|
||||
return None
|
||||
matched_row = self._find_download_title_match_conn(conn, normalized_title, exclude_show_id=normalized_show_id)
|
||||
if matched_row is not None:
|
||||
matched_item = self._row_to_item(matched_row)
|
||||
@@ -2128,6 +2162,7 @@ class WatchlistStore:
|
||||
cursor = conn.execute("DELETE FROM watchlist WHERE show_id = ?", (str(show_id).strip(),))
|
||||
if cursor.rowcount < 1:
|
||||
raise KeyError("Anime not found in watchlist.")
|
||||
self._remember_removal_conn(conn, existing["show_id"], existing["title"])
|
||||
event = self.thumbnail_events.pop(str(show_id).strip(), None)
|
||||
if event is not None:
|
||||
event.set()
|
||||
@@ -2342,7 +2377,9 @@ def download_watchlist_item(show_id, mode):
|
||||
"season": item.get("auto_download_series") or "1",
|
||||
"episode_offset": item.get("auto_download_offset"),
|
||||
"mode": normalized_mode,
|
||||
"quality": runtime["config"]["quality"],
|
||||
"quality": item.get("auto_download_quality")
|
||||
or runtime["config"].get("auto_download_quality")
|
||||
or runtime["config"]["quality"],
|
||||
"episodes": episode_spec,
|
||||
"download_dir": runtime["config"]["download_dir"],
|
||||
}
|
||||
@@ -2525,8 +2562,10 @@ def get_watchlist_refresh_status():
|
||||
|
||||
|
||||
def remove_from_watchlist(show_id):
|
||||
ensure_runtime()
|
||||
return WATCHLIST.remove(show_id)
|
||||
runtime = ensure_runtime()
|
||||
result = WATCHLIST.remove(show_id)
|
||||
runtime["download_queue"].detach_show(show_id)
|
||||
return result
|
||||
|
||||
|
||||
def upload_watchlist_thumbnail(payload):
|
||||
@@ -2547,6 +2586,8 @@ def resolve_job_watchlist_identity(job, config=None):
|
||||
|
||||
def sync_downloaded_job_to_watchlist(job):
|
||||
ensure_runtime()
|
||||
if job.get("skip_watchlist_sync"):
|
||||
return None
|
||||
show_id, title, reason = resolve_job_watchlist_identity_impl(
|
||||
job,
|
||||
search_fn=search_anime,
|
||||
|
||||
Reference in New Issue
Block a user