feat(plex): every show card plays the episode it would put on
A show card's picture opened the show page everywhere but Home, whose shelves carried the
resolved `next`. Now every Plex picture plays: a show asks `GET /api/plex/show/{id}/next`
(the in-progress episode, else the first unwatched, else S1·E1 — the rule Home and the show
page's Resume follow) on the click, fresh each time. A started show shows Continue + Restart;
its title, an ⓘ and the menu's "Open show" row open its page; one with no episodes opens there.
The question is asked per show, never carried on every card: three probes a show would cost a
grid page up to 180 queries. The hover preview asks it once it opens and names the episode
("Next: S6·E16 — Title"). Related shows on a show page play the same way.
This commit is contained in:
@@ -19,7 +19,7 @@ import app.state as state
|
||||
from app.auth import current_user
|
||||
from app.db import get_db
|
||||
from app.main import app
|
||||
from app.models import PlexItem, PlexLibrary, PlexSeason, PlexShow, User
|
||||
from app.models import PlexItem, PlexLibrary, PlexSeason, PlexShow, PlexState, User
|
||||
from app.plex import detail
|
||||
from app.plex.sync import _apply_facet_fields, _enrich_people_batch
|
||||
|
||||
@@ -446,3 +446,63 @@ def test_item_detail_markers_carry_plex_final_flag(db, monkeypatch, override_dep
|
||||
{"type": "credits", "start_s": 6811.0, "end_s": 6831.0, "final": False},
|
||||
{"type": "credits", "start_s": 7549.0, "end_s": 7559.0, "final": True},
|
||||
]
|
||||
|
||||
|
||||
def _show_with_episodes(db, n=3):
|
||||
lib = PlexLibrary(plex_key="3", title="Shows", kind="show", enabled=True)
|
||||
db.add(lib)
|
||||
db.flush()
|
||||
show = PlexShow(rating_key="sn1", library_id=lib.id, title="Next Show")
|
||||
db.add(show)
|
||||
db.flush()
|
||||
eps = [
|
||||
PlexItem(
|
||||
rating_key=f"sn1e{i}",
|
||||
library_id=lib.id,
|
||||
kind="episode",
|
||||
title=f"Episode {i}",
|
||||
show_id=show.id,
|
||||
season_number=1,
|
||||
episode_number=i,
|
||||
)
|
||||
for i in range(1, n + 1)
|
||||
]
|
||||
db.add_all(eps)
|
||||
db.flush()
|
||||
return eps
|
||||
|
||||
|
||||
def test_show_next_plays_the_first_episode_of_an_untouched_show(db, monkeypatch, override_dep):
|
||||
"""A show card's picture plays: never started → its first episode."""
|
||||
_show_with_episodes(db)
|
||||
user = _user(db, "next1@example.com")
|
||||
db.commit()
|
||||
resp = _get(db, user, monkeypatch, override_dep, "/api/plex/show/sn1/next")
|
||||
assert resp.status_code == 200, resp.text
|
||||
nxt = resp.json()["next"]
|
||||
assert nxt["id"] == "sn1e1"
|
||||
assert nxt["show_title"] == "Next Show"
|
||||
|
||||
|
||||
def test_show_next_continues_the_episode_in_progress(db, monkeypatch, override_dep):
|
||||
"""Started → the episode in progress (the show page's Resume), not the first unwatched."""
|
||||
eps = _show_with_episodes(db)
|
||||
user = _user(db, "next2@example.com")
|
||||
db.add(PlexState(user_id=user.id, item_id=eps[0].id, status="watched"))
|
||||
db.add(PlexState(user_id=user.id, item_id=eps[2].id, status="new", position_seconds=120))
|
||||
db.commit()
|
||||
resp = _get(db, user, monkeypatch, override_dep, "/api/plex/show/sn1/next")
|
||||
assert resp.json()["next"]["id"] == "sn1e3"
|
||||
assert resp.json()["next"]["position_seconds"] == 120
|
||||
|
||||
|
||||
def test_show_next_is_null_for_an_empty_show_and_404_for_an_unknown_one(
|
||||
db, monkeypatch, override_dep
|
||||
):
|
||||
_show_with_episodes(db, n=0)
|
||||
user = _user(db, "next3@example.com")
|
||||
db.commit()
|
||||
assert _get(db, user, monkeypatch, override_dep, "/api/plex/show/sn1/next").json() == {
|
||||
"next": None
|
||||
}
|
||||
assert _get(db, user, monkeypatch, override_dep, "/api/plex/show/nope/next").status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user