Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/VideoDeepLinks for Player and MetaDetails + send more events #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 58 additions & 29 deletions stremio-core-kotlin/src/commonMain/rust/env/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use stremio_core::{
analytics::Analytics,
models::{ctx::Ctx, streaming_server::StreamingServer},
runtime::{msg::Event, Env, EnvError, EnvFuture, EnvFutureExt, TryEnvFuture},
types::api::AuthRequest,
};

use crate::{
Expand Down Expand Up @@ -113,35 +114,63 @@ impl AndroidEnv {
}
pub fn emit_to_analytics(event: &AndroidEvent, model: &AndroidModel, path: &str) {
let (name, data) = match event {
AndroidEvent::CoreEvent(Event::PlayerPlaying { load_time, context }) => (
"playerPlaying".to_owned(),
json!({
"loadTime": load_time,
"player": context
}),
),
AndroidEvent::CoreEvent(Event::PlayerStopped { context }) => {
("playerStopped".to_owned(), json!({ "player": context }))
}
AndroidEvent::CoreEvent(Event::PlayerEnded {
context,
is_binge_enabled,
is_playing_next_video,
}) => (
"playerEnded".to_owned(),
json!({
"player": context,
"isBingeEnabled": is_binge_enabled,
"isPlayingNextVideo": is_playing_next_video
}),
),
AndroidEvent::CoreEvent(Event::TraktPlaying { context }) => {
("traktPlaying".to_owned(), json!({ "player": context }))
}
AndroidEvent::CoreEvent(Event::TraktPaused { context }) => {
("traktPaused".to_owned(), json!({ "player": context }))
}
_ => return,
AndroidEvent::CoreEvent(core_event) => match core_event {
Event::UserAuthenticated { auth_request } => (
"login".to_owned(),
json!({
"type": match auth_request {
AuthRequest::Login { facebook, .. } if *facebook => "facebook",
AuthRequest::Login { .. } => "login",
AuthRequest::Facebook { .. } => "authWithFacebook",
AuthRequest::LoginWithToken { .. } => "loginWithToken",
AuthRequest::Register { .. } => "register",
},
}),
),
Event::AddonInstalled { transport_url, id } => (
"installAddon".to_owned(),
json!({
"addonTransportUrl": transport_url,
"addonID": id
}),
),
Event::AddonUninstalled { transport_url, id } => (
"removeAddon".to_owned(),
json!({
"addonTransportUrl": transport_url,
"addonID": id
}),
),
Event::PlayerPlaying { load_time, context } => (
"playerPlaying".to_owned(),
json!({
"loadTime": load_time,
"player": context
}),
),
Event::PlayerStopped { context } => {
("playerStopped".to_owned(), json!({ "player": context }))
}
Event::PlayerEnded {
context,
is_binge_enabled,
is_playing_next_video,
} => (
"playerEnded".to_owned(),
json!({
"player": context,
"isBingeEnabled": is_binge_enabled,
"isPlayingNextVideo": is_playing_next_video
}),
),
Event::TraktPlaying { context } => {
("traktPlaying".to_owned(), json!({ "player": context }))
}
Event::TraktPaused { context } => {
("traktPaused".to_owned(), json!({ "player": context }))
}
_ => return,
},
};
ANALYTICS.emit(name, data, &model.ctx, &model.streaming_server, path);
}
Expand Down
4 changes: 2 additions & 2 deletions stremio-core-kotlin/src/commonMain/rust/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl AndroidModel {
.encode_to_vec(),
AndroidModelField::MetaDetails => self
.meta_details
.to_protobuf::<AndroidEnv>(&self.ctx)
.to_protobuf::<AndroidEnv>(&(&self.ctx, &self.streaming_server))
.encode_to_vec(),
AndroidModelField::AddonDetails => self
.addon_details
Expand All @@ -176,7 +176,7 @@ impl AndroidModel {
.encode_to_vec(),
AndroidModelField::Player => self
.player
.to_protobuf::<AndroidEnv>(&self.ctx)
.to_protobuf::<AndroidEnv>(&(&self.ctx, &self.streaming_server))
.encode_to_vec(),

// guard against new fields being added to the CSharp model
Expand Down
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
Loading
Loading