Skip to main content

pick_current_episode

Function pick_current_episode 

Source
pub fn pick_current_episode(
    series_id: &str,
    episodes: &[MediaItem],
    next_up: &[MediaItem],
    resume: &[MediaItem],
) -> Option<MediaItem>
Expand description

The episode a viewer should land on when they open series_id.

Order of preference, and why:

  1. An episode in progress. That is literally where playback stopped; Next Up would skip past it. On a tie the earliest in series order wins, so a viewer who dipped into a later episode still returns to the one they are working through.
  2. The server’s Next Up for this series — it accounts for watch history we do not cache locally.
  3. The episode after the furthest-watched one, falling back to the first unwatched episode when nothing has been watched or the series is finished. This is the offline path: OfflineRepository::get_next_up_episodes returns an empty vec, so without this rung the whole feature would be online-only. It deliberately does not return the first unwatched episode outright — an unwatched episode behind the viewer’s furthest point was skipped on purpose, and sending them back to it is the bug DR-101 was reopened for.
  4. The first episode, so a never-watched series opens on its premiere rather than on nothing.

next_up / resume entries are honoured even when absent from episodes (the season fan-out can miss an id the server returns), but only when they belong to this series.