Fix movie watchlist completion sync

This commit is contained in:
Dymas
2026-05-26 07:26:54 +02:00
parent 28410b2946
commit ff605aca03
6 changed files with 56 additions and 9 deletions
+18 -5
View File
@@ -2001,13 +2001,14 @@ class WatchlistStore:
)
return self.schedule_refresh(existing["show_id"], source=source)
def mark_downloaded(self, show_id, title="", mode="", episodes=""):
def mark_downloaded(self, show_id, title="", mode="", episodes="", media_type=""):
normalized_show_id = str(show_id or "").strip()
if not normalized_show_id:
raise ValueError("Missing show_id for watchlist download sync.")
normalized_title = str(title or "").strip()
normalized_mode = str(mode or "").strip().lower()
normalized_media_type = normalize_media_type(media_type or "tv")
episode_spec = str(episodes or "").strip()
now = now_iso()
downloaded_episode_values = []
@@ -2030,7 +2031,10 @@ class WatchlistStore:
completed_item = dict(existing_item)
completed_item["downloaded_sub_episodes"] = decode_episode_values(sub_payload)
completed_item["downloaded_dub_episodes"] = decode_episode_values(dub_payload)
is_complete, _reason = watchlist_item_download_complete(completed_item, mode=normalized_mode)
if normalize_media_type(existing_item.get("media_type")) == "movie":
is_complete = True
else:
is_complete, _reason = watchlist_item_download_complete(completed_item, mode=normalized_mode)
target_category = "finished" if is_complete else existing_item["category"]
conn.execute(
"""
@@ -2058,7 +2062,10 @@ class WatchlistStore:
completed_item = dict(matched_item)
completed_item["downloaded_sub_episodes"] = decode_episode_values(sub_payload)
completed_item["downloaded_dub_episodes"] = decode_episode_values(dub_payload)
is_complete, _reason = watchlist_item_download_complete(completed_item, mode=normalized_mode)
if normalize_media_type(matched_item.get("media_type")) == "movie":
is_complete = True
else:
is_complete, _reason = watchlist_item_download_complete(completed_item, mode=normalized_mode)
target_category = "finished" if is_complete else matched_item["category"]
conn.execute(
"""
@@ -2117,7 +2124,7 @@ class WatchlistStore:
"alternative_titles_json": None,
"anidb_aid": None,
"anidb_title": None,
"media_type": "tv",
"media_type": normalized_media_type,
"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,
@@ -2599,7 +2606,13 @@ def sync_downloaded_job_to_watchlist(job):
if not show_id:
debug_log("watchlist.sync.resolve_failed", job=job, reason=reason)
raise ValueError(f"Could not resolve a watchlist show_id for the completed download: {reason}.")
return WATCHLIST.mark_downloaded(show_id, title=title, mode=job.get("mode"), episodes=job.get("episodes"))
return WATCHLIST.mark_downloaded(
show_id,
title=title,
mode=job.get("mode"),
episodes=job.get("episodes"),
media_type=job.get("media_type"),
)
def prepare_download_job(job):
config = ensure_runtime()["config"]