Skip to content

Commit

Permalink
feat(stremio-core-protobuf): VideoDeepLinks for MetaDetails and Player
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Dec 17, 2024
1 parent b9fc79e commit b73d1fd
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 29 deletions.
19 changes: 19 additions & 0 deletions stremio-core-protobuf/proto/stremio/core/types/video.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,28 @@ message Video {
required bool upcoming = 8;
required bool watched = 9;
required bool current_video = 10;
// Watch progress percentage
optional double progress = 11;
// scheduled: bool,

required VideoDeepLinks deep_links = 12;

message SeriesInfo {
required int64 season = 1;
required int64 episode = 2;
}
}

message VideoDeepLinks {
required string meta_details_videos = 1;
required string meta_details_streams = 2;
// pub player: Option<String>,
// pub external_player: Option<ExternalPlayerLink>,
optional string player = 3;
required ExternalPlayerLink external_player = 4;

message ExternalPlayerLink {
optional string download = 1;
optional string streaming = 2;
}
}
21 changes: 16 additions & 5 deletions stremio-core-protobuf/src/bridge/loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use stremio_core::{
common::{Loadable, ResourceError},
ctx::{Ctx, CtxError},
link::LinkError,
streaming_server::PlaybackDevice,
streaming_server::{PlaybackDevice, StreamingServer},
},
runtime::EnvError,
types::{
Expand Down Expand Up @@ -53,6 +53,8 @@ impl
ToProtobuf<
models::loadable_meta_item::Content,
(
&Ctx,
&StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
Option<&String>,
Expand All @@ -62,17 +64,26 @@ impl
{
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
&self,
(library_item, watched, addon_name, meta_request): &(
(ctx, streaming_server, library_item, watched, addon_name, meta_request): &(
&Ctx,
&StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
Option<&String>,
&ResourceRequest,
),
) -> models::loadable_meta_item::Content {
match &self {
Loadable::Ready(ready) => models::loadable_meta_item::Content::Ready(
ready.to_protobuf::<E>(&(*library_item, *watched, *addon_name, *meta_request)),
),
Loadable::Ready(ready) => {
models::loadable_meta_item::Content::Ready(ready.to_protobuf::<E>(&(
*ctx,
*streaming_server,
*library_item,
*watched,
*addon_name,
*meta_request,
)))
}
Loadable::Err(error) => models::loadable_meta_item::Content::Error(models::Error {
message: error.to_string(),
}),
Expand Down
22 changes: 19 additions & 3 deletions stremio-core-protobuf/src/bridge/resource_loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use stremio_core::{
models::{
common::{DescriptorLoadable, ResourceLoadable},
ctx::Ctx,
streaming_server::StreamingServer,
},
types::{
addon::{Descriptor, ResourceRequest},
Expand Down Expand Up @@ -60,18 +61,33 @@ impl ToProtobuf<models::LoadablePage, Ctx> for ResourceLoadable<Vec<MetaItemPrev
}
}

impl ToProtobuf<models::LoadableMetaItem, (&Ctx, Option<&LibraryItem>, Option<&WatchedBitField>)>
for &ResourceLoadable<MetaItem>
impl
ToProtobuf<
models::LoadableMetaItem,
(
&Ctx,
&StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
),
> for &ResourceLoadable<MetaItem>
{
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
&self,
(ctx, library_item, watched): &(&Ctx, Option<&LibraryItem>, Option<&WatchedBitField>),
(ctx, streming_server, library_item, watched): &(
&Ctx,
&StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
),
) -> models::LoadableMetaItem {
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableMetaItem {
title: addon_name.to_string(),
request: self.request.to_protobuf::<E>(&()),
content: self.content.to_protobuf::<E>(&(
*ctx,
*streming_server,
*library_item,
*watched,
Some(&addon_name),
Expand Down
82 changes: 73 additions & 9 deletions stremio-core-protobuf/src/model/fields/meta_details.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use boolinator::Boolinator;
use stremio_core::deep_links::MetaItemDeepLinks;

use stremio_core::deep_links::{MetaItemDeepLinks, VideoDeepLinks};
use stremio_core::models::ctx::Ctx;
use stremio_core::models::meta_details::{MetaDetails, Selected};
use stremio_core::models::{
meta_details::{MetaDetails, Selected},
streaming_server::StreamingServer,
};
use stremio_core::runtime::Env;
use stremio_core::types::addon::ResourceRequest;
use stremio_core::types::library::LibraryItem;
use stremio_core::types::resource::{MetaItem, SeriesInfo, Video};
use stremio_core::types::watched_bitfield::WatchedBitField;

use url::Url;

use crate::bridge::{FromProtobuf, ToProtobuf};
use crate::protobuf::stremio::core::{models, types};

Expand Down Expand Up @@ -53,18 +59,25 @@ impl
ToProtobuf<
types::Video,
(
&Ctx,
Option<&Url>,
// &StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
Option<&String>,
&ResourceRequest,
),
> for Video
{
fn to_protobuf<E: Env + 'static>(
&self,
(library_item, watched, addon_name): &(
(ctx, streaming_server_url, library_item, watched, addon_name, request): &(
&Ctx,
Option<&Url>,
Option<&LibraryItem>,
Option<&WatchedBitField>,
Option<&String>,
&ResourceRequest,
),
) -> types::Video {
types::Video {
Expand All @@ -88,6 +101,23 @@ impl
.and_then(|library_item| library_item.state.video_id.to_owned())
.map(|current_video_id| current_video_id == self.id)
.unwrap_or_default(),
progress: library_item.and_then(|library_item| {
ctx.library
.items
.get(&library_item.id)
.filter(|library_item| Some(self.id.to_owned()) == library_item.state.video_id)
.map(|library_item| library_item.progress())
}),
// scheduled: meta_item.preview.behavior_hints.has_scheduled_videos,
deep_links: VideoDeepLinks::from((
self,
*request,
// necessary because Core doesn't use the
// preferred `Option<&Url>` format
&streaming_server_url.map(Clone::clone),
&ctx.profile.settings,
))
.to_protobuf::<E>(&()),
}
}
}
Expand All @@ -109,10 +139,32 @@ impl FromProtobuf<Video> for types::Video {
}
}

impl ToProtobuf<types::VideoDeepLinks, ()> for VideoDeepLinks {
fn to_protobuf<E: Env + 'static>(&self, _args: &()) -> types::VideoDeepLinks {
types::VideoDeepLinks {
meta_details_videos: self.meta_details_videos.clone(),
meta_details_streams: self.meta_details_streams.clone(),
player: self.player.clone(),
external_player: types::video_deep_links::ExternalPlayerLink {
download: self
.external_player
.as_ref()
.and_then(|ep| ep.download.clone()),
streaming: self
.external_player
.as_ref()
.and_then(|ep| ep.streaming.clone()),
},
}
}
}

impl
ToProtobuf<
types::MetaItem,
(
&Ctx,
&StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
Option<&String>,
Expand All @@ -122,7 +174,9 @@ impl
{
fn to_protobuf<E: Env + 'static>(
&self,
(library_item, watched, addon_name, meta_request): &(
(ctx, streaming_server, library_item, watched, addon_name, meta_request): &(
&Ctx,
&StreamingServer,
Option<&LibraryItem>,
Option<&WatchedBitField>,
Option<&String>,
Expand All @@ -146,9 +200,15 @@ impl
.preview
.trailer_streams
.to_protobuf::<E>(&(None, None, None, None)),
videos: self
.videos
.to_protobuf::<E>(&(*library_item, *watched, *addon_name)),
videos: self.videos.to_protobuf::<E>(&(
*ctx,
streaming_server.base_url.as_ref(),
*library_item,
*watched,
*addon_name,
*meta_request,
)),

behavior_hints: self.preview.behavior_hints.to_protobuf::<E>(&()),
deep_links: MetaItemDeepLinks::from((self, *meta_request)).to_protobuf::<E>(&()),
progress: library_item.and_then(|item| {
Expand All @@ -166,8 +226,11 @@ impl
}
}

impl ToProtobuf<models::MetaDetails, Ctx> for MetaDetails {
fn to_protobuf<E: Env + 'static>(&self, ctx: &Ctx) -> models::MetaDetails {
impl ToProtobuf<models::MetaDetails, (&Ctx, &StreamingServer)> for MetaDetails {
fn to_protobuf<E: Env + 'static>(
&self,
(ctx, streaming_server): &(&Ctx, &StreamingServer),
) -> models::MetaDetails {
let meta_item = self
.meta_items
.iter()
Expand Down Expand Up @@ -226,6 +289,7 @@ impl ToProtobuf<models::MetaDetails, Ctx> for MetaDetails {
title,
meta_item: meta_item.to_protobuf::<E>(&(
ctx,
streaming_server,
self.library_item.as_ref(),
self.watched.as_ref(),
)),
Expand Down
44 changes: 32 additions & 12 deletions stremio-core-protobuf/src/model/fields/player.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use stremio_core::models::ctx::Ctx;
use stremio_core::models::player::{Player, Selected, VideoParams};
use stremio_core::types::streams::{AudioTrack, StreamItemState, SubtitleTrack};
use stremio_core::{
models::{
ctx::Ctx,
player::{Player, Selected, VideoParams},
streaming_server::StreamingServer,
},
types::streams::{AudioTrack, StreamItemState, SubtitleTrack},
};

use crate::bridge::{FromProtobuf, ToProtobuf};
use crate::protobuf::stremio::core::models;
use crate::{
bridge::{FromProtobuf, ToProtobuf},
protobuf::stremio::core::models,
};

impl FromProtobuf<Selected> for models::player::Selected {
fn from_protobuf(&self) -> Selected {
Expand Down Expand Up @@ -139,22 +146,35 @@ impl ToProtobuf<models::player::Selected, Ctx> for Selected {
}
}

impl ToProtobuf<models::Player, Ctx> for Player {
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(&self, ctx: &Ctx) -> models::Player {
impl ToProtobuf<models::Player, (Ctx, StreamingServer)> for Player {
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
&self,
(ctx, streaming_server): &(Ctx, StreamingServer),
) -> models::Player {
models::Player {
selected: self.selected.to_protobuf::<E>(ctx),
video_params: self.video_params.to_protobuf::<E>(&()),
meta_item: self.meta_item.as_ref().to_protobuf::<E>(&(
ctx,
streaming_server,
self.library_item.as_ref(),
self.watched.as_ref(),
)),
subtitles: self.subtitles.to_protobuf::<E>(ctx),
next_video: self.next_video.to_protobuf::<E>(&(
self.library_item.as_ref(),
self.watched.as_ref(),
None,
)),
next_video: self
.selected
.as_ref()
.and_then(|selected| selected.meta_request.as_ref())
.and_then(|meta_request| {
self.next_video.to_protobuf::<E>(&(
ctx,
streaming_server.base_url.as_ref(),
self.library_item.as_ref(),
self.watched.as_ref(),
None,
meta_request,
))
}),
series_info: self.series_info.to_protobuf::<E>(&()),
library_item: self.library_item.to_protobuf::<E>(&(ctx, None)),
stream_state: self.stream_state.to_protobuf::<E>(&()),
Expand Down

0 comments on commit b73d1fd

Please sign in to comment.