Video auto-wishlist: store the show library_id (fixes 'show not matched')

The real difference from a manual add: the wishlist resolves a show's synopsis +
cast from /api/video/detail/show/<library_id>, and falls back to the TMDB endpoint
only when library_id is absent (which redirects/lacks cast for owned shows). A
manual add sends show.library_id; the automation sent none — so auto-added shows
read as 'not matched' with no synopsis/actors. The handler now carries the show's
library id (the calendar's show_id) through to the wishlist.
This commit is contained in:
BoulderBadgeDad 2026-06-21 10:11:13 -07:00
parent d925c34ce5
commit 94e06f2d50
2 changed files with 20 additions and 12 deletions

View file

@ -27,11 +27,13 @@ def _default_fetch_airing(today: str) -> List[Dict[str, Any]]:
today, today, server_source=resolve_video_server(), watchlist_only=True)
def _default_add_episodes(show_tmdb_id: Any, show_title: Any, episodes: List[Dict[str, Any]]) -> int:
def _default_add_episodes(show_tmdb_id: Any, show_title: Any, episodes: List[Dict[str, Any]],
library_id: Any = None) -> int:
from api.video import get_video_db
from core.video.sources import resolve_video_server
return get_video_db().add_episodes_to_wishlist(
show_tmdb_id, show_title, episodes, server_source=resolve_video_server())
show_tmdb_id, show_title, episodes, library_id=library_id,
server_source=resolve_video_server())
def _default_season_meta(tmdb_id: Any, season_number: Any):
@ -82,7 +84,7 @@ def auto_video_add_airing_episodes(
# Group what to wish for by show: airing today, NOT already owned, with a
# real season/episode. add_episodes_to_wishlist is idempotent, so re-runs
# never duplicate.
by_show: Dict[tuple, List[Dict[str, Any]]] = {}
by_show: Dict[tuple, Dict[str, Any]] = {}
season_cache: Dict[tuple, tuple] = {}
for r in rows:
if r.get('has_file'):
@ -95,7 +97,12 @@ def auto_video_add_airing_episodes(
# poster); fall back to the calendar/DB values if TMDB is unavailable.
poster, emap = _season_lookup(season_meta, tid, sn, season_cache)
tm = emap.get(en) or {}
by_show.setdefault((tid, r.get('show_title')), []).append({
# library_id (the show's library row id, given as show_id) is REQUIRED — the
# wishlist resolves a show's synopsis + cast from /detail/show/<library_id>;
# without it the show shows as un-matched with no synopsis/actors.
grp = by_show.setdefault((tid, r.get('show_title')),
{'library_id': r.get('show_id'), 'eps': []})
grp['eps'].append({
'season_number': sn,
'episode_number': en,
'title': r.get('title') or tm.get('title'),
@ -106,8 +113,8 @@ def auto_video_add_airing_episodes(
})
added = 0
for (tid, title), eps in by_show.items():
added += int(add_episodes(tid, title, eps) or 0)
for (tid, title), grp in by_show.items():
added += int(add_episodes(tid, title, grp['eps'], grp['library_id']) or 0)
shows = len(by_show)
deps.update_progress(

View file

@ -15,7 +15,7 @@ class _Deps:
def _row(tid, title, s, e, owned=False):
return {"show_tmdb_id": tid, "show_title": title, "season_number": s,
return {"show_tmdb_id": tid, "show_id": tid * 100, "show_title": title, "season_number": s,
"episode_number": e, "title": "Ep", "air_date": "2026-06-21", "has_file": owned}
@ -29,8 +29,8 @@ def test_adds_unowned_airings_grouped_by_show():
]
added = []
def add(tid, title, eps):
added.append((tid, title, len(eps)))
def add(tid, title, eps, library_id=None):
added.append((tid, title, len(eps), library_id))
return len(eps)
res = auto_video_add_airing_episodes(
@ -41,7 +41,8 @@ def test_adds_unowned_airings_grouped_by_show():
assert res["status"] == "completed"
assert res["episodes_added"] == 3 # 2 of Widows Bay + 1 of Another Show
assert res["shows"] == 2
assert (1, "Widows Bay", 2) in added and (2, "Another Show", 1) in added
# the show's library_id (show_id) is carried so the wishlist can match the show
assert (1, "Widows Bay", 2, 100) in added and (2, "Another Show", 1, 200) in added
def test_uses_tmdb_season_metadata_like_a_manual_add():
@ -59,7 +60,7 @@ def test_uses_tmdb_season_metadata_like_a_manual_add():
captured = {}
def add(tid, title, eps):
def add(tid, title, eps, library_id=None):
captured["eps"] = eps
return len(eps)
@ -78,7 +79,7 @@ def test_falls_back_to_db_values_when_tmdb_unavailable():
"has_file": False, "overview": "db synopsis", "still_url": "/library/metadata/9/thumb/1"}]
captured = {}
def add(tid, title, eps):
def add(tid, title, eps, library_id=None):
captured["eps"] = eps
return len(eps)