From bf1f3575540fd92556c6d407fbe161eaee42cca0 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Fri, 10 Nov 2023 15:15:49 +0200 Subject: [PATCH] bump core again --- Cargo.lock | 6 +- src/commonMain/rust/bridge/action.rs | 14 +++++ src/commonMain/rust/bridge/library_item.rs | 1 + src/commonMain/rust/bridge/loadable.rs | 34 ++++++++++++ .../rust/bridge/resource_loadable.rs | 55 +++++++++++-------- .../rust/model/fields/meta_details.rs | 28 ++-------- .../stremio/core/models/meta_details.proto | 15 ++++- .../stremio/core/runtime/action_ctx.proto | 31 +++++++---- .../stremio/core/runtime/action_load.proto | 2 + .../proto/stremio/core/types/library.proto | 1 + .../proto/stremio/core/types/meta_item.proto | 1 + 11 files changed, 125 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cdac86..be8fb54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2329,7 +2329,7 @@ dependencies = [ [[package]] name = "stremio-core" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?branch=implement-stream-state-management#26593fe6af789505bdfcb64f931e3546ec1e18bc" +source = "git+https://github.com/Stremio/stremio-core?branch=implement-stream-state-management#c2fc12d9a9d3c787d1c594d9a85daa619cb79664" dependencies = [ "anyhow", "base64 0.21.0", @@ -2415,7 +2415,7 @@ dependencies = [ [[package]] name = "stremio-derive" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?branch=implement-stream-state-management#26593fe6af789505bdfcb64f931e3546ec1e18bc" +source = "git+https://github.com/Stremio/stremio-core?branch=implement-stream-state-management#c2fc12d9a9d3c787d1c594d9a85daa619cb79664" dependencies = [ "case", "proc-macro-crate", @@ -2445,7 +2445,7 @@ dependencies = [ [[package]] name = "stremio-watched-bitfield" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?branch=implement-stream-state-management#26593fe6af789505bdfcb64f931e3546ec1e18bc" +source = "git+https://github.com/Stremio/stremio-core?branch=implement-stream-state-management#c2fc12d9a9d3c787d1c594d9a85daa619cb79664" dependencies = [ "base64 0.13.0", "flate2", diff --git a/src/commonMain/rust/bridge/action.rs b/src/commonMain/rust/bridge/action.rs index 7a790e1..1532b55 100644 --- a/src/commonMain/rust/bridge/action.rs +++ b/src/commonMain/rust/bridge/action.rs @@ -31,6 +31,7 @@ impl FromProtobuf for runtime::Action { Some(action_ctx::Args::InstallTraktAddon(_args)) => { Action::Ctx(ActionCtx::InstallTraktAddon) } + Some(action_ctx::Args::LogoutTrakt(_args)) => Action::Ctx(ActionCtx::LogoutTrakt), Some(action_ctx::Args::UpgradeAddon(descriptor)) => { Action::Ctx(ActionCtx::UpgradeAddon(descriptor.from_protobuf())) } @@ -49,6 +50,12 @@ impl FromProtobuf for runtime::Action { Some(action_ctx::Args::RewindLibraryItem(id)) => { Action::Ctx(ActionCtx::RewindLibraryItem(id.to_owned())) } + Some(action_ctx::Args::ToggleLibraryItemNotifications(args)) => Action::Ctx( + ActionCtx::ToggleLibraryItemNotifications(args.id.to_owned(), args.toggle), + ), + Some(action_ctx::Args::DismissNotificationItem(id)) => { + Action::Ctx(ActionCtx::DismissNotificationItem(id.to_owned())) + } Some(action_ctx::Args::PushUserToApi(_args)) => { Action::Ctx(ActionCtx::PushUserToAPI) } @@ -64,6 +71,9 @@ impl FromProtobuf for runtime::Action { Some(action_ctx::Args::SyncLibraryWithApi(_args)) => { Action::Ctx(ActionCtx::SyncLibraryWithAPI) } + Some(action_ctx::Args::PullNotifications(_args)) => { + Action::Ctx(ActionCtx::PullNotifications) + } None => unimplemented!("ActionCtx missing"), }, Some(runtime::action::Type::Link(action_link)) => match &action_link.args { @@ -211,6 +221,10 @@ impl FromProtobuf for runtime::Action { Action::Load(ActionLoad::Player(Box::new(selected.from_protobuf()))) } Some(action_load::Args::Link(_args)) => Action::Load(ActionLoad::Link), + Some(action_load::Args::DataExport(_args)) => Action::Load(ActionLoad::DataExport), + Some(action_load::Args::LocalSearch(_args)) => { + Action::Load(ActionLoad::LocalSearch) + } None => unimplemented!("ActionLoad missing"), }, Some(runtime::action::Type::Unload(_args)) => Action::Unload, diff --git a/src/commonMain/rust/bridge/library_item.rs b/src/commonMain/rust/bridge/library_item.rs index e92aa62..417cd58 100644 --- a/src/commonMain/rust/bridge/library_item.rs +++ b/src/commonMain/rust/bridge/library_item.rs @@ -27,6 +27,7 @@ impl ToProtobuf for LibraryItem { time_offset: self.state.time_offset, duration: self.state.duration, video_id: self.state.video_id.clone(), + no_notif: self.state.no_notif, }, behavior_hints: self.behavior_hints.to_protobuf(&()), deep_links: types::MetaItemDeepLinks { diff --git a/src/commonMain/rust/bridge/loadable.rs b/src/commonMain/rust/bridge/loadable.rs index fbf4be6..fc546f3 100644 --- a/src/commonMain/rust/bridge/loadable.rs +++ b/src/commonMain/rust/bridge/loadable.rs @@ -99,6 +99,40 @@ impl } } +impl + ToProtobuf< + models::loadable_stream::Content, + (&Ctx, &String, &ResourceRequest, Option<&ResourceRequest>), + > for Loadable, ResourceError> +{ + fn to_protobuf( + &self, + (ctx, addon_name, stream_request, meta_request): &( + &Ctx, + &String, + &ResourceRequest, + Option<&ResourceRequest>, + ), + ) -> models::loadable_stream::Content { + match &self { + Loadable::Ready(ready) => { + models::loadable_stream::Content::Ready(models::OptionStream { + stream: ready.to_protobuf(&( + Some(*ctx), + Some(*addon_name), + Some(*stream_request), + *meta_request, + )), + }) + } + Loadable::Err(error) => models::loadable_stream::Content::Error(models::Error { + message: error.to_string(), + }), + Loadable::Loading => models::loadable_stream::Content::Loading(models::Loading {}), + } + } +} + impl ToProtobuf> for Loadable, ResourceError> { diff --git a/src/commonMain/rust/bridge/resource_loadable.rs b/src/commonMain/rust/bridge/resource_loadable.rs index d4c9384..efa9f36 100644 --- a/src/commonMain/rust/bridge/resource_loadable.rs +++ b/src/commonMain/rust/bridge/resource_loadable.rs @@ -5,6 +5,7 @@ use stremio_core::types::addon::{DescriptorPreview, ResourceRequest}; use stremio_core::types::library::LibraryItem; use stremio_core::types::resource::{MetaItem, MetaItemPreview, Stream, Subtitles}; use stremio_watched_bitfield::WatchedBitField; +use url::Url; use crate::bridge::ToProtobuf; use crate::protobuf::stremio::core::models; @@ -54,14 +55,7 @@ impl ToProtobuf, Option<&W &self, (ctx, library_item, watched): &(&Ctx, Option<&LibraryItem>, Option<&WatchedBitField>), ) -> models::LoadableMetaItem { - let addon_name = ctx - .profile - .addons - .iter() - .find(|addon| addon.transport_url == self.request.base) - .map(|addon| &addon.manifest.name) - .cloned() - .unwrap_or_default(); + let addon_name = get_addon_name(ctx, &self.request.base); models::LoadableMetaItem { title: addon_name.to_string(), request: self.request.to_protobuf(&()), @@ -82,14 +76,7 @@ impl ToProtobuf)> &self, (ctx, meta_request): &(&Ctx, Option<&ResourceRequest>), ) -> models::LoadableStreams { - let addon_name = ctx - .profile - .addons - .iter() - .find(|addon| addon.transport_url == self.request.base) - .map(|addon| &addon.manifest.name) - .cloned() - .unwrap_or_default(); + let addon_name = get_addon_name(ctx, &self.request.base); models::LoadableStreams { title: addon_name.to_owned(), request: self.request.to_protobuf(&()), @@ -100,16 +87,26 @@ impl ToProtobuf)> } } +impl ToProtobuf)> + for ResourceLoadable> +{ + fn to_protobuf( + &self, + (ctx, meta_request): &(&Ctx, Option<&ResourceRequest>), + ) -> models::LoadableStream { + let addon_name = get_addon_name(ctx, &self.request.base); + models::LoadableStream { + request: self.request.to_protobuf(&()), + content: self + .content + .to_protobuf(&(ctx, &addon_name, &self.request, *meta_request)), + } + } +} + impl ToProtobuf for ResourceLoadable> { fn to_protobuf(&self, ctx: &Ctx) -> models::LoadableSubtitles { - let addon_name = ctx - .profile - .addons - .iter() - .find(|addon| addon.transport_url == self.request.base) - .map(|addon| &addon.manifest.name) - .cloned() - .unwrap_or_default(); + let addon_name = get_addon_name(ctx, &self.request.base); models::LoadableSubtitles { title: addon_name.to_owned(), request: self.request.to_protobuf(&()), @@ -135,3 +132,13 @@ impl ToProtobuf for DescriptorLoadable { } } } + +fn get_addon_name(ctx: &Ctx, addon_url: &Url) -> String { + ctx.profile + .addons + .iter() + .find(|addon| &addon.transport_url == addon_url) + .map(|addon| &addon.manifest.name) + .cloned() + .unwrap_or_default() +} diff --git a/src/commonMain/rust/model/fields/meta_details.rs b/src/commonMain/rust/model/fields/meta_details.rs index 11057ac..d75513a 100644 --- a/src/commonMain/rust/model/fields/meta_details.rs +++ b/src/commonMain/rust/model/fields/meta_details.rs @@ -1,6 +1,5 @@ use boolinator::Boolinator; use stremio_core::deep_links::MetaItemDeepLinks; -use stremio_core::models::common::Loadable; use stremio_core::models::ctx::Ctx; use stremio_core::models::meta_details::{MetaDetails, Selected}; use stremio_core::runtime::Env; @@ -159,6 +158,9 @@ impl } }), in_library: library_item.map(|item| !item.removed).unwrap_or_default(), + receive_notifications: library_item + .map(|item| !item.state.no_notif) + .unwrap_or_default(), } } } @@ -218,23 +220,6 @@ impl ToProtobuf for MetaDetails { }) .unwrap_or_else(|| meta_item.preview.name.to_owned()) }); - let suggested_stream_request = - self.suggested_stream.as_ref().and_then(|suggested_stream| { - streams - .iter() - .find(|resource| match &resource.content { - Some(Loadable::Ready(streams)) => streams.contains(suggested_stream), - _ => false, - }) - .map(|resource| &resource.request) - }); - let suggested_stream_addon_name = suggested_stream_request.and_then(|stream_request| { - ctx.profile - .addons - .iter() - .find(|addon| addon.transport_url == stream_request.base) - .map(|addon| &addon.manifest.name) - }); models::MetaDetails { selected: self.selected.to_protobuf(&()), title, @@ -244,12 +229,7 @@ impl ToProtobuf for MetaDetails { self.watched.as_ref(), )), streams: streams.to_protobuf(&(ctx, meta_request)), - suggested_stream: self.suggested_stream.to_protobuf(&( - Some(ctx), - suggested_stream_addon_name, - suggested_stream_request, - meta_request, - )), + suggested_stream: self.suggested_stream.to_protobuf(&(ctx, meta_request)), } } } diff --git a/src/main/proto/stremio/core/models/meta_details.proto b/src/main/proto/stremio/core/models/meta_details.proto index 9d32aee..9136b99 100644 --- a/src/main/proto/stremio/core/models/meta_details.proto +++ b/src/main/proto/stremio/core/models/meta_details.proto @@ -14,7 +14,7 @@ message MetaDetails { optional string title = 2; optional LoadableMetaItem meta_item = 3; repeated LoadableStreams streams = 4; - optional stremio.core.types.Stream suggested_stream = 5; + optional LoadableStream suggested_stream = 5; message Selected { required stremio.core.types.ResourcePath meta_path = 1; @@ -45,4 +45,17 @@ message LoadableStreams { message Streams { repeated stremio.core.types.Stream streams = 1; +} + +message LoadableStream { + required stremio.core.types.ResourceRequest request = 1; + oneof content { + Loading loading = 2; + Error error = 3; + OptionStream ready = 4; + } +} + +message OptionStream { + optional stremio.core.types.Stream stream = 1; } \ No newline at end of file diff --git a/src/main/proto/stremio/core/runtime/action_ctx.proto b/src/main/proto/stremio/core/runtime/action_ctx.proto index bf2b650..45b3027 100644 --- a/src/main/proto/stremio/core/runtime/action_ctx.proto +++ b/src/main/proto/stremio/core/runtime/action_ctx.proto @@ -16,16 +16,25 @@ message ActionCtx { google.protobuf.Empty logout = 2; stremio.core.types.Descriptor install_addon = 3; google.protobuf.Empty install_trakt_addon = 4; - stremio.core.types.Descriptor upgrade_addon = 5; - stremio.core.types.Descriptor uninstall_addon = 6; - stremio.core.types.Profile.Settings update_settings = 7; - stremio.core.types.MetaItemPreview add_to_library = 8; - string remove_from_library = 9; - string rewind_library_item = 10; - google.protobuf.Empty push_user_to_api = 11; - google.protobuf.Empty pull_user_from_api = 12; - google.protobuf.Empty push_addons_to_api = 13; - google.protobuf.Empty pull_addons_from_api = 14; - google.protobuf.Empty sync_library_with_api = 15; + google.protobuf.Empty logout_trakt = 5; + stremio.core.types.Descriptor upgrade_addon = 6; + stremio.core.types.Descriptor uninstall_addon = 7; + stremio.core.types.Profile.Settings update_settings = 8; + stremio.core.types.MetaItemPreview add_to_library = 9; + string remove_from_library = 10; + string rewind_library_item = 11; + LibraryItemToggle toggle_library_item_notifications = 12; + string dismiss_notification_item = 13; + google.protobuf.Empty push_user_to_api = 14; + google.protobuf.Empty pull_user_from_api = 15; + google.protobuf.Empty push_addons_to_api = 16; + google.protobuf.Empty pull_addons_from_api = 17; + google.protobuf.Empty sync_library_with_api = 18; + google.protobuf.Empty pull_notifications = 19; + } + + message LibraryItemToggle { + required string id = 1; + required bool toggle = 2; } } \ No newline at end of file diff --git a/src/main/proto/stremio/core/runtime/action_load.proto b/src/main/proto/stremio/core/runtime/action_load.proto index af882a1..22b9124 100644 --- a/src/main/proto/stremio/core/runtime/action_load.proto +++ b/src/main/proto/stremio/core/runtime/action_load.proto @@ -25,5 +25,7 @@ message ActionLoad { stremio.core.models.MetaDetails.Selected meta_details = 7; stremio.core.models.Player.Selected player = 8; google.protobuf.Empty link = 9; + google.protobuf.Empty data_export = 10; + google.protobuf.Empty local_search = 11; } } \ No newline at end of file diff --git a/src/main/proto/stremio/core/types/library.proto b/src/main/proto/stremio/core/types/library.proto index 469248b..a8ad3d8 100644 --- a/src/main/proto/stremio/core/types/library.proto +++ b/src/main/proto/stremio/core/types/library.proto @@ -24,4 +24,5 @@ message LibraryItemState { required uint64 time_offset = 1; required uint64 duration = 2; optional string video_id = 3; + required bool no_notif = 4; } diff --git a/src/main/proto/stremio/core/types/meta_item.proto b/src/main/proto/stremio/core/types/meta_item.proto index 7931ca7..b5f05cb 100644 --- a/src/main/proto/stremio/core/types/meta_item.proto +++ b/src/main/proto/stremio/core/types/meta_item.proto @@ -27,6 +27,7 @@ message MetaItem { required MetaItemDeepLinks deep_links = 16; optional double progress = 17; required bool in_library = 18; + required bool receive_notifications = 19; } enum PosterShape {