Skip to content

Commit

Permalink
feat(player): implement next_stream based on selected binge group
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Oct 12, 2023
1 parent b6cc8c8 commit 35fa792
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct Player {
pub subtitles: Vec<ResourceLoadable<Vec<Subtitles>>>,
pub next_video: Option<Video>,
pub next_streams: Option<ResourceLoadable<Vec<Stream>>>,
pub next_stream: Option<Stream>,
pub series_info: Option<SeriesInfo>,
pub library_item: Option<LibraryItem>,
#[serde(skip_serializing)]
Expand Down Expand Up @@ -205,6 +206,12 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&self.next_video,
&self.selected,
);
let next_stream_effects = next_stream_update(
&mut self.next_stream,
&self.next_streams,
&self.selected,
&ctx.profile.settings,
);
let series_info_effects =
series_info_update(&mut self.series_info, &self.selected, &self.meta_item);
let library_item_effects = library_item_update::<E>(
Expand Down Expand Up @@ -259,6 +266,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(subtitles_effects)
.join(next_video_effects)
.join(next_streams_effects)
.join(next_stream_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(watched_effects)
Expand Down Expand Up @@ -287,6 +295,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
let subtitles_effects = eq_update(&mut self.subtitles, vec![]);
let next_video_effects = eq_update(&mut self.next_video, None);
let next_streams_effects = eq_update(&mut self.next_streams, None);
let next_stream_effects = eq_update(&mut self.next_stream, None);
let series_info_effects = eq_update(&mut self.series_info, None);
let library_item_effects = eq_update(&mut self.library_item, None);
let watched_effects = eq_update(&mut self.watched, None);
Expand All @@ -302,6 +311,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(subtitles_effects)
.join(next_video_effects)
.join(next_streams_effects)
.join(next_stream_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(watched_effects)
Expand Down Expand Up @@ -489,6 +499,13 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&self.next_video,
&self.selected,
));
let next_stream_effects = next_stream_update(
&mut self.next_stream,
&self.next_streams,
&self.selected,
&ctx.profile.settings,
);

let series_info_effects =
series_info_update(&mut self.series_info, &self.selected, &self.meta_item);
let library_item_effects = library_item_update::<E>(
Expand Down Expand Up @@ -525,6 +542,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(subtitles_effects)
.join(next_video_effects)
.join(next_streams_effects)
.join(next_stream_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(watched_effects)
Expand Down Expand Up @@ -684,6 +702,31 @@ where
}
}

fn next_stream_update(
stream: &mut Option<Stream>,
next_streams: &Option<ResourceLoadable<Vec<Stream>>>,
selected: &Option<Selected>,
settings: &ProfileSettings,
) -> Effects {
let next_stream = match (selected, next_streams) {
(
Some(Selected { stream, .. }),
Some(ResourceLoadable {
content: Some(Loadable::Ready(streams)),
..
}),
) if settings.binge_watching => streams
.iter()
.find(|Stream { behavior_hints, .. }| {
behavior_hints.binge_group == stream.behavior_hints.binge_group
})
.cloned(),
_ => None,
};

eq_update(stream, next_stream)
}

fn series_info_update(
series_info: &mut Option<SeriesInfo>,
selected: &Option<Selected>,
Expand Down

0 comments on commit 35fa792

Please sign in to comment.