Skip to content

Commit

Permalink
chore: Update CW Preview and action MarkAsWatched video
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Sep 11, 2023
1 parent 0e639bc commit fccc85d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/commonMain/rust/bridge/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl FromProtobuf<Action> for runtime::Action {
}
Some(action_meta_details::Args::MarkVideoAsWatched(video_state)) => {
Action::MetaDetails(ActionMetaDetails::MarkVideoAsWatched(
video_state.video_id.to_owned(),
video_state.video.from_protobuf(),
video_state.is_watched,
))
}
Expand Down
43 changes: 43 additions & 0 deletions src/commonMain/rust/bridge/continue_watching_preview.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use stremio_core::deep_links::LibraryItemDeepLinks;
use stremio_core::models::continue_watching_preview::Item;

use crate::protobuf::stremio::core::models;
use crate::protobuf::stremio::core::types;

use super::ToProtobuf;

impl ToProtobuf<models::ContinueWatchingItem, ()> for Item {
fn to_protobuf(&self, _args: &()) -> models::ContinueWatchingItem {
let deep_links = LibraryItemDeepLinks::from(&self.library_item);
models::ContinueWatchingItem {
id: self.library_item.id.to_string(),
r#type: self.library_item.r#type.to_string(),
name: self.library_item.name.to_string(),
poster: self.library_item.poster.to_protobuf(&()),
poster_shape: self.library_item.poster_shape.to_protobuf(&()) as i32,
state: types::LibraryItemState {
time_offset: self.library_item.state.time_offset,
duration: self.library_item.state.duration,
video_id: self.library_item.state.video_id.clone(),
},
behavior_hints: self.library_item.behavior_hints.to_protobuf(&()),
deep_links: types::MetaItemDeepLinks {
meta_details_videos: deep_links.meta_details_videos,
meta_details_streams: deep_links.meta_details_streams,
player: deep_links.player,
},
progress: if self.library_item.state.time_offset > 0
&& self.library_item.state.duration > 0
{
Some(
self.library_item.state.time_offset as f64
/ self.library_item.state.duration as f64,
)
} else {
None
},
watched: self.library_item.state.times_watched > 0,
notifications: self.notifications as u64,
}
}
}
3 changes: 3 additions & 0 deletions src/commonMain/rust/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub use android_model_field::*;
mod auth_request;
pub use auth_request::*;

mod continue_watching_preview;
pub use continue_watching_preview::*;

mod date;
pub use date::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::protobuf::stremio::core::models;
impl ToProtobuf<models::ContinueWatchingPreview, ()> for ContinueWatchingPreview {
fn to_protobuf(&self, _args: &()) -> models::ContinueWatchingPreview {
models::ContinueWatchingPreview {
library_items: self.library_items.to_protobuf(&()),
items: self.items.to_protobuf(&()),
}
}
}
26 changes: 26 additions & 0 deletions src/commonMain/rust/model/fields/meta_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ impl ToProtobuf<types::video::SeriesInfo, ()> for SeriesInfo {
}
}

impl FromProtobuf<SeriesInfo> for types::video::SeriesInfo {
fn from_protobuf(&self) -> SeriesInfo {
SeriesInfo {
season: self.season.unsigned_abs() as u32,
episode: self.episode.unsigned_abs() as u32,
}
}
}

impl
ToProtobuf<
types::Video,
Expand Down Expand Up @@ -80,6 +89,23 @@ impl
}
}

impl FromProtobuf<Video> for types::Video {
fn from_protobuf(&self) -> Video {
Video {
id: self.id.to_owned(),
title: self.title.to_owned(),
released: self.released.to_owned().from_protobuf(),
overview: self.overview.to_owned(),
thumbnail: self.thumbnail.to_owned(),
streams: self.streams.to_owned().from_protobuf(),
series_info: self.series_info.to_owned().from_protobuf(),
// trailer_streams: self.trailer_streams.to_owned(),
// TODO: implement trailer streams!
trailer_streams: vec![],
}
}
}

impl
ToProtobuf<
types::MetaItem,
Expand Down
1 change: 1 addition & 0 deletions src/commonMain/rust/model/fields/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl ToProtobuf<models::player::Selected, Ctx> for Selected {
.find(|addon| addon.transport_url == request.base)
.map(|addon| &addon.manifest.name)
});

models::player::Selected {
stream: self
.stream
Expand Down
3 changes: 2 additions & 1 deletion src/commonMain/rust/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl AndroidModel {
let ctx = Ctx::new(profile, library, streams, notifications);

let (discover, discover_effects) = CatalogWithFilters::<MetaItemPreview>::new(&ctx.profile);
let (library_, library_effects) = LibraryWithFilters::<NotRemovedFilter>::new(&ctx.library);
let (library_, library_effects) =
LibraryWithFilters::<NotRemovedFilter>::new(&ctx.library, &ctx.notifications);
let (library_by_type, library_by_type_effects) = LibraryByType::<NotRemovedFilter>::new();
let (addons, addons_effects) = AddonsWithFilters::new(&ctx.profile);
let (streaming_server, streaming_server_effects) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ option java_package = "com.stremio.core.models";

import "stremio/core/types/library.proto";

import "stremio/core/types/meta_item.proto";

message ContinueWatchingItem {
required string id = 1;
required string type = 2;
required string name = 3;
optional string poster = 4;
required stremio.core.types.PosterShape poster_shape = 5;
required stremio.core.types.LibraryItemState state = 6;
required stremio.core.types.MetaItemBehaviorHints behavior_hints = 7;
required stremio.core.types.MetaItemDeepLinks deep_links = 8;
optional double progress = 9;
required bool watched = 10;
required uint64 notifications = 11;
}

message ContinueWatchingPreview {
repeated stremio.core.types.LibraryItem library_items = 1;
repeated ContinueWatchingItem items = 1;
}
1 change: 1 addition & 0 deletions src/main/proto/stremio/core/types/video.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ message Video {
optional string thumbnail = 5;
repeated Stream streams = 6;
optional SeriesInfo seriesInfo = 7;
// TODO: Add trailer streams
required bool upcoming = 8;
required bool watched = 9;
required bool current_video = 10;
Expand Down

0 comments on commit fccc85d

Please sign in to comment.