Skip to content

Commit

Permalink
feat(stremio-core-web): Player - watched & progress of the MetaItem V…
Browse files Browse the repository at this point in the history
…ideo & Next video

Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Nov 18, 2024
1 parent 645d6ec commit 62a08ba
Showing 1 changed file with 67 additions and 26 deletions.
93 changes: 67 additions & 26 deletions stremio-core-web/src/model/serialize_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod model {
pub video: &'a stremio_core::types::resource::Video,
pub upcoming: bool,
pub watched: bool,
pub progress: Option<u32>,
pub progress: Option<f64>,
pub scheduled: bool,
pub deep_links: VideoDeepLinks,
}
Expand Down Expand Up @@ -134,30 +134,44 @@ pub fn serialize_player<E: stremio_core::runtime::Env + 'static>(
.map(|ResourceLoadable { request, content }| match &content {
Some(Loadable::Loading) | None => Loadable::Loading,
Some(Loadable::Err(error)) => Loadable::Err(error),
Some(Loadable::Ready(meta_item)) => {
Loadable::Ready(model::MetaItem {
meta_item,
videos: meta_item
.videos
.iter()
.map(|video| model::Video {
Some(Loadable::Ready(meta_item)) => Loadable::Ready(model::MetaItem {
meta_item,
videos: meta_item
.videos
.iter()
.map(|video| model::Video {
video,
upcoming: meta_item.preview.behavior_hints.has_scheduled_videos
&& video.released > Some(E::now()),
watched: ctx
.library
.items
.get(&meta_item.preview.id)
.map(|library_item| {
library_item
.state
.watched_bitfield(&meta_item.videos)
.get_video(&video.id)
})
.unwrap_or_default(),
// only the currently playing video can have the progress
// as we keep that information in the LibraryItem
progress: ctx
.library
.items
.get(&meta_item.preview.id)
.map(|library_item| library_item.progress()),
scheduled: meta_item.preview.behavior_hints.has_scheduled_videos,
deep_links: VideoDeepLinks::from((
video,
upcoming: meta_item.preview.behavior_hints.has_scheduled_videos
&& video.released > Some(E::now()),
watched: false, // TODO use library
progress: None, // TODO use library,
scheduled: meta_item.preview.behavior_hints.has_scheduled_videos,
deep_links: VideoDeepLinks::from((
video,
request,
&streaming_server.base_url,
&ctx.profile.settings,
))
.into_web_deep_links(),
})
.collect(),
})
}
request,
&streaming_server.base_url,
&ctx.profile.settings,
))
.into_web_deep_links(),
})
.collect(),
}),
}),
subtitles: player
.subtitles
Expand Down Expand Up @@ -214,8 +228,35 @@ pub fn serialize_player<E: stremio_core::runtime::Env + 'static>(
&& video.released > Some(E::now())
})
.unwrap_or_default(),
watched: false, // TODO use library
progress: None, // TODO use library,
watched: player
.meta_item
.as_ref()
.and_then(|meta_item| match meta_item {
ResourceLoadable {
content: Some(Loadable::Ready(meta_item)),
..
} => Some(meta_item),
_ => None,
})
.and_then(|meta_item| {
ctx.library
.items
.get(&meta_item.preview.id)
.map(|library_item| {
library_item
.state
.watched_bitfield(&meta_item.videos)
.get_video(&video.id)
})
})
.unwrap_or_default(),
// We do not have information about other videos in the LibraryItem
// apart from the currently playing one.
// We could eventually use e.g. StreamsBucket to get local streams
// and match the next video with existing stream, however, we only use this next_video
// for generating the Deep links
// Will always be None!
progress: None,
scheduled: player
.meta_item
.as_ref()
Expand Down

0 comments on commit 62a08ba

Please sign in to comment.