fix(plex): Restart only where an episode has a resume point; the Surprise draw is re-read, not redrawn
Show cards carry resumable (ShowState, from the same rollup) so a part-watched show whose next episode is untouched offers Play, not a Continue and a Restart that do the same thing; plexStarted is the one rule for cards and menus. The Surprise rail's key sits under the discover root: whatever refreshes the rails re-reads the draw (keep=) with its watch state now, kept past the 5-minute gc, and only the reshuffle deals. Closing the player refreshes the Discover rails. A show card's play acts on the last click only, and only where it was made.
This commit is contained in:
@@ -331,6 +331,20 @@ def test_a_reshuffle_deals_other_titles_first(db, monkeypatch, override_dep):
|
||||
assert set(movies("/api/plex/surprise?scope=movie&exclude=m2&exclude=m3")) == {"m2", "m3"}
|
||||
|
||||
|
||||
def test_a_kept_draw_is_read_again_not_redrawn(db, monkeypatch, override_dep):
|
||||
# The rail's draw stands until the ↻, but its cards' watch state moves: `keep` answers the titles on
|
||||
# screen, in their order and as they stand now, a watched one included; the scope still bounds it.
|
||||
user = _seed(db)
|
||||
url = "/api/plex/surprise?scope=both&keep=m3&keep=sh1&keep=m1&keep=nope"
|
||||
items = _get(db, user, monkeypatch, override_dep, url).json()["items"]
|
||||
assert _ids(items) == ["m3", "sh1", "m1"]
|
||||
by_id = {c["id"]: c for c in items}
|
||||
assert by_id["m1"]["status"] == "watched"
|
||||
assert by_id["m3"]["position_seconds"] > 0
|
||||
movie_only = "/api/plex/surprise?scope=movie&keep=sh1&keep=m2"
|
||||
assert _ids(_get(db, user, monkeypatch, override_dep, movie_only).json()["items"]) == ["m2"]
|
||||
|
||||
|
||||
def test_discover_scope_movie_excludes_shows(db, monkeypatch, override_dep):
|
||||
user = _seed(db)
|
||||
d = _get(db, user, monkeypatch, override_dep, "/api/plex/discover?scope=movie").json()
|
||||
|
||||
@@ -18,6 +18,7 @@ from app.db import get_db
|
||||
from app.main import app
|
||||
from app.models import PlexItem, PlexLibrary, PlexSeason, PlexShow, PlexState, User
|
||||
from app.plex import rollup, sync
|
||||
from app.plex.cards import ShowState
|
||||
|
||||
|
||||
def _dt(day: int) -> datetime:
|
||||
@@ -184,21 +185,50 @@ class TestRollup:
|
||||
def test_state_map_new_inprogress_watched(self, db):
|
||||
s = _seed(db)
|
||||
show, user = s["show"], s["user"]
|
||||
# e1 in-progress, e2 new -> in_progress
|
||||
assert rollup.state_map(db, user.id, [show.id]) == {show.id: "in_progress"}
|
||||
# e1 in-progress, e2 new -> in_progress, and e1's resume point makes it resumable
|
||||
assert rollup.state_map(db, user.id, [show.id]) == {show.id: ShowState("in_progress", True)}
|
||||
# empty input short-circuits
|
||||
assert rollup.state_map(db, user.id, []) == {}
|
||||
# a fresh user with no state -> new
|
||||
other = User(email="rollup-other@example.com")
|
||||
db.add(other)
|
||||
db.commit()
|
||||
assert rollup.state_map(db, other.id, [show.id]) == {show.id: "new"}
|
||||
# mark every episode watched for `user` -> watched
|
||||
assert rollup.state_map(db, other.id, [show.id]) == {show.id: ShowState("new", False)}
|
||||
# e1 finished, e2 untouched: part watched, but no episode to resume — Continue and Restart
|
||||
# would both play e2 from its start
|
||||
db.execute(delete(PlexState).where(PlexState.user_id == user.id))
|
||||
for e in db.execute(select(PlexItem).where(PlexItem.kind == "episode")).scalars():
|
||||
db.add(PlexState(user_id=user.id, item_id=e.id, status="watched"))
|
||||
e1, e2 = db.execute(
|
||||
select(PlexItem).where(PlexItem.kind == "episode").order_by(PlexItem.episode_number)
|
||||
).scalars()
|
||||
db.add(PlexState(user_id=user.id, item_id=e1.id, status="watched"))
|
||||
db.commit()
|
||||
assert rollup.state_map(db, user.id, [show.id]) == {show.id: "watched"}
|
||||
assert rollup.state_map(db, user.id, [show.id]) == {
|
||||
show.id: ShowState("in_progress", False)
|
||||
}
|
||||
# mark every episode watched for `user` -> watched
|
||||
db.add(PlexState(user_id=user.id, item_id=e2.id, status="watched"))
|
||||
db.commit()
|
||||
assert rollup.state_map(db, user.id, [show.id]) == {show.id: ShowState("watched", False)}
|
||||
|
||||
def test_the_grid_card_says_whether_a_show_has_an_episode_to_resume(
|
||||
self, db, monkeypatch, override_dep
|
||||
):
|
||||
s = _seed(db)
|
||||
user = s["user"]
|
||||
cards = {
|
||||
i["id"]: i
|
||||
for i in _get(db, user, monkeypatch, override_dep, "/api/plex/library").json()["items"]
|
||||
}
|
||||
assert cards["s1"]["resumable"] is True
|
||||
db.execute(
|
||||
delete(PlexState).where(PlexState.user_id == user.id, PlexState.position_seconds > 0)
|
||||
)
|
||||
db.commit()
|
||||
cards = {
|
||||
i["id"]: i
|
||||
for i in _get(db, user, monkeypatch, override_dep, "/api/plex/library").json()["items"]
|
||||
}
|
||||
assert cards["s1"]["resumable"] is False
|
||||
|
||||
|
||||
def _fake_paginate(by_type):
|
||||
|
||||
Reference in New Issue
Block a user