Skip to content

Commit

Permalink
add missing proto and rust mapping impl
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Nov 2, 2023
1 parent 145cec9 commit a418dbe
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Android NDK
run: yes | sdkmanager "ndk;21.0.6113669" >/dev/null
- name: Set default rust toolchain
run: rustup default 1.61.0
run: rustup default 1.67.1
- name: Install rustfmt
run: rustup component add rustfmt
- name: Install clippy
Expand Down
4 changes: 2 additions & 2 deletions src/commonMain/rust/bridge/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ impl FromProtobuf<Action> for runtime::Action {
}
}
Some(runtime::action::Type::Player(action_player)) => match &action_player.args {
Some(action_player::Args::VideoParamsChanged(video_params_changed)) => {
Some(action_player::Args::VideoParamsChanged(video_params)) => {
Action::Player(ActionPlayer::VideoParamsChanged {
video_params: video_params_changed.video_param.from_protobuf(),
video_params: Some(video_params.from_protobuf()),
})
}
Some(action_player::Args::TimeChanged(item_state)) => {
Expand Down
60 changes: 0 additions & 60 deletions src/commonMain/rust/bridge/continue_watching_item.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/commonMain/rust/bridge/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl ToProtobuf<runtime::Event, ()> for Event {
impl ToProtobuf<runtime::RuntimeEvent, ()> for RuntimeEvent<AndroidEnv, AndroidModel> {
fn to_protobuf(&self, _args: &()) -> runtime::RuntimeEvent {
let event = match self {
RuntimeEvent::NewState(fields) => {
RuntimeEvent::NewState(fields, ..) => {
runtime::runtime_event::Event::NewState(runtime::runtime_event::NewState {
fields: fields
.to_protobuf(&())
Expand Down
26 changes: 15 additions & 11 deletions src/commonMain/rust/bridge/library_item.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
use stremio_core::deep_links::LibraryItemDeepLinks;
use stremio_core::models::ctx::Ctx;
use stremio_core::types::library::LibraryItem;
use stremio_core::types::profile::Settings;
use stremio_core::types::streams::StreamsItem;
use url::Url;

use crate::bridge::ToProtobuf;
use crate::protobuf::stremio::core::types;

impl ToProtobuf<types::LibraryItem, (Option<&StreamsItem>, Option<&Url>, &Settings)> for LibraryItem {
fn to_protobuf(&self, args: &(Option<&StreamsItem>, Option<&Url>, &Settings)) -> types::LibraryItem {
let deep_links = LibraryItemDeepLinks::from((self, args.0, args.1, args.2));
impl ToProtobuf<types::LibraryItem, Ctx> for LibraryItem {
fn to_protobuf(&self, ctx: &Ctx) -> types::LibraryItem {
let notifications = ctx
.notifications
.items
.get(&self.id)
.map(|notifs| notifs.len())
.unwrap_or_default();
let settings = &ctx.profile.settings;
let streaming_server_url = &settings.streaming_server_url;
let deep_links =
LibraryItemDeepLinks::from((self, None, Some(streaming_server_url), settings));
types::LibraryItem {
id: self.id.to_string(),
r#type: self.r#type.to_string(),
Expand All @@ -27,12 +34,9 @@ impl ToProtobuf<types::LibraryItem, (Option<&StreamsItem>, Option<&Url>, &Settin
meta_details_streams: deep_links.meta_details_streams,
player: deep_links.player,
},
progress: if self.state.time_offset > 0 && self.state.duration > 0 {
Some(self.state.time_offset as f64 / self.state.duration as f64)
} else {
None
},
progress: self.progress(),
watched: self.state.times_watched > 0,
notifications: notifications as u64,
}
}
}
3 changes: 0 additions & 3 deletions src/commonMain/rust/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ pub use android_model_field::*;
mod auth_request;
pub use auth_request::*;

mod continue_watching_item;
pub use continue_watching_item::*;

mod date;
pub use date::*;

Expand Down
17 changes: 12 additions & 5 deletions src/commonMain/rust/model/fields/continue_watching_preview.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use stremio_core::models::continue_watching_preview::ContinueWatchingPreview;
use stremio_core::models::continue_watching_preview::{ContinueWatchingPreview, Item};
use stremio_core::models::ctx::Ctx;

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

impl ToProtobuf<models::ContinueWatchingPreview, ()> for ContinueWatchingPreview {
fn to_protobuf(&self, _args: &()) -> models::ContinueWatchingPreview {
impl ToProtobuf<types::LibraryItem, Ctx> for Item {
fn to_protobuf(&self, ctx: &Ctx) -> types::LibraryItem {
self.library_item.to_protobuf(ctx)
}
}

impl ToProtobuf<models::ContinueWatchingPreview, Ctx> for ContinueWatchingPreview {
fn to_protobuf(&self, ctx: &Ctx) -> models::ContinueWatchingPreview {
models::ContinueWatchingPreview {
items: self.items.to_protobuf(todo!()),
library_items: self.items.to_protobuf(ctx),
}
}
}
7 changes: 4 additions & 3 deletions src/commonMain/rust/model/fields/library.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp;
use std::convert::TryFrom;
use std::num::NonZeroUsize;
use stremio_core::models::ctx::Ctx;

use stremio_core::models::library_with_filters::{
LibraryRequest, LibraryRequestPage, LibraryWithFilters, Selectable, SelectablePage,
Expand Down Expand Up @@ -110,12 +111,12 @@ impl ToProtobuf<models::library_with_filters::Selectable, ()> for Selectable {
}
}

impl<F> ToProtobuf<models::LibraryWithFilters, ()> for LibraryWithFilters<F> {
fn to_protobuf(&self, _args: &()) -> models::LibraryWithFilters {
impl<F> ToProtobuf<models::LibraryWithFilters, Ctx> for LibraryWithFilters<F> {
fn to_protobuf(&self, ctx: &Ctx) -> models::LibraryWithFilters {
models::LibraryWithFilters {
selected: self.selected.to_protobuf(&()),
selectable: self.selectable.to_protobuf(&()),
catalog: self.catalog.to_protobuf(todo!("Args")),
catalog: self.catalog.to_protobuf(ctx),
}
}
}
13 changes: 7 additions & 6 deletions src/commonMain/rust/model/fields/library_by_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use stremio_core::models::ctx::Ctx;
use stremio_core::models::library_by_type::{
Catalog, LibraryByType, Selectable, SelectableSort, Selected,
};
Expand Down Expand Up @@ -42,24 +43,24 @@ impl ToProtobuf<models::library_by_type::Selectable, ()> for Selectable {
}
}

impl ToProtobuf<models::LibraryCatalog, ()> for Catalog {
fn to_protobuf(&self, _args: &()) -> models::LibraryCatalog {
impl ToProtobuf<models::LibraryCatalog, Ctx> for Catalog {
fn to_protobuf(&self, ctx: &Ctx) -> models::LibraryCatalog {
let items = self
.iter()
.flatten()
.map(|item| item.to_protobuf(todo!("Args")))
.map(|item| item.to_protobuf(ctx))
.collect::<Vec<_>>();
let r#type = items.first().map(|item| item.r#type.to_owned());
models::LibraryCatalog { r#type, items }
}
}

impl<F> ToProtobuf<models::LibraryByType, ()> for LibraryByType<F> {
fn to_protobuf(&self, _args: &()) -> models::LibraryByType {
impl<F> ToProtobuf<models::LibraryByType, Ctx> for LibraryByType<F> {
fn to_protobuf(&self, ctx: &Ctx) -> models::LibraryByType {
models::LibraryByType {
selected: self.selected.to_protobuf(&()),
selectable: self.selectable.to_protobuf(&()),
catalogs: self.catalogs.to_protobuf(&()),
catalogs: self.catalogs.to_protobuf(ctx),
}
}
}
4 changes: 2 additions & 2 deletions src/commonMain/rust/model/fields/meta_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl FromProtobuf<Selected> for models::meta_details::Selected {
Selected {
meta_path: self.meta_path.from_protobuf(),
stream_path: self.stream_path.from_protobuf(),
guess_stream: self.guess_stream,
guess_stream: self.guess_stream_path,
}
}
}
Expand All @@ -27,7 +27,7 @@ impl ToProtobuf<models::meta_details::Selected, ()> for Selected {
models::meta_details::Selected {
meta_path: self.meta_path.to_protobuf(&()),
stream_path: self.stream_path.to_protobuf(&()),
guess_stream: self.guess_stream,
guess_stream_path: self.guess_stream,
}
}
}
Expand Down
16 changes: 1 addition & 15 deletions src/commonMain/rust/model/fields/player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use stremio_core::models::ctx::Ctx;
use stremio_core::models::player::{Player, Selected, VideoParams};
use stremio_core::types::streams::StreamsItemKey;

use crate::bridge::{FromProtobuf, ToProtobuf};
use crate::protobuf::stremio::core::models;
Expand Down Expand Up @@ -56,19 +55,6 @@ impl ToProtobuf<models::player::Selected, Ctx> for Selected {

impl ToProtobuf<models::Player, Ctx> for Player {
fn to_protobuf(&self, ctx: &Ctx) -> models::Player {


// let stream_item = ctx.streams.items.get(StreamsItemKey { meta_id: self.selected.map(|selected| selected.meta_request.and_then) ), video_id: () });

// let streaming_server_url = match ctx.streaming_server.base_url.clone() {
// Loadable::Ready(url) => Some(url),
// _ => None,
// };
// let meta_item_id = self.meta_item.map(|meta_item| meta_item.request.path.id.clone());
// let meta_item_id = self.vi.and_then(|meta_item| meta_item.request.path.id.clone());
// let stream_item = ctx.streams.items.get(StreamsItemKey { meta_id: self., video_id: () });


models::Player {
selected: self.selected.to_protobuf(ctx),
video_params: self.video_params.to_protobuf(&()),
Expand All @@ -84,7 +70,7 @@ impl ToProtobuf<models::Player, Ctx> for Player {
None,
)),
series_info: self.series_info.to_protobuf(&()),
library_item: todo!(), //self.library_item.to_protobuf(&()),
library_item: self.library_item.to_protobuf(ctx),
}
}
}
8 changes: 4 additions & 4 deletions src/commonMain/rust/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ impl AndroidModel {
AndroidModelField::AuthLink => self.auth_link.to_protobuf(&()).encode_to_vec(),
AndroidModelField::ContinueWatchingPreview => self
.continue_watching_preview
.to_protobuf(&())
.to_protobuf(&self.ctx)
.encode_to_vec(),
AndroidModelField::Library => self.library.to_protobuf(&()).encode_to_vec(),
AndroidModelField::Library => self.library.to_protobuf(&self.ctx).encode_to_vec(),
AndroidModelField::LibraryByType => {
self.library_by_type.to_protobuf(&()).encode_to_vec()
self.library_by_type.to_protobuf(&self.ctx).encode_to_vec()
}
AndroidModelField::Board => self.board.to_protobuf(&self.ctx).encode_to_vec(),
AndroidModelField::Search => self.search.to_protobuf(&self.ctx).encode_to_vec(),
Expand All @@ -114,4 +114,4 @@ impl AndroidModel {
AndroidModelField::Player => self.player.to_protobuf(&self.ctx).encode_to_vec(),
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@ 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 ContinueWatchingItem items = 1;
repeated stremio.core.types.LibraryItem library_items = 1;
}
2 changes: 1 addition & 1 deletion src/main/proto/stremio/core/models/meta_details.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ message MetaDetails {
message Selected {
required stremio.core.types.ResourcePath meta_path = 1;
optional stremio.core.types.ResourcePath stream_path = 2;
required bool guess_stream = 3;
required bool guess_stream_path = 3;
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/main/proto/stremio/core/runtime/action_player.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ package stremio.core.runtime;
option java_package = "com.stremio.core.runtime.msg";

import "google/protobuf/empty.proto";

import "stremio/core/models/player.proto";

message ActionPlayer {
oneof args {
VideoParamsChanged video_params_changed = 1;
stremio.core.models.Player.VideoParams video_params_changed = 1;
PlayerItemState time_changed = 2;
bool paused_changed = 3;
google.protobuf.Empty ended = 4;
Expand All @@ -21,8 +20,4 @@ message ActionPlayer {
required uint64 duration = 2;
required string device = 3;
}

message VideoParamsChanged {
optional stremio.core.models.Player.VideoParams video_param = 1;
}
}
3 changes: 2 additions & 1 deletion src/main/proto/stremio/core/types/library.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ message LibraryItem {
required LibraryItemState state = 6;
required MetaItemBehaviorHints behavior_hints = 7;
required MetaItemDeepLinks deep_links = 8;
optional double progress = 9;
required double progress = 9;
required bool watched = 10;
required uint64 notifications = 11;
}

message LibraryItemState {
Expand Down

0 comments on commit a418dbe

Please sign in to comment.