Skip to content

Commit

Permalink
Merge pull request #738 from Stremio/fix/wasm-player-watched-progress…
Browse files Browse the repository at this point in the history
…-of-library-items-and-videos

feat(wasn) Player - watched & progress of the MetaItem Video & Next Video
  • Loading branch information
elpiel authored Dec 4, 2024
2 parents 8be9ebe + 99c990b commit 9e3abdf
Showing 1 changed file with 79 additions and 26 deletions.
105 changes: 79 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,56 @@ 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).and_then(
|library_item| {
// only set up the progress for the current video
// for series, the selected stream path ID should be the video id!
if player
.selected
.as_ref()
.and_then(|selected| selected.stream_request.as_ref())
.map(|stream_request| stream_request.path.id == video.id)
.unwrap_or_default()
{
Some(library_item.progress())
} else {
None
}
},
),
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 +240,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 9e3abdf

Please sign in to comment.