From f6ca9858a85adc8674ce808b758e725fb50d3dc3 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 1 Oct 2024 11:55:57 +0300 Subject: [PATCH 1/4] feat: use stremio-core-protobuf from stremio-core-kotlin repo --- Cargo.lock | 69 +++- Cargo.toml | 5 +- src/commonMain/rust/bridge.rs | 31 -- src/commonMain/rust/bridge/action.rs | 259 ------------- src/commonMain/rust/bridge/auth_request.rs | 68 ---- src/commonMain/rust/bridge/date.rs | 19 - src/commonMain/rust/bridge/env_error.rs | 12 - src/commonMain/rust/bridge/event.rs | 235 ----------- src/commonMain/rust/bridge/events.rs | 44 --- src/commonMain/rust/bridge/extra_value.rs | 22 -- src/commonMain/rust/bridge/from_protobuf.rs | 4 - src/commonMain/rust/bridge/library_item.rs | 48 --- src/commonMain/rust/bridge/link.rs | 23 -- src/commonMain/rust/bridge/list.rs | 13 - src/commonMain/rust/bridge/loadable.rs | 364 ------------------ src/commonMain/rust/bridge/manifest.rs | 286 -------------- src/commonMain/rust/bridge/meta_preview.rs | 100 ----- src/commonMain/rust/bridge/option.rs | 13 - src/commonMain/rust/bridge/pair.rs | 11 - src/commonMain/rust/bridge/poster_shape.rs | 24 -- src/commonMain/rust/bridge/profile.rs | 192 --------- .../rust/bridge/resource_loadable.rs | 147 ------- src/commonMain/rust/bridge/resource_path.rs | 26 -- .../rust/bridge/resource_request.rs | 31 -- src/commonMain/rust/bridge/stream.rs | 216 ----------- src/commonMain/rust/bridge/string.rs | 14 - src/commonMain/rust/bridge/subtitle.rs | 23 -- src/commonMain/rust/bridge/to_protobuf.rs | 3 - src/commonMain/rust/lib.rs | 5 +- src/commonMain/rust/model/addons.rs | 61 --- src/commonMain/rust/model/fields.rs | 18 - .../rust/model/fields/addon_detail.rs | 33 -- .../rust/model/fields/addons_with_filters.rs | 130 ------- .../rust/model/fields/catalogs_with_extra.rs | 51 --- .../model/fields/continue_watching_preview.rs | 20 - src/commonMain/rust/model/fields/ctx.rs | 12 - src/commonMain/rust/model/fields/discover.rs | 94 ----- src/commonMain/rust/model/fields/library.rs | 126 ------ .../rust/model/fields/library_by_type.rs | 66 ---- src/commonMain/rust/model/fields/link.rs | 14 - .../rust/model/fields/meta_details.rs | 235 ----------- src/commonMain/rust/model/fields/player.rs | 144 ------- .../rust/model/fields/streaming_server.rs | 115 ------ src/commonMain/rust/model/model.rs | 32 +- 44 files changed, 81 insertions(+), 3377 deletions(-) delete mode 100644 src/commonMain/rust/bridge/action.rs delete mode 100644 src/commonMain/rust/bridge/auth_request.rs delete mode 100644 src/commonMain/rust/bridge/date.rs delete mode 100644 src/commonMain/rust/bridge/env_error.rs delete mode 100644 src/commonMain/rust/bridge/event.rs delete mode 100644 src/commonMain/rust/bridge/events.rs delete mode 100644 src/commonMain/rust/bridge/extra_value.rs delete mode 100644 src/commonMain/rust/bridge/from_protobuf.rs delete mode 100644 src/commonMain/rust/bridge/library_item.rs delete mode 100644 src/commonMain/rust/bridge/link.rs delete mode 100644 src/commonMain/rust/bridge/list.rs delete mode 100644 src/commonMain/rust/bridge/loadable.rs delete mode 100644 src/commonMain/rust/bridge/manifest.rs delete mode 100644 src/commonMain/rust/bridge/meta_preview.rs delete mode 100644 src/commonMain/rust/bridge/option.rs delete mode 100644 src/commonMain/rust/bridge/pair.rs delete mode 100644 src/commonMain/rust/bridge/poster_shape.rs delete mode 100644 src/commonMain/rust/bridge/profile.rs delete mode 100644 src/commonMain/rust/bridge/resource_loadable.rs delete mode 100644 src/commonMain/rust/bridge/resource_path.rs delete mode 100644 src/commonMain/rust/bridge/resource_request.rs delete mode 100644 src/commonMain/rust/bridge/stream.rs delete mode 100644 src/commonMain/rust/bridge/string.rs delete mode 100644 src/commonMain/rust/bridge/subtitle.rs delete mode 100644 src/commonMain/rust/bridge/to_protobuf.rs delete mode 100644 src/commonMain/rust/model/addons.rs delete mode 100644 src/commonMain/rust/model/fields.rs delete mode 100644 src/commonMain/rust/model/fields/addon_detail.rs delete mode 100644 src/commonMain/rust/model/fields/addons_with_filters.rs delete mode 100644 src/commonMain/rust/model/fields/catalogs_with_extra.rs delete mode 100644 src/commonMain/rust/model/fields/continue_watching_preview.rs delete mode 100644 src/commonMain/rust/model/fields/ctx.rs delete mode 100644 src/commonMain/rust/model/fields/discover.rs delete mode 100644 src/commonMain/rust/model/fields/library.rs delete mode 100644 src/commonMain/rust/model/fields/library_by_type.rs delete mode 100644 src/commonMain/rust/model/fields/link.rs delete mode 100644 src/commonMain/rust/model/fields/meta_details.rs delete mode 100644 src/commonMain/rust/model/fields/player.rs delete mode 100644 src/commonMain/rust/model/fields/streaming_server.rs diff --git a/Cargo.lock b/Cargo.lock index 1bc57fc..cec7b46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,9 +322,9 @@ dependencies = [ [[package]] name = "either" -version = "1.13.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "enclose" @@ -594,9 +594,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -624,6 +624,15 @@ dependencies = [ "serde", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.11.0" @@ -1338,7 +1347,7 @@ dependencies = [ [[package]] name = "stremio-core" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?rev=f74c212752443ef625a17d48ce4dc955f2300bc7#f74c212752443ef625a17d48ce4dc955f2300bc7" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/serialize-model-separatelly-from-creating-it#87e12f2d7bf0329f2bf8170f170617e58a2f7a1f" dependencies = [ "anyhow", "base64 0.21.7", @@ -1353,7 +1362,6 @@ dependencies = [ "hex", "http", "itertools 0.11.0", - "lazy_static", "lazysort", "localsearch", "magnet-url", @@ -1380,6 +1388,26 @@ dependencies = [ "url", ] +[[package]] +name = "stremio-core-protobuf" +version = "0.1.0" +source = "git+https://github.com/Stremio/stremio-core-kotlin?branch=feat/improve-imports-and-exports#31bfd9bf797d9f28841d7995a489f5262f092bd3" +dependencies = [ + "Inflector", + "boolinator", + "chrono", + "glob", + "hex", + "prost", + "prost-build", + "prost-types", + "protox", + "semver", + "stremio-core", + "stremio-core-web", + "url", +] + [[package]] name = "stremio-core-swift" version = "1.2.63" @@ -1409,15 +1437,36 @@ dependencies = [ "serde_json", "serde_path_to_error", "stremio-core", + "stremio-core-protobuf", "stremio-watched-bitfield", "tokio", "url", ] +[[package]] +name = "stremio-core-web" +version = "0.47.8" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/serialize-model-separatelly-from-creating-it#87e12f2d7bf0329f2bf8170f170617e58a2f7a1f" +dependencies = [ + "boolinator", + "chrono", + "either", + "enclose", + "futures", + "itertools 0.10.5", + "once_cell", + "semver", + "serde", + "serde_json", + "stremio-core", + "tracing", + "url", +] + [[package]] name = "stremio-derive" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?rev=f74c212752443ef625a17d48ce4dc955f2300bc7#f74c212752443ef625a17d48ce4dc955f2300bc7" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/serialize-model-separatelly-from-creating-it#87e12f2d7bf0329f2bf8170f170617e58a2f7a1f" dependencies = [ "case", "proc-macro-crate", @@ -1451,7 +1500,7 @@ dependencies = [ [[package]] name = "stremio-watched-bitfield" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?rev=f74c212752443ef625a17d48ce4dc955f2300bc7#f74c212752443ef625a17d48ce4dc955f2300bc7" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/serialize-model-separatelly-from-creating-it#87e12f2d7bf0329f2bf8170f170617e58a2f7a1f" dependencies = [ "base64 0.13.1", "flate2", @@ -1680,9 +1729,9 @@ checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "url" -version = "2.5.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", diff --git a/Cargo.toml b/Cargo.toml index c8632a7..17473ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,14 @@ lto = true opt-level = 3 [dependencies] -stremio-core = { git = "https://github.com/Stremio/stremio-core", rev = "f74c212752443ef625a17d48ce4dc955f2300bc7", features = [ +stremio-core = { git = "https://github.com/Stremio/stremio-core", branch = "feat/serialize-model-separatelly-from-creating-it", features = [ "derive", "analytics", "env-future-send", ] } +stremio-core-protobuf = { git = "https://github.com/Stremio/stremio-core-kotlin", branch = "feat/improve-imports-and-exports" } -stremio-watched-bitfield = { git = "https://github.com/Stremio/stremio-core", rev = "f74c212752443ef625a17d48ce4dc955f2300bc7" } +stremio-watched-bitfield = { git = "https://github.com/Stremio/stremio-core", branch = "feat/serialize-model-separatelly-from-creating-it" } serde = "1.0.*" serde_json = "1.0.*" futures = "0.3.*" diff --git a/src/commonMain/rust/bridge.rs b/src/commonMain/rust/bridge.rs index 1429144..c58b5d4 100644 --- a/src/commonMain/rust/bridge.rs +++ b/src/commonMain/rust/bridge.rs @@ -1,33 +1,2 @@ -//! [`ToProtobuf`] and [`FromProtobuf`] impls for various fields -//! -//! [`ToProtobuf`]: crate::bridge::ToProtobuf -//! [`FromProtobuf`]: crate::bridge::FromProtobuf -pub use to_protobuf::*; -pub use from_protobuf::*; -mod action; mod apple_model_field; -mod auth_request; -mod date; -mod env_error; -mod event; -mod events; -mod extra_value; -mod library_item; -mod link; -mod list; -mod loadable; -mod manifest; -mod meta_preview; -mod option; -mod pair; -mod poster_shape; -mod profile; -mod resource_loadable; -mod resource_path; -mod resource_request; -mod stream; -mod string; -mod subtitle; -mod to_protobuf; -mod from_protobuf; diff --git a/src/commonMain/rust/bridge/action.rs b/src/commonMain/rust/bridge/action.rs deleted file mode 100644 index 010a4de..0000000 --- a/src/commonMain/rust/bridge/action.rs +++ /dev/null @@ -1,259 +0,0 @@ -use std::ops::Range; - -use stremio_core::runtime::msg::{ - Action, ActionCatalogWithFilters, ActionCatalogsWithExtra, ActionCtx, ActionLibraryByType, - ActionLink, ActionLoad, ActionMetaDetails, ActionPlayer, ActionStreamingServer, - CreateTorrentArgs, PlayOnDeviceArgs, -}; -use stremio_core::runtime::RuntimeAction; - -use crate::bridge::FromProtobuf; -use crate::env::AppleEnv; -use crate::model::AppleModel; -use crate::protobuf::stremio::core::runtime; -use crate::protobuf::stremio::core::runtime::{ - action_catalog_with_filters, action_catalogs_with_extra, action_ctx, action_library_by_type, - action_link, action_load, action_meta_details, action_player, action_streaming_server, - create_torrent_args, Field, -}; - -impl FromProtobuf for runtime::Action { - fn from_protobuf(&self) -> Action { - match &self.r#type { - Some(runtime::action::Type::Ctx(action_ctx)) => match &action_ctx.args { - Some(action_ctx::Args::Authenticate(auth_request)) => { - Action::Ctx(ActionCtx::Authenticate(auth_request.from_protobuf())) - } - Some(action_ctx::Args::Logout(_args)) => Action::Ctx(ActionCtx::Logout), - Some(action_ctx::Args::InstallAddon(descriptor)) => { - Action::Ctx(ActionCtx::InstallAddon(descriptor.from_protobuf())) - } - 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())) - } - Some(action_ctx::Args::UninstallAddon(descriptor)) => { - Action::Ctx(ActionCtx::UninstallAddon(descriptor.from_protobuf())) - } - Some(action_ctx::Args::UpdateSettings(settings)) => { - Action::Ctx(ActionCtx::UpdateSettings(settings.from_protobuf())) - } - Some(action_ctx::Args::AddToLibrary(meta_item_preview)) => { - Action::Ctx(ActionCtx::AddToLibrary(meta_item_preview.from_protobuf())) - } - Some(action_ctx::Args::RemoveFromLibrary(id)) => { - Action::Ctx(ActionCtx::RemoveFromLibrary(id.to_owned())) - } - Some(action_ctx::Args::RewindLibraryItem(id)) => { - Action::Ctx(ActionCtx::RewindLibraryItem(id.to_owned())) - } - Some(action_ctx::Args::LibraryItemMarkAsWatched(args)) => { - Action::Ctx(ActionCtx::LibraryItemMarkAsWatched { - id: args.id.to_owned(), - is_watched: args.is_watched, - }) - } - 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) - } - Some(action_ctx::Args::PullUserFromApi(_args)) => { - Action::Ctx(ActionCtx::PullUserFromAPI) - } - Some(action_ctx::Args::PushAddonsToApi(_args)) => { - Action::Ctx(ActionCtx::PushAddonsToAPI) - } - Some(action_ctx::Args::PullAddonsFromApi(_args)) => { - Action::Ctx(ActionCtx::PullAddonsFromAPI) - } - Some(action_ctx::Args::SyncLibraryWithApi(_args)) => { - Action::Ctx(ActionCtx::SyncLibraryWithAPI) - } - Some(action_ctx::Args::PullNotifications(_args)) => { - Action::Ctx(ActionCtx::PullNotifications) - } - Some(action_ctx::Args::GetEvents(_args)) => Action::Ctx(ActionCtx::GetEvents), - Some(action_ctx::Args::DismissEvent(id)) => { - Action::Ctx(ActionCtx::DismissEvent(id.to_owned())) - } - None => unimplemented!("ActionCtx missing"), - }, - Some(runtime::action::Type::Link(action_link)) => match &action_link.args { - Some(action_link::Args::ReadData(_args)) => Action::Link(ActionLink::ReadData), - None => unimplemented!("ActionLink missing"), - }, - Some(runtime::action::Type::CatalogWithFilters(action_catalog)) => { - match &action_catalog.args { - Some(action_catalog_with_filters::Args::LoadNextPage(_args)) => { - Action::CatalogWithFilters(ActionCatalogWithFilters::LoadNextPage) - } - None => unimplemented!("ActionCatalogWithFilters missing"), - } - } - Some(runtime::action::Type::CatalogsWithExtra(action_catalog)) => { - match &action_catalog.args { - Some(action_catalogs_with_extra::Args::LoadRange(range)) => { - Action::CatalogsWithExtra(ActionCatalogsWithExtra::LoadRange(Range { - start: range.start as usize, - end: range.end as usize, - })) - } - Some(action_catalogs_with_extra::Args::LoadNextPage(index)) => { - Action::CatalogsWithExtra(ActionCatalogsWithExtra::LoadNextPage( - *index as usize, - )) - } - None => unimplemented!("ActionCatalogsWithExtra missing"), - } - } - Some(runtime::action::Type::LibraryByType(action_library_by_type)) => { - match &action_library_by_type.args { - Some(action_library_by_type::Args::LoadNextPage(index)) => { - Action::LibraryByType(ActionLibraryByType::LoadNextPage(*index as usize)) - } - None => unimplemented!("ActionLibraryByType missing"), - } - } - Some(runtime::action::Type::MetaDetails(action_meta_details)) => { - match &action_meta_details.args { - Some(action_meta_details::Args::MarkAsWatched(watched)) => { - Action::MetaDetails(ActionMetaDetails::MarkAsWatched(*watched)) - } - Some(action_meta_details::Args::MarkVideoAsWatched(video_state)) => { - Action::MetaDetails(ActionMetaDetails::MarkVideoAsWatched( - video_state.video.from_protobuf(), - video_state.is_watched, - )) - } - None => unimplemented!("ActionMetaDetails missing"), - } - } - Some(runtime::action::Type::StreamingServer(action_streaming_server)) => { - match &action_streaming_server.args { - Some(action_streaming_server::Args::Reload(_args)) => { - Action::StreamingServer(ActionStreamingServer::Reload) - } - Some(action_streaming_server::Args::UpdateSettings(settings)) => { - Action::StreamingServer(ActionStreamingServer::UpdateSettings( - settings.from_protobuf(), - )) - } - Some(action_streaming_server::Args::CreateTorrent(create_args)) => { - match &create_args.args { - Some(create_torrent_args::Args::File(file)) => { - Action::StreamingServer(ActionStreamingServer::CreateTorrent( - CreateTorrentArgs::File(file.to_owned()), - )) - } - Some(create_torrent_args::Args::Magnet(magnet)) => { - Action::StreamingServer(ActionStreamingServer::CreateTorrent( - CreateTorrentArgs::Magnet(magnet.from_protobuf()), - )) - } - None => unimplemented!("CreateTorrentArgs missing"), - } - } - Some(action_streaming_server::Args::PlayOnDevice(args)) => { - Action::StreamingServer(ActionStreamingServer::PlayOnDevice( - PlayOnDeviceArgs { - device: args.device.to_string(), - source: args.source.to_string(), - time: args.time.map(|x| x as u64).to_owned(), - }, - )) - } - Some(action_streaming_server::Args::GetStatistics(request)) => { - Action::StreamingServer(ActionStreamingServer::GetStatistics( - request.from_protobuf(), - )) - } - None => unimplemented!("ActionStreamingServer missing"), - } - } - Some(runtime::action::Type::Player(action_player)) => match &action_player.args { - Some(action_player::Args::VideoParamsChanged(video_params)) => { - Action::Player(ActionPlayer::VideoParamsChanged { - video_params: Some(video_params.from_protobuf()), - }) - } - Some(action_player::Args::StreamStateChanged(stream_state)) => { - Action::Player(ActionPlayer::StreamStateChanged { - state: stream_state.from_protobuf(), - }) - } - Some(action_player::Args::TimeChanged(item_state)) => { - Action::Player(ActionPlayer::TimeChanged { - time: item_state.time, - duration: item_state.duration, - device: item_state.device.to_owned(), - }) - } - Some(action_player::Args::PausedChanged(paused)) => { - Action::Player(ActionPlayer::PausedChanged { paused: *paused }) - } - Some(action_player::Args::NextVideo(_args)) => { - Action::Player(ActionPlayer::NextVideo {}) - } - Some(action_player::Args::Ended(_args)) => Action::Player(ActionPlayer::Ended {}), - None => unimplemented!("ActionLink missing"), - }, - Some(runtime::action::Type::Load(action_load)) => match &action_load.args { - Some(action_load::Args::AddonDetails(selected)) => { - Action::Load(ActionLoad::AddonDetails(selected.from_protobuf())) - } - Some(action_load::Args::CatalogsWithExtra(selected)) => { - Action::Load(ActionLoad::CatalogsWithExtra(selected.from_protobuf())) - } - Some(action_load::Args::CatalogWithFilters(selected)) => Action::Load( - ActionLoad::CatalogWithFilters(Some(selected.from_protobuf())), - ), - Some(action_load::Args::AddonsWithFilters(selected)) => { - Action::Load(match selected.request.base.is_empty() { - true => ActionLoad::InstalledAddonsWithFilters(selected.from_protobuf()), - _ => ActionLoad::CatalogWithFilters(Some(selected.from_protobuf())), - }) - } - Some(action_load::Args::LibraryWithFilters(selected)) => { - Action::Load(ActionLoad::LibraryWithFilters(selected.from_protobuf())) - } - Some(action_load::Args::LibraryByType(selected)) => { - Action::Load(ActionLoad::LibraryByType(selected.from_protobuf())) - } - Some(action_load::Args::MetaDetails(selected)) => { - Action::Load(ActionLoad::MetaDetails(selected.from_protobuf())) - } - Some(action_load::Args::Player(selected)) => { - 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, - None => unimplemented!("Action missing"), - } - } -} - -impl FromProtobuf> for runtime::RuntimeAction { - fn from_protobuf(&self) -> RuntimeAction { - RuntimeAction { - field: self - .field - .and_then(|value| Field::try_from(value).ok()) - .from_protobuf(), - action: self.action.from_protobuf(), - } - } -} diff --git a/src/commonMain/rust/bridge/auth_request.rs b/src/commonMain/rust/bridge/auth_request.rs deleted file mode 100644 index e1829fa..0000000 --- a/src/commonMain/rust/bridge/auth_request.rs +++ /dev/null @@ -1,68 +0,0 @@ -use stremio_core::types::api::AuthRequest; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::AuthRequest { - fn from_protobuf(&self) -> AuthRequest { - match &self.r#type { - Some(types::auth_request::Type::Login(login)) => AuthRequest::Login { - email: login.email.to_owned(), - password: login.password.to_owned(), - facebook: login.facebook.to_owned(), - }, - Some(types::auth_request::Type::LoginWithToken(login_with_token)) => { - AuthRequest::LoginWithToken { - token: login_with_token.token.to_owned(), - } - } - Some(types::auth_request::Type::Facebook(facebook)) => AuthRequest::Facebook { - token: facebook.token.to_owned(), - }, - Some(types::auth_request::Type::Register(register)) => AuthRequest::Register { - email: register.email.to_owned(), - password: register.password.to_owned(), - gdpr_consent: register.gdpr_consent.from_protobuf(), - }, - None => unimplemented!("AuthRequest must be present"), - } - } -} - -impl ToProtobuf for AuthRequest { - fn to_protobuf(&self, _args: &()) -> types::AuthRequest { - let request = match self { - AuthRequest::Login { - email, - password, - facebook, - } => types::auth_request::Type::Login(types::auth_request::Login { - email: email.to_owned(), - password: password.to_owned(), - facebook: facebook.to_owned(), - }), - AuthRequest::LoginWithToken { token } => { - types::auth_request::Type::LoginWithToken(types::auth_request::LoginWithToken { - token: token.to_owned(), - }) - } - AuthRequest::Facebook { token } => { - types::auth_request::Type::Facebook(types::auth_request::Facebook { - token: token.to_owned(), - }) - } - AuthRequest::Register { - email, - password, - gdpr_consent, - } => types::auth_request::Type::Register(types::auth_request::Register { - email: email.to_owned(), - password: password.to_owned(), - gdpr_consent: gdpr_consent.to_protobuf(&()), - }), - }; - types::AuthRequest { - r#type: Some(request), - } - } -} diff --git a/src/commonMain/rust/bridge/date.rs b/src/commonMain/rust/bridge/date.rs deleted file mode 100644 index 3340663..0000000 --- a/src/commonMain/rust/bridge/date.rs +++ /dev/null @@ -1,19 +0,0 @@ -use chrono::{DateTime, TimeZone, Utc}; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::google::protobuf::Timestamp; - -impl FromProtobuf> for Timestamp { - fn from_protobuf(&self) -> DateTime { - Utc.timestamp_opt(self.seconds, self.nanos as u32).unwrap() - } -} - -impl ToProtobuf for DateTime { - fn to_protobuf(&self, _args: &()) -> Timestamp { - Timestamp { - seconds: self.timestamp(), - nanos: self.timestamp_subsec_nanos() as i32, - } - } -} diff --git a/src/commonMain/rust/bridge/env_error.rs b/src/commonMain/rust/bridge/env_error.rs deleted file mode 100644 index 0b68e74..0000000 --- a/src/commonMain/rust/bridge/env_error.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::runtime; -use stremio_core::runtime::EnvError; - -impl ToProtobuf for EnvError { - fn to_protobuf(&self, _args: &()) -> runtime::EnvError { - runtime::EnvError { - code: self.code() as i32, - message: self.message(), - } - } -} diff --git a/src/commonMain/rust/bridge/event.rs b/src/commonMain/rust/bridge/event.rs deleted file mode 100644 index b11a2f8..0000000 --- a/src/commonMain/rust/bridge/event.rs +++ /dev/null @@ -1,235 +0,0 @@ -use stremio_core::models::ctx::CtxError; -use stremio_core::runtime::msg::Event; -use stremio_core::runtime::RuntimeEvent; - -use crate::bridge::ToProtobuf; -use crate::env::AppleEnv; -use crate::model::AppleModel; -use crate::protobuf::stremio::core::runtime; - -impl ToProtobuf for Event { - fn to_protobuf(&self, _args: &()) -> runtime::Event { - let event = match self { - Event::ProfilePushedToStorage { uid } => runtime::event::Type::ProfilePushedToStorage( - runtime::event::ProfilePushedToStorage { uid: uid.clone() }, - ), - Event::LibraryItemsPushedToStorage { ids } => { - runtime::event::Type::LibraryItemsPushedToStorage( - runtime::event::LibraryItemsPushedToStorage { ids: ids.clone() }, - ) - } - Event::StreamsPushedToStorage { uid } => runtime::event::Type::StreamsPushedToStorage( - runtime::event::StreamsPushedToStorage { uid: uid.clone() }, - ), - Event::SearchHistoryPushedToStorage { uid } => { - runtime::event::Type::SearchHistoryPushedToStorage( - runtime::event::SearchHistoryPushedToStorage { uid: uid.clone() }, - ) - } - Event::NotificationsPushedToStorage { ids } => { - runtime::event::Type::NotificationsPushedToStorage( - runtime::event::NotificationsPushedToStorage { ids: ids.clone() }, - ) - } - Event::DismissedEventsPushedToStorage { uid } => { - runtime::event::Type::DismissedEventsPushedToStorage( - runtime::event::DismissedEventsPushedToStorage { uid: uid.clone() }, - ) - } - Event::UserPulledFromAPI { uid } => { - runtime::event::Type::UserPulledFromApi(runtime::event::UserPulledFromApi { - uid: uid.clone(), - }) - } - Event::UserPushedToAPI { uid } => { - runtime::event::Type::UserPushedToApi(runtime::event::UserPushedToApi { - uid: uid.clone(), - }) - } - Event::AddonsPulledFromAPI { transport_urls } => { - runtime::event::Type::AddonsPulledFromApi(runtime::event::AddonsPulledFromApi { - transport_urls: transport_urls.to_protobuf(&()), - }) - } - Event::AddonsPushedToAPI { transport_urls } => { - runtime::event::Type::AddonsPushedToApi(runtime::event::AddonsPushedToApi { - transport_urls: transport_urls.to_protobuf(&()), - }) - } - Event::UserAuthenticated { auth_request } => { - runtime::event::Type::UserAuthenticated(runtime::event::UserAuthenticated { - auth_request: auth_request.to_protobuf(&()), - }) - } - Event::UserAddonsLocked { addons_locked } => { - runtime::event::Type::UserAddonsLocked(runtime::event::UserAddonsLocked { - addons_locked: *addons_locked, - }) - } - Event::UserLibraryMissing { library_missing } => { - runtime::event::Type::UserLibraryMissing(runtime::event::UserLibraryMissing { - library_missing: *library_missing, - }) - } - Event::UserLoggedOut { uid } => { - runtime::event::Type::UserLoggedOut(runtime::event::UserLoggedOut { - uid: uid.clone(), - }) - } - Event::SessionDeleted { auth_key } => { - runtime::event::Type::SessionDeleted(runtime::event::SessionDeleted { - auth_key: auth_key.0.to_owned(), - }) - } - Event::TraktAddonFetched { uid } => { - runtime::event::Type::TraktAddonFetched(runtime::event::TraktAddonFetched { - uid: uid.clone(), - }) - } - Event::TraktLoggedOut { uid } => { - runtime::event::Type::TraktLoggedOut(runtime::event::TraktLoggedOut { - uid: uid.clone(), - }) - } - Event::AddonInstalled { transport_url, id } => { - runtime::event::Type::AddonInstalled(runtime::event::AddonInstalled { - transport_url: transport_url.to_string(), - id: id.to_owned(), - }) - } - Event::AddonUpgraded { transport_url, id } => { - runtime::event::Type::AddonUpgraded(runtime::event::AddonUpgraded { - transport_url: transport_url.to_string(), - id: id.to_owned(), - }) - } - Event::AddonUninstalled { transport_url, id } => { - runtime::event::Type::AddonUninstalled(runtime::event::AddonUninstalled { - transport_url: transport_url.to_string(), - id: id.to_owned(), - }) - } - Event::LibraryItemAdded { id } => { - runtime::event::Type::LibraryItemAdded(runtime::event::LibraryItemAdded { - id: id.to_owned(), - }) - } - Event::LibraryItemRemoved { id } => { - runtime::event::Type::LibraryItemRemoved(runtime::event::LibraryItemRemoved { - id: id.to_owned(), - }) - } - Event::LibraryItemRewinded { id } => { - runtime::event::Type::LibraryItemRewinded(runtime::event::LibraryItemRewinded { - id: id.to_owned(), - }) - } - Event::LibraryItemNotificationsToggled { id } => { - runtime::event::Type::LibraryItemNotificationsToggled( - runtime::event::LibraryItemNotificationsToggled { id: id.clone() }, - ) - } - Event::LibraryItemMarkedAsWatched { id, is_watched } => { - runtime::event::Type::LibraryItemMarkedAsWatched( - runtime::event::LibraryItemMarkedAsWatched { - id: id.clone(), - is_watched: *is_watched, - }, - ) - } - Event::NotificationsDismissed { id } => runtime::event::Type::NotificationsDismissed( - runtime::event::NotificationsDismissed { id: id.clone() }, - ), - Event::LibrarySyncWithAPIPlanned { uid, plan } => { - runtime::event::Type::LibrarySyncWithApiPlanned( - runtime::event::LibrarySyncWithApiPlanned { - uid: uid.clone(), - plan: plan.to_protobuf(&()), - }, - ) - } - Event::LibraryItemsPushedToAPI { ids } => { - runtime::event::Type::LibraryItemsPushedToApi( - runtime::event::LibraryItemsPushedToApi { ids: ids.clone() }, - ) - } - Event::LibraryItemsPulledFromAPI { ids } => { - runtime::event::Type::LibraryItemsPulledFromApi( - runtime::event::LibraryItemsPulledFromApi { ids: ids.clone() }, - ) - } - Event::SettingsUpdated { settings } => { - runtime::event::Type::SettingsUpdated(runtime::event::SettingsUpdated { - settings: settings.to_protobuf(&()), - }) - } - Event::PlayerPlaying { .. } => { - runtime::event::Type::PlayerPlaying(runtime::event::PlayerPlaying {}) - } - Event::PlayerStopped { .. } => { - runtime::event::Type::PlayerStopped(runtime::event::PlayerStopped {}) - } - Event::PlayerNextVideo { .. } => { - runtime::event::Type::PlayerNextVideo(runtime::event::PlayerNextVideo {}) - } - Event::PlayerEnded { .. } => { - runtime::event::Type::PlayerEnded(runtime::event::PlayerEnded {}) - } - Event::TraktPlaying { .. } => { - runtime::event::Type::TraktPlaying(runtime::event::TraktPlaying {}) - } - Event::TraktPaused { .. } => { - runtime::event::Type::TraktPaused(runtime::event::TraktPaused {}) - } - Event::MagnetParsed { magnet } => { - runtime::event::Type::MagnetParsed(runtime::event::MagnetParsed { - magnet: magnet.to_protobuf(&()), - }) - } - Event::TorrentParsed { torrent } => { - runtime::event::Type::TorrentParsed(runtime::event::TorrentParsed { - torrent: torrent.to_owned(), - }) - } - Event::PlayingOnDevice { device } => { - runtime::event::Type::PlayingOnDevice(runtime::event::PlayingOnDevice { - device: device.to_owned(), - }) - } - Event::Error { error, source } => { - let error = match error { - CtxError::API(error) => error.message.to_owned(), - CtxError::Env(error) => error.message(), - CtxError::Other(error) => error.message(), - }; - runtime::event::Type::Error(Box::from(runtime::event::Error { - error, - source: Box::from(source.to_protobuf(&())), - })) - } - }; - runtime::Event { - r#type: Some(event), - } - } -} - -impl ToProtobuf for RuntimeEvent { - fn to_protobuf(&self, _args: &()) -> runtime::RuntimeEvent { - let event = match self { - RuntimeEvent::NewState(fields, ..) => { - runtime::runtime_event::Event::NewState(runtime::runtime_event::NewState { - fields: fields - .to_protobuf(&()) - .iter() - .map(|field| *field as i32) - .collect(), - }) - } - RuntimeEvent::CoreEvent(event) => { - runtime::runtime_event::Event::CoreEvent(event.to_protobuf(&())) - } - }; - runtime::RuntimeEvent { event: Some(event) } - } -} diff --git a/src/commonMain/rust/bridge/events.rs b/src/commonMain/rust/bridge/events.rs deleted file mode 100644 index 378b6f1..0000000 --- a/src/commonMain/rust/bridge/events.rs +++ /dev/null @@ -1,44 +0,0 @@ -use stremio_core::types::api::{GetModalResponse, GetNotificationResponse}; -use stremio_core::types::events::Events; - -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::models; - -impl ToProtobuf for Events { - fn to_protobuf(&self, _args: &()) -> models::Events { - models::Events { - modal: self.modal.to_protobuf(&()), - notification: self.notification.to_protobuf(&()), - } - } -} - -impl ToProtobuf for GetModalResponse { - fn to_protobuf(&self, _args: &()) -> models::EventModal { - models::EventModal { - id: self.id.to_owned(), - title: self.title.to_owned(), - message: self.message.to_owned(), - image_url: self.image_url.to_protobuf(&()), - addon: self - .addon - .as_ref() - .map(|addon| models::event_modal::ModalAddon { - manifest_url: addon.manifest_url.to_protobuf(&()), - name: addon.name.to_owned(), - }), - external_url: self.external_url.to_protobuf(&()), - } - } -} - -impl ToProtobuf for GetNotificationResponse { - fn to_protobuf(&self, _args: &()) -> models::EventNotification { - models::EventNotification { - id: self.id.to_owned(), - title: self.title.to_owned(), - message: self.message.to_owned(), - external_url: self.external_url.to_protobuf(&()), - } - } -} diff --git a/src/commonMain/rust/bridge/extra_value.rs b/src/commonMain/rust/bridge/extra_value.rs deleted file mode 100644 index 288d3a9..0000000 --- a/src/commonMain/rust/bridge/extra_value.rs +++ /dev/null @@ -1,22 +0,0 @@ -use stremio_core::types::addon::ExtraValue; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::ExtraValue { - fn from_protobuf(&self) -> ExtraValue { - ExtraValue { - name: self.name.to_owned(), - value: self.value.to_owned(), - } - } -} - -impl ToProtobuf for ExtraValue { - fn to_protobuf(&self, _args: &()) -> types::ExtraValue { - types::ExtraValue { - name: self.name.to_owned(), - value: self.value.to_owned(), - } - } -} diff --git a/src/commonMain/rust/bridge/from_protobuf.rs b/src/commonMain/rust/bridge/from_protobuf.rs deleted file mode 100644 index 36f4454..0000000 --- a/src/commonMain/rust/bridge/from_protobuf.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub trait FromProtobuf { - #[allow(clippy::wrong_self_convention)] - fn from_protobuf(&self) -> T; -} diff --git a/src/commonMain/rust/bridge/library_item.rs b/src/commonMain/rust/bridge/library_item.rs deleted file mode 100644 index 1f78a31..0000000 --- a/src/commonMain/rust/bridge/library_item.rs +++ /dev/null @@ -1,48 +0,0 @@ -use stremio_core::deep_links::LibraryItemDeepLinks; -use stremio_core::models::ctx::Ctx; -use stremio_core::types::library::LibraryItem; - -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::types; - -impl ToProtobuf)> for LibraryItem { - fn to_protobuf( - &self, - (ctx, maybe_notifications): &(&Ctx, Option), - ) -> types::LibraryItem { - let notifications = maybe_notifications - .or_else(|| { - 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(), - name: self.name.to_string(), - poster: self.poster.to_protobuf(&()), - poster_shape: self.poster_shape.to_protobuf(&()) as i32, - state: types::LibraryItemState { - 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 { - meta_details_videos: deep_links.meta_details_videos, - meta_details_streams: deep_links.meta_details_streams, - player: deep_links.player, - }, - progress: self.progress(), - watched: self.state.times_watched > 0, - notifications: notifications as u64, - } - } -} diff --git a/src/commonMain/rust/bridge/link.rs b/src/commonMain/rust/bridge/link.rs deleted file mode 100644 index 60481d7..0000000 --- a/src/commonMain/rust/bridge/link.rs +++ /dev/null @@ -1,23 +0,0 @@ -use stremio_core::types::resource::Link; - -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::types; - -impl ToProtobuf for Link { - fn to_protobuf(&self, _args: &()) -> types::LinkPreview { - types::LinkPreview { - name: self.name.to_string(), - category: self.category.to_string(), - } - } -} - -impl ToProtobuf for Link { - fn to_protobuf(&self, _args: &()) -> types::Link { - types::Link { - name: self.name.to_string(), - category: self.category.to_string(), - url: self.url.to_string(), - } - } -} diff --git a/src/commonMain/rust/bridge/list.rs b/src/commonMain/rust/bridge/list.rs deleted file mode 100644 index d7ad8a3..0000000 --- a/src/commonMain/rust/bridge/list.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate::bridge::{FromProtobuf, ToProtobuf}; - -impl, U> FromProtobuf> for Vec { - fn from_protobuf(&self) -> Vec { - self.iter().map(|item| item.from_protobuf()).collect() - } -} - -impl, U, A> ToProtobuf, A> for Vec { - fn to_protobuf(&self, args: &A) -> Vec { - self.iter().map(|item| item.to_protobuf(args)).collect() - } -} diff --git a/src/commonMain/rust/bridge/loadable.rs b/src/commonMain/rust/bridge/loadable.rs deleted file mode 100644 index 7c345d5..0000000 --- a/src/commonMain/rust/bridge/loadable.rs +++ /dev/null @@ -1,364 +0,0 @@ -use itertools::Itertools; -use stremio_core::deep_links::MetaItemDeepLinks; -use stremio_core::models::common::{Loadable, ResourceError}; -use stremio_core::models::ctx::{Ctx, CtxError}; -use stremio_core::models::link::LinkError; -use stremio_core::models::streaming_server::PlaybackDevice; -use stremio_core::runtime::EnvError; -use stremio_core::types::addon::{Descriptor, DescriptorPreview, ResourcePath, ResourceRequest}; -use stremio_core::types::api::{ - GetModalResponse, GetNotificationResponse, LinkAuthKey, LinkCodeResponse, -}; -use stremio_core::types::library::LibraryItem; -use stremio_core::types::resource::{MetaItem, MetaItemPreview, Stream, Subtitles}; -use stremio_core::types::streaming_server::{Settings, Statistics}; -use stremio_watched_bitfield::WatchedBitField; -use url::Url; - -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::models; -use crate::protobuf::stremio::core::models::{LoadedModal, LoadedNotification, PlaybackDevices}; - -impl ToProtobuf - for Loadable, ResourceError> -{ - fn to_protobuf( - &self, - (ctx, request): &(&Ctx, &ResourceRequest), - ) -> models::loadable_page::Content { - match &self { - Loadable::Ready(ready) => models::loadable_page::Content::Ready(models::Page { - meta_items: ready - .iter() - .unique_by(|meta_item| &meta_item.id) - .map(|meta_item| meta_item.to_owned()) - .collect_vec() - .to_protobuf(&(*ctx, *request)), - }), - Loadable::Err(error) => models::loadable_page::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_page::Content::Loading(models::Loading {}), - } - } -} - -impl - ToProtobuf< - models::loadable_meta_item::Content, - ( - Option<&LibraryItem>, - Option<&WatchedBitField>, - Option<&String>, - &ResourceRequest, - ), - > for Loadable -{ - fn to_protobuf( - &self, - (library_item, watched, addon_name, meta_request): &( - 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(&(*library_item, *watched, *addon_name, *meta_request)), - ), - Loadable::Err(error) => models::loadable_meta_item::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_meta_item::Content::Loading(models::Loading {}), - } - } -} - -impl - ToProtobuf< - models::loadable_streams::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_streams::Content { - match &self { - Loadable::Ready(ready) => models::loadable_streams::Content::Ready(models::Streams { - streams: ready.to_protobuf(&( - Some(*ctx), - Some(*addon_name), - Some(*stream_request), - *meta_request, - )), - }), - Loadable::Err(error) => models::loadable_streams::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_streams::Content::Loading(models::Loading {}), - } - } -} - -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> -{ - fn to_protobuf(&self, addon_name: &Option<&String>) -> models::loadable_subtitles::Content { - match &self { - Loadable::Ready(ready) => { - models::loadable_subtitles::Content::Ready(models::Subtitles { - subtitles: ready.to_protobuf(addon_name), - }) - } - Loadable::Err(error) => models::loadable_subtitles::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_subtitles::Content::Loading(models::Loading {}), - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, _args: &()) -> models::LoadableSettings { - let content = match &self { - Loadable::Ready(ready) => { - models::loadable_settings::Content::Ready(ready.to_protobuf(&())) - } - Loadable::Err(error) => models::loadable_settings::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_settings::Content::Loading(models::Loading {}), - }; - models::LoadableSettings { - content: Some(content), - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, _args: &()) -> models::LoadableBaseUrl { - let content = match &self { - Loadable::Ready(ready) => models::loadable_base_url::Content::Ready(ready.to_string()), - Loadable::Err(error) => models::loadable_base_url::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_base_url::Content::Loading(models::Loading {}), - }; - models::LoadableBaseUrl { - content: Some(content), - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, _args: &()) -> models::LoadableCode { - let content = match &self { - Loadable::Ready(ready) => models::loadable_code::Content::Ready(ready.to_protobuf(&())), - Loadable::Err(error) => models::loadable_code::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_code::Content::Loading(models::Loading {}), - }; - models::LoadableCode { - content: Some(content), - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, _args: &()) -> models::LoadableAuthKey { - let content = match &self { - Loadable::Ready(ready) => { - models::loadable_auth_key::Content::Ready(ready.to_protobuf(&())) - } - Loadable::Err(error) => models::loadable_auth_key::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_auth_key::Content::Loading(models::Loading {}), - }; - models::LoadableAuthKey { - content: Some(content), - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, _args: &()) -> models::LoadableTorrent { - let content = match &self { - Loadable::Ready(ready) => { - let deeplinks = MetaItemDeepLinks::from(ready).to_protobuf(&()); - models::loadable_torrent::Deeplinks::Ready(deeplinks) - } - Loadable::Err(error) => models::loadable_torrent::Deeplinks::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_torrent::Deeplinks::Loading(models::Loading {}), - }; - models::LoadableTorrent { - deeplinks: Some(content), - } - } -} - -impl ToProtobuf for Loadable, EnvError> { - fn to_protobuf(&self, _args: &()) -> models::LoadablePlaybackDevices { - let content = match &self { - Loadable::Ready(ready) => { - models::loadable_playback_devices::Content::Ready(PlaybackDevices { - devices: ready.to_protobuf(&()), - }) - } - Loadable::Err(error) => { - models::loadable_playback_devices::Content::Error(models::Error { - message: error.to_string(), - }) - } - Loadable::Loading => { - models::loadable_playback_devices::Content::Loading(models::Loading {}) - } - }; - models::LoadablePlaybackDevices { - content: Some(content), - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, _args: &()) -> models::LoadableStatistics { - let content = match &self { - Loadable::Ready(ready) => { - models::loadable_statistics::Content::Ready(ready.to_protobuf(&())) - } - Loadable::Err(error) => models::loadable_statistics::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_statistics::Content::Loading(models::Loading {}), - }; - models::LoadableStatistics { - content: Some(content), - } - } -} - -impl ToProtobuf - for Loadable, ResourceError> -{ - fn to_protobuf(&self, ctx: &Ctx) -> models::loadable_addon_catalog::Content { - match &self { - Loadable::Ready(ready) => { - models::loadable_addon_catalog::Content::Ready(models::Addons { - items: ready.to_protobuf(ctx), - }) - } - Loadable::Err(error) => models::loadable_addon_catalog::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => { - models::loadable_addon_catalog::Content::Loading(models::Loading {}) - } - } - } -} - -impl ToProtobuf for Loadable { - fn to_protobuf(&self, ctx: &Ctx) -> models::loadable_descriptor::Content { - match &self { - Loadable::Ready(ready) => { - models::loadable_descriptor::Content::Ready(ready.to_protobuf(ctx)) - } - Loadable::Err(error) => models::loadable_descriptor::Content::Error(models::Error { - message: error.to_string(), - }), - Loadable::Loading => models::loadable_descriptor::Content::Loading(models::Loading {}), - } - } -} - -impl ToProtobuf for Loadable, CtxError> { - fn to_protobuf(&self, _args: &()) -> models::LoadableModal { - let content = match &self { - Loadable::Ready(ready) => models::loadable_modal::Content::Ready(LoadedModal { - modal: ready.to_protobuf(&()), - }), - Loadable::Err(error) => models::loadable_modal::Content::Error(models::Error { - message: match error { - CtxError::API(error) => error.message.to_owned(), - CtxError::Env(error) => error.message(), - CtxError::Other(error) => error.message(), - }, - }), - Loadable::Loading => models::loadable_modal::Content::Loading(models::Loading {}), - }; - models::LoadableModal { - content: Some(content), - } - } -} - -impl ToProtobuf - for Loadable, CtxError> -{ - fn to_protobuf(&self, _args: &()) -> models::LoadableNotification { - let content = match &self { - Loadable::Ready(ready) => { - models::loadable_notification::Content::Ready(LoadedNotification { - notification: ready.to_protobuf(&()), - }) - } - Loadable::Err(error) => models::loadable_notification::Content::Error(models::Error { - message: match error { - CtxError::API(error) => error.message.to_owned(), - CtxError::Env(error) => error.message(), - CtxError::Other(error) => error.message(), - }, - }), - Loadable::Loading => { - models::loadable_notification::Content::Loading(models::Loading {}) - } - }; - models::LoadableNotification { - content: Some(content), - } - } -} diff --git a/src/commonMain/rust/bridge/manifest.rs b/src/commonMain/rust/bridge/manifest.rs deleted file mode 100644 index 1b3bdea..0000000 --- a/src/commonMain/rust/bridge/manifest.rs +++ /dev/null @@ -1,286 +0,0 @@ -use semver::Version; -use std::str::FromStr; -use stremio_core::models::ctx::Ctx; -use stremio_core::types::addon::{ - Descriptor, DescriptorFlags, DescriptorPreview, ExtraProp, Manifest, ManifestBehaviorHints, - ManifestCatalog, ManifestExtra, ManifestPreview, ManifestResource, OptionsLimit, -}; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::ExtraProp { - fn from_protobuf(&self) -> ExtraProp { - ExtraProp { - name: self.name.to_owned(), - is_required: self.is_required, - options: self.options.to_owned(), - options_limit: OptionsLimit(self.options_limit as usize), - } - } -} - -impl FromProtobuf for types::ManifestBehaviorHints { - fn from_protobuf(&self) -> ManifestBehaviorHints { - ManifestBehaviorHints { - adult: self.adult, - p2p: self.p2p, - configurable: self.configurable, - configuration_required: self.configuration_required, - } - } -} - -impl FromProtobuf for types::manifest_extra::Extra { - fn from_protobuf(&self) -> ManifestExtra { - match self { - types::manifest_extra::Extra::Full(extra) => ManifestExtra::Full { - props: extra.props.from_protobuf(), - }, - types::manifest_extra::Extra::Short(extra) => ManifestExtra::Short { - required: extra.required.to_owned(), - supported: extra.supported.to_owned(), - }, - } - } -} - -impl FromProtobuf for types::ManifestCatalog { - fn from_protobuf(&self) -> ManifestCatalog { - ManifestCatalog { - id: self.id.to_owned(), - r#type: self.r#type.to_owned(), - name: self.name.clone(), - extra: self.extra.extra.from_protobuf().unwrap(), - } - } -} - -impl FromProtobuf for types::ManifestResource { - fn from_protobuf(&self) -> ManifestResource { - if self.types.is_empty() && self.id_prefixes.is_empty() { - ManifestResource::Short(self.name.to_owned()) - } else { - ManifestResource::Full { - name: self.name.to_owned(), - types: Some(self.types.to_owned()), - id_prefixes: Some(self.id_prefixes.to_owned()), - } - } - } -} - -impl FromProtobuf for types::ManifestPreview { - fn from_protobuf(&self) -> ManifestPreview { - ManifestPreview { - id: self.id.to_owned(), - version: Version::from_str(self.version.as_str()) - .expect("Manifest.version parsing failed"), - name: self.name.to_owned(), - description: self.description.to_owned(), - logo: self.logo.from_protobuf(), - background: self.background.from_protobuf(), - types: self.types.to_owned(), - behavior_hints: self.behavior_hints.from_protobuf(), - } - } -} - -impl FromProtobuf for types::Manifest { - fn from_protobuf(&self) -> Manifest { - Manifest { - id: self.id.to_owned(), - version: Version::from_str(self.version.as_str()) - .expect("Manifest.version parsing failed"), - name: self.name.to_owned(), - contact_email: None, - description: self.description.to_owned(), - logo: self.logo.from_protobuf(), - background: self.background.from_protobuf(), - types: self.types.to_owned(), - resources: self.resources.from_protobuf(), - id_prefixes: Some(self.id_prefixes.to_owned()) - .filter(|id_prefixes| !id_prefixes.is_empty()), - catalogs: self.catalogs.from_protobuf(), - addon_catalogs: self.addon_catalogs.from_protobuf(), - behavior_hints: self.behavior_hints.from_protobuf(), - } - } -} - -impl FromProtobuf for types::DescriptorFlags { - fn from_protobuf(&self) -> DescriptorFlags { - DescriptorFlags { - official: self.official, - protected: self.protected, - } - } -} - -impl FromProtobuf for types::Descriptor { - fn from_protobuf(&self) -> Descriptor { - Descriptor { - manifest: self.manifest.from_protobuf(), - transport_url: self.transport_url.from_protobuf(), - flags: self.flags.from_protobuf(), - } - } -} - -impl ToProtobuf for ExtraProp { - fn to_protobuf(&self, _args: &()) -> types::ExtraProp { - types::ExtraProp { - name: self.name.to_owned(), - is_required: self.is_required, - options: self.options.to_owned(), - options_limit: self.options_limit.0 as i32, - } - } -} - -impl ToProtobuf for ManifestBehaviorHints { - fn to_protobuf(&self, _args: &()) -> types::ManifestBehaviorHints { - types::ManifestBehaviorHints { - adult: self.adult, - p2p: self.p2p, - configurable: self.configurable, - configuration_required: self.configuration_required, - } - } -} - -impl ToProtobuf for ManifestExtra { - fn to_protobuf(&self, _args: &()) -> types::manifest_extra::Extra { - match self { - ManifestExtra::Full { props } => { - types::manifest_extra::Extra::Full(types::FullManifestExtra { - props: props.to_protobuf(&()), - }) - } - ManifestExtra::Short { - required, - supported, - } => types::manifest_extra::Extra::Short(types::ShortManifestExtra { - required: required.to_owned(), - supported: supported.to_owned(), - }), - } - } -} - -impl ToProtobuf for ManifestCatalog { - fn to_protobuf(&self, _args: &()) -> types::ManifestCatalog { - types::ManifestCatalog { - id: self.id.to_owned(), - r#type: self.r#type.to_owned(), - name: self.name.clone(), - extra: types::ManifestExtra { - extra: Some(self.extra.to_protobuf(&())), - }, - } - } -} - -impl ToProtobuf for ManifestResource { - fn to_protobuf(&self, _args: &()) -> types::ManifestResource { - match self { - ManifestResource::Short(name) => types::ManifestResource { - name: name.to_owned(), - types: vec![], - id_prefixes: vec![], - }, - ManifestResource::Full { - name, - types, - id_prefixes, - } => types::ManifestResource { - name: name.to_owned(), - types: types.to_owned().unwrap_or_default(), - id_prefixes: id_prefixes.to_owned().unwrap_or_default(), - }, - } - } -} - -impl ToProtobuf for ManifestPreview { - fn to_protobuf(&self, _args: &()) -> types::ManifestPreview { - types::ManifestPreview { - id: self.id.to_owned(), - version: self.version.to_string(), - name: self.name.to_owned(), - description: self.description.to_owned(), - logo: self.logo.to_protobuf(&()), - background: self.background.to_protobuf(&()), - types: self.types.to_owned(), - behavior_hints: self.behavior_hints.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Manifest { - fn to_protobuf(&self, _args: &()) -> types::Manifest { - types::Manifest { - id: self.id.to_owned(), - version: self.version.to_string(), - name: self.name.to_owned(), - description: self.description.to_owned(), - logo: self.logo.to_protobuf(&()), - background: self.background.to_protobuf(&()), - types: self.types.to_owned(), - contact_email: self.contact_email.to_owned(), - resources: self.resources.to_protobuf(&()), - id_prefixes: self.id_prefixes.to_owned().unwrap_or_default(), - catalogs: self.catalogs.to_protobuf(&()), - addon_catalogs: self.addon_catalogs.to_protobuf(&()), - behavior_hints: self.behavior_hints.to_protobuf(&()), - } - } -} - -impl ToProtobuf for DescriptorFlags { - fn to_protobuf(&self, _args: &()) -> types::DescriptorFlags { - types::DescriptorFlags { - official: self.official, - protected: self.protected, - } - } -} - -impl ToProtobuf for DescriptorPreview { - fn to_protobuf(&self, ctx: &Ctx) -> types::DescriptorPreview { - types::DescriptorPreview { - manifest: self.manifest.to_protobuf(&()), - transport_url: self.transport_url.to_protobuf(&()), - installed: ctx - .profile - .addons - .iter() - .any(|addon| addon.transport_url == self.transport_url), - } - } -} - -impl ToProtobuf for Descriptor { - fn to_protobuf(&self, ctx: &Ctx) -> types::Descriptor { - let installed_addon = ctx - .profile - .addons - .iter() - .find(|addon| addon.transport_url == self.transport_url); - types::Descriptor { - manifest: self.manifest.to_protobuf(&()), - transport_url: self.transport_url.to_protobuf(&()), - flags: self.flags.to_protobuf(&()), - installed: installed_addon.is_some(), - installable: installed_addon.is_none() - && !self.manifest.behavior_hints.configuration_required, - upgradeable: installed_addon - .filter(|addon| !addon.flags.protected) - .map(|addon| addon.manifest.version != self.manifest.version) - .unwrap_or_default(), - uninstallable: installed_addon - .filter(|addon| !addon.flags.protected) - .is_some(), - } - } -} diff --git a/src/commonMain/rust/bridge/meta_preview.rs b/src/commonMain/rust/bridge/meta_preview.rs deleted file mode 100644 index 0a3a151..0000000 --- a/src/commonMain/rust/bridge/meta_preview.rs +++ /dev/null @@ -1,100 +0,0 @@ -use chrono::Duration; -use stremio_core::deep_links::MetaItemDeepLinks; -use stremio_core::models::ctx::Ctx; -use stremio_core::runtime::Env; -use stremio_core::types::addon::ResourceRequest; -use stremio_core::types::resource::{MetaItemBehaviorHints, MetaItemPreview, PosterShape}; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::env::AppleEnv; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::MetaItemBehaviorHints { - fn from_protobuf(&self) -> MetaItemBehaviorHints { - MetaItemBehaviorHints { - default_video_id: self.default_video_id.to_owned(), - featured_video_id: self.featured_video_id.to_owned(), - has_scheduled_videos: self.has_scheduled_videos, - other: Default::default(), - } - } -} - -impl FromProtobuf for types::MetaItemPreview { - fn from_protobuf(&self) -> MetaItemPreview { - MetaItemPreview { - id: self.id.to_owned(), - r#type: self.r#type.to_owned(), - name: self.name.to_owned(), - poster_shape: types::PosterShape::try_from(self.poster_shape) - .ok() - .from_protobuf() - .unwrap_or(PosterShape::Poster), - poster: self.poster.from_protobuf(), - background: self.background.from_protobuf(), - logo: self.logo.from_protobuf(), - description: self.description.to_owned(), - release_info: self.release_info.to_owned(), - runtime: self.runtime.to_owned(), - released: self.released.from_protobuf(), - links: Default::default(), - trailer_streams: Default::default(), - behavior_hints: self.behavior_hints.from_protobuf(), - } - } -} - -impl ToProtobuf for MetaItemBehaviorHints { - fn to_protobuf(&self, _args: &()) -> types::MetaItemBehaviorHints { - types::MetaItemBehaviorHints { - default_video_id: self.default_video_id.clone(), - featured_video_id: self.featured_video_id.clone(), - has_scheduled_videos: self.has_scheduled_videos, - } - } -} - -impl ToProtobuf for MetaItemDeepLinks { - fn to_protobuf(&self, _args: &()) -> types::MetaItemDeepLinks { - types::MetaItemDeepLinks { - meta_details_videos: self.meta_details_videos.clone(), - meta_details_streams: self.meta_details_streams.clone(), - player: self.player.clone(), - } - } -} - -impl ToProtobuf for MetaItemPreview { - fn to_protobuf( - &self, - (ctx, meta_request): &(&Ctx, &ResourceRequest), - ) -> types::MetaItemPreview { - types::MetaItemPreview { - id: self.id.to_string(), - r#type: self.r#type.to_string(), - name: self.name.to_string(), - poster_shape: self.poster_shape.to_protobuf(&()) as i32, - poster: self.poster.to_protobuf(&()), - background: self.background.to_protobuf(&()), - logo: self.logo.to_protobuf(&()), - description: self.description.clone(), - release_info: self.release_info.clone(), - runtime: self.runtime.clone(), - released: self.released.to_protobuf(&()), - links: self.links.to_protobuf(&()), - behavior_hints: self.behavior_hints.to_protobuf(&()), - deep_links: MetaItemDeepLinks::from((self, *meta_request)).to_protobuf(&()), - in_library: ctx - .library - .items - .get(&self.id) - .map(|library_item| !library_item.removed) - .unwrap_or_default(), - in_cinema: self - .released - .filter(|_released| self.r#type == "movie") - .map(|released| released + Duration::days(30) > AppleEnv::now()) - .unwrap_or_default(), - } - } -} diff --git a/src/commonMain/rust/bridge/option.rs b/src/commonMain/rust/bridge/option.rs deleted file mode 100644 index 2306b4d..0000000 --- a/src/commonMain/rust/bridge/option.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate::bridge::{FromProtobuf, ToProtobuf}; - -impl, U> FromProtobuf> for Option { - fn from_protobuf(&self) -> Option { - self.as_ref().map(|item| item.from_protobuf()) - } -} - -impl, U, A> ToProtobuf, A> for Option { - fn to_protobuf(&self, args: &A) -> Option { - self.as_ref().map(|item| item.to_protobuf(args)) - } -} diff --git a/src/commonMain/rust/bridge/pair.rs b/src/commonMain/rust/bridge/pair.rs deleted file mode 100644 index 6473436..0000000 --- a/src/commonMain/rust/bridge/pair.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::runtime; - -impl ToProtobuf for (Vec, Vec) { - fn to_protobuf(&self, _args: &()) -> runtime::PlanPair { - runtime::PlanPair { - first: self.0.clone(), - second: self.1.clone(), - } - } -} diff --git a/src/commonMain/rust/bridge/poster_shape.rs b/src/commonMain/rust/bridge/poster_shape.rs deleted file mode 100644 index 1b5d491..0000000 --- a/src/commonMain/rust/bridge/poster_shape.rs +++ /dev/null @@ -1,24 +0,0 @@ -use stremio_core::types::resource::PosterShape; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::PosterShape { - fn from_protobuf(&self) -> PosterShape { - match self { - types::PosterShape::Poster => PosterShape::Poster, - types::PosterShape::Landscape => PosterShape::Landscape, - types::PosterShape::Square => PosterShape::Square, - } - } -} - -impl ToProtobuf for PosterShape { - fn to_protobuf(&self, _args: &()) -> types::PosterShape { - match self { - PosterShape::Poster => types::PosterShape::Poster, - PosterShape::Landscape => types::PosterShape::Landscape, - PosterShape::Square => types::PosterShape::Square, - } - } -} diff --git a/src/commonMain/rust/bridge/profile.rs b/src/commonMain/rust/bridge/profile.rs deleted file mode 100644 index 36984f6..0000000 --- a/src/commonMain/rust/bridge/profile.rs +++ /dev/null @@ -1,192 +0,0 @@ -use std::cmp; - -use stremio_core::types::api::{LinkAuthKey, LinkCodeResponse}; -use stremio_core::types::profile::{ - Auth, FrameRateMatchingStrategy, GDPRConsent, Profile, Settings, User, -}; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::profile::FrameRateMatchingStrategy { - fn from_protobuf(&self) -> FrameRateMatchingStrategy { - match self { - types::profile::FrameRateMatchingStrategy::Disabled => { - FrameRateMatchingStrategy::Disabled - } - types::profile::FrameRateMatchingStrategy::FrameRateOnly => { - FrameRateMatchingStrategy::FrameRateOnly - } - types::profile::FrameRateMatchingStrategy::FrameRateAndResolution => { - FrameRateMatchingStrategy::FrameRateAndResolution - } - } - } -} - -impl ToProtobuf for FrameRateMatchingStrategy { - fn to_protobuf(&self, _args: &()) -> types::profile::FrameRateMatchingStrategy { - match self { - FrameRateMatchingStrategy::Disabled => { - types::profile::FrameRateMatchingStrategy::Disabled - } - FrameRateMatchingStrategy::FrameRateOnly => { - types::profile::FrameRateMatchingStrategy::FrameRateOnly - } - FrameRateMatchingStrategy::FrameRateAndResolution => { - types::profile::FrameRateMatchingStrategy::FrameRateAndResolution - } - } - } -} - -impl FromProtobuf for types::GdprConsent { - fn from_protobuf(&self) -> GDPRConsent { - GDPRConsent { - tos: self.tos, - privacy: self.privacy, - marketing: self.marketing, - from: self.from.clone(), - } - } -} - -impl FromProtobuf for types::profile::Settings { - fn from_protobuf(&self) -> Settings { - Settings { - interface_language: self.interface_language.to_string(), - streaming_server_url: self.streaming_server_url.from_protobuf(), - player_type: self.player_type.clone(), - binge_watching: self.binge_watching, - play_in_background: self.play_in_background, - hardware_decoding: self.hardware_decoding, - frame_rate_matching_strategy: types::profile::FrameRateMatchingStrategy::try_from( - self.frame_rate_matching_strategy, - ) - .ok() - .from_protobuf() - .unwrap_or(FrameRateMatchingStrategy::Disabled), - next_video_notification_duration: u32::try_from(cmp::max( - self.next_video_notification_duration, - 0, - )) - .unwrap_or(u32::MAX), - audio_passthrough: self.audio_passthrough, - audio_language: Some(self.audio_language.to_string()), - secondary_audio_language: self.secondary_audio_language.clone(), - subtitles_language: Some(self.subtitles_language.to_string()), - secondary_subtitles_language: self.secondary_subtitles_language.clone(), - subtitles_size: u8::try_from(cmp::max(self.subtitles_size, 0)).unwrap_or(u8::MAX), - subtitles_font: self.subtitles_font.to_string(), - subtitles_bold: self.subtitles_bold, - subtitles_offset: u8::try_from(cmp::max(self.subtitles_offset, 0)).unwrap_or(u8::MAX), - subtitles_text_color: self.subtitles_text_color.to_string(), - subtitles_background_color: self.subtitles_background_color.to_string(), - subtitles_outline_color: self.subtitles_outline_color.to_string(), - subtitles_opacity: u8::try_from(cmp::max(self.subtitles_opacity, 0)).unwrap_or(u8::MAX), - esc_exit_fullscreen: self.esc_exit_fullscreen, - seek_time_duration: u32::try_from(cmp::max(self.seek_time_duration, 0)) - .unwrap_or(u32::MAX), - seek_short_time_duration: u32::try_from(cmp::max(self.seek_time_duration, 0)) - .unwrap_or(u32::MAX), - pause_on_minimize: self.pause_on_minimize, - surround_sound: self.surround_sound, - streaming_server_warning_dismissed: None, - } - } -} - -impl ToProtobuf for LinkAuthKey { - fn to_protobuf(&self, _args: &()) -> types::LinkAuthKey { - types::LinkAuthKey { - auth_key: self.auth_key.to_string(), - } - } -} - -impl ToProtobuf for LinkCodeResponse { - fn to_protobuf(&self, _args: &()) -> types::LinkCodeResponse { - types::LinkCodeResponse { - code: self.code.to_string(), - link: self.link.to_string(), - qrcode: self.qrcode.to_string(), - } - } -} - -impl ToProtobuf for GDPRConsent { - fn to_protobuf(&self, _args: &()) -> types::GdprConsent { - types::GdprConsent { - tos: self.tos, - privacy: self.privacy, - marketing: self.marketing, - from: self.from.clone(), - } - } -} - -impl ToProtobuf for User { - fn to_protobuf(&self, _args: &()) -> types::User { - types::User { - id: self.id.to_string(), - email: self.email.to_string(), - fb_id: self.fb_id.clone(), - avatar: self.avatar.clone(), - gdpr_consent: self.gdpr_consent.to_protobuf(&()), - date_registered: self.date_registered.to_protobuf(&()), - last_modified: self.last_modified.to_protobuf(&()), - premium_expire: self.premium_expire.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Auth { - fn to_protobuf(&self, _args: &()) -> types::Auth { - types::Auth { - key: self.key.0.to_string(), - user: self.user.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Settings { - fn to_protobuf(&self, _args: &()) -> types::profile::Settings { - types::profile::Settings { - interface_language: self.interface_language.to_string(), - streaming_server_url: self.streaming_server_url.to_string(), - binge_watching: self.binge_watching, - play_in_background: self.play_in_background, - hardware_decoding: self.hardware_decoding, - audio_passthrough: self.audio_passthrough, - audio_language: self.audio_language.clone().unwrap_or_default(), - subtitles_language: self.subtitles_language.clone().unwrap_or_default(), - subtitles_size: self.subtitles_size as i32, - subtitles_font: self.subtitles_font.to_string(), - subtitles_bold: self.subtitles_bold, - subtitles_offset: self.subtitles_offset as i32, - subtitles_text_color: self.subtitles_text_color.to_string(), - subtitles_background_color: self.subtitles_background_color.to_string(), - subtitles_outline_color: self.subtitles_outline_color.to_string(), - subtitles_opacity: self.subtitles_opacity as i32, - esc_exit_fullscreen: self.esc_exit_fullscreen, - seek_time_duration: self.seek_time_duration as i64, - seek_short_time_duration: self.seek_short_time_duration as i64, - pause_on_minimize: self.pause_on_minimize, - secondary_audio_language: self.secondary_audio_language.clone(), - secondary_subtitles_language: self.secondary_subtitles_language.clone(), - player_type: self.player_type.clone(), - frame_rate_matching_strategy: self.frame_rate_matching_strategy.to_protobuf(&()) as i32, - next_video_notification_duration: self.next_video_notification_duration as i64, - surround_sound: self.surround_sound, - } - } -} - -impl ToProtobuf for Profile { - fn to_protobuf(&self, _args: &()) -> types::Profile { - types::Profile { - auth: self.auth.to_protobuf(&()), - settings: self.settings.to_protobuf(&()), - } - } -} diff --git a/src/commonMain/rust/bridge/resource_loadable.rs b/src/commonMain/rust/bridge/resource_loadable.rs deleted file mode 100644 index 4b6f9cb..0000000 --- a/src/commonMain/rust/bridge/resource_loadable.rs +++ /dev/null @@ -1,147 +0,0 @@ -use inflector::Inflector; -use stremio_core::deep_links::DiscoverDeepLinks; -use stremio_core::models::common::{DescriptorLoadable, ResourceLoadable}; -use stremio_core::models::ctx::Ctx; -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; - -impl ToProtobuf for ResourceLoadable> { - fn to_protobuf(&self, ctx: &Ctx) -> models::LoadablePage { - let title = ctx - .profile - .addons - .iter() - .find(|addon| addon.transport_url == self.request.base) - .and_then(|addon| { - addon - .manifest - .catalogs - .iter() - .find(|manifest_catalog| { - manifest_catalog.id == self.request.path.id - && manifest_catalog.r#type == self.request.path.r#type - }) - .map(|manifest_catalog| (addon, manifest_catalog)) - }) - .map(|(addon, manifest_catalog)| { - format!( - "{} - {}", - &manifest_catalog - .name - .as_ref() - .unwrap_or(&addon.manifest.name) - .to_title_case(), - &manifest_catalog.r#type.to_title_case(), - ) - }) - .unwrap_or_default(); - let deep_links = DiscoverDeepLinks::from(&self.request).to_protobuf(&()); - models::LoadablePage { - title, - request: self.request.to_protobuf(&()), - content: self.content.to_protobuf(&(ctx, &self.request)), - deep_links, - } - } -} - -impl ToProtobuf, Option<&WatchedBitField>)> - for &ResourceLoadable -{ - fn to_protobuf( - &self, - (ctx, library_item, watched): &(&Ctx, 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(&()), - content: self.content.to_protobuf(&( - *library_item, - *watched, - Some(&addon_name), - &self.request, - )), - } - } -} - -impl ToProtobuf)> - for ResourceLoadable> -{ - fn to_protobuf( - &self, - (ctx, meta_request): &(&Ctx, Option<&ResourceRequest>), - ) -> models::LoadableStreams { - let addon_name = get_addon_name(ctx, &self.request.base); - models::LoadableStreams { - title: addon_name.to_owned(), - 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, 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 = get_addon_name(ctx, &self.request.base); - models::LoadableSubtitles { - title: addon_name.to_owned(), - request: self.request.to_protobuf(&()), - content: self.content.to_protobuf(&(Some(&addon_name))), - } - } -} - -impl ToProtobuf for &ResourceLoadable> { - fn to_protobuf(&self, ctx: &Ctx) -> models::LoadableAddonCatalog { - models::LoadableAddonCatalog { - request: self.request.to_protobuf(&()), - content: self.content.to_protobuf(ctx), - } - } -} - -impl ToProtobuf for DescriptorLoadable { - fn to_protobuf(&self, ctx: &Ctx) -> models::LoadableDescriptor { - models::LoadableDescriptor { - transport_url: self.transport_url.to_string(), - content: Some(self.content.to_protobuf(ctx)), - } - } -} - -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/bridge/resource_path.rs b/src/commonMain/rust/bridge/resource_path.rs deleted file mode 100644 index 2b4ddfc..0000000 --- a/src/commonMain/rust/bridge/resource_path.rs +++ /dev/null @@ -1,26 +0,0 @@ -use stremio_core::types::addon::ResourcePath; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::ResourcePath { - fn from_protobuf(&self) -> ResourcePath { - ResourcePath { - resource: self.resource.to_owned(), - r#type: self.r#type.to_owned(), - id: self.id.to_owned(), - extra: self.extra.from_protobuf(), - } - } -} - -impl ToProtobuf for ResourcePath { - fn to_protobuf(&self, _args: &()) -> types::ResourcePath { - types::ResourcePath { - resource: self.resource.to_owned(), - r#type: self.r#type.to_owned(), - id: self.id.to_owned(), - extra: self.extra.to_protobuf(&()), - } - } -} diff --git a/src/commonMain/rust/bridge/resource_request.rs b/src/commonMain/rust/bridge/resource_request.rs deleted file mode 100644 index f506c2c..0000000 --- a/src/commonMain/rust/bridge/resource_request.rs +++ /dev/null @@ -1,31 +0,0 @@ -use stremio_core::models::installed_addons_with_filters::InstalledAddonsRequest; -use stremio_core::types::addon::ResourceRequest; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::ResourceRequest { - fn from_protobuf(&self) -> ResourceRequest { - ResourceRequest { - base: self.base.from_protobuf(), - path: self.path.from_protobuf(), - } - } -} - -impl FromProtobuf for types::ResourceRequest { - fn from_protobuf(&self) -> InstalledAddonsRequest { - InstalledAddonsRequest { - r#type: Some(self.path.r#type.to_string()).filter(|s| !s.is_empty()), - } - } -} - -impl ToProtobuf for ResourceRequest { - fn to_protobuf(&self, _args: &()) -> types::ResourceRequest { - types::ResourceRequest { - base: self.base.to_string(), - path: self.path.to_protobuf(&()), - } - } -} diff --git a/src/commonMain/rust/bridge/stream.rs b/src/commonMain/rust/bridge/stream.rs deleted file mode 100644 index 6e1bb51..0000000 --- a/src/commonMain/rust/bridge/stream.rs +++ /dev/null @@ -1,216 +0,0 @@ -use hex::FromHex; -use stremio_core::deep_links::StreamDeepLinks; -use stremio_core::models::ctx::Ctx; -use stremio_core::types::addon::ResourceRequest; -use stremio_core::types::resource::{ - Stream, StreamBehaviorHints, StreamProxyHeaders, StreamSource, -}; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::stream::Source { - fn from_protobuf(&self) -> StreamSource { - match self { - types::stream::Source::Url(source) => StreamSource::Url { - url: source.url.from_protobuf(), - }, - types::stream::Source::YouTube(source) => StreamSource::YouTube { - yt_id: source.yt_id.to_owned(), - }, - types::stream::Source::Torrent(source) => StreamSource::Torrent { - info_hash: <[u8; 20]>::from_hex(source.info_hash.as_str()) - .expect("Stream.info_hash parse failed"), - file_idx: source.file_idx.map(|idx| idx as u16), - announce: source.announce.clone(), - file_must_include: source.file_must_include.to_owned(), - }, - types::stream::Source::External(source) => StreamSource::External { - external_url: source.external_url.from_protobuf(), - android_tv_url: source.android_tv_url.from_protobuf(), - tizen_url: None, - webos_url: None, - }, - types::stream::Source::PlayerFrame(source) => StreamSource::PlayerFrame { - player_frame_url: source.player_frame_url.from_protobuf(), - }, - types::stream::Source::Rar(source) => StreamSource::Rar { - rar_urls: source.rar_urls.from_protobuf(), - file_idx: source.file_idx.map(|idx| idx as u16), - file_must_include: source.file_must_include.to_owned(), - }, - types::stream::Source::Zip(source) => StreamSource::Zip { - zip_urls: source.zip_urls.from_protobuf(), - file_idx: source.file_idx.map(|idx| idx as u16), - file_must_include: source.file_must_include.to_owned(), - }, - } - } -} - -impl FromProtobuf for types::StreamProxyHeaders { - fn from_protobuf(&self) -> StreamProxyHeaders { - StreamProxyHeaders { - request: self.request.to_owned(), - response: self.response.to_owned(), - } - } -} - -impl FromProtobuf for types::Stream { - fn from_protobuf(&self) -> Stream { - Stream { - source: self.source.from_protobuf().unwrap(), - name: self.name.to_owned(), - description: self.description.to_owned(), - thumbnail: self.thumbnail.to_owned(), - subtitles: self.subtitles.from_protobuf(), - behavior_hints: StreamBehaviorHints { - not_web_ready: self.behavior_hints.not_web_ready, - binge_group: self.behavior_hints.binge_group.to_owned(), - country_whitelist: Some(self.behavior_hints.country_whitelist.to_owned()), - proxy_headers: self.behavior_hints.proxy_headers.from_protobuf(), - filename: self.behavior_hints.filename.to_owned(), - video_hash: self.behavior_hints.video_hash.to_owned(), - video_size: self.behavior_hints.video_size, - other: Default::default(), - }, - } - } -} - -impl ToProtobuf for StreamSource { - fn to_protobuf(&self, _args: &()) -> types::stream::Source { - match self { - StreamSource::Url { url } => types::stream::Source::Url(types::stream::Url { - url: url.to_string(), - }), - StreamSource::YouTube { yt_id } => { - types::stream::Source::YouTube(types::stream::YouTube { - yt_id: yt_id.to_string(), - }) - } - StreamSource::Torrent { - info_hash, - file_idx, - announce, - file_must_include, - } => types::stream::Source::Torrent(types::stream::Torrent { - info_hash: hex::encode(info_hash), - file_idx: file_idx.map(|idx| idx as i32), - announce: announce.clone(), - file_must_include: file_must_include.to_owned(), - }), - StreamSource::External { - external_url, - android_tv_url, - .. - } => types::stream::Source::External(types::stream::External { - external_url: external_url.to_protobuf(&()), - android_tv_url: android_tv_url.to_protobuf(&()), - }), - StreamSource::PlayerFrame { player_frame_url } => { - types::stream::Source::PlayerFrame(types::stream::PlayerFrame { - player_frame_url: player_frame_url.to_string(), - }) - } - StreamSource::Rar { - rar_urls, - file_idx, - file_must_include, - } => types::stream::Source::Rar(types::stream::Rar { - rar_urls: rar_urls.to_protobuf(&()), - file_idx: file_idx.map(|idx| idx as i32), - file_must_include: file_must_include.to_owned(), - }), - StreamSource::Zip { - zip_urls, - file_idx, - file_must_include, - } => types::stream::Source::Zip(types::stream::Zip { - zip_urls: zip_urls.to_protobuf(&()), - file_idx: file_idx.map(|idx| idx as i32), - file_must_include: file_must_include.to_owned(), - }), - } - } -} - -impl ToProtobuf for StreamProxyHeaders { - fn to_protobuf(&self, _args: &()) -> types::StreamProxyHeaders { - types::StreamProxyHeaders { - request: self.request.to_owned(), - response: self.response.to_owned(), - } - } -} - -impl - ToProtobuf< - types::Stream, - ( - Option<&Ctx>, - Option<&String>, - Option<&ResourceRequest>, - Option<&ResourceRequest>, - ), - > for Stream -{ - fn to_protobuf( - &self, - (ctx, addon_name, stream_request, meta_request): &( - Option<&Ctx>, - Option<&String>, - Option<&ResourceRequest>, - Option<&ResourceRequest>, - ), - ) -> types::Stream { - // in calls that have None for ctx this would panic if we don't set it to default. - let settings = ctx - .map(|ctx| ctx.profile.settings.to_owned()) - .unwrap_or_default(); - - let deep_links = match (stream_request, meta_request) { - (Some(stream_request), Some(meta_request)) => StreamDeepLinks::from(( - self, - *stream_request, - *meta_request, - &ctx.map(|ctx| ctx.profile.settings.streaming_server_url.clone()), - &settings, - )), - _ => StreamDeepLinks::from(( - self, - &ctx.map(|ctx| ctx.profile.settings.streaming_server_url.clone()), - &settings, - )), - }; - - types::Stream { - name: self.name.to_owned().or_else(|| addon_name.cloned()), - description: self.description.clone(), - thumbnail: self.thumbnail.clone(), - subtitles: self.subtitles.to_protobuf(addon_name), - behavior_hints: types::StreamBehaviorHints { - not_web_ready: self.behavior_hints.not_web_ready, - binge_group: self.behavior_hints.binge_group.to_owned(), - country_whitelist: self - .behavior_hints - .country_whitelist - .to_owned() - .unwrap_or_default(), - proxy_headers: self.behavior_hints.proxy_headers.to_protobuf(&()), - filename: self.behavior_hints.filename.to_owned(), - video_hash: self.behavior_hints.video_hash.to_owned(), - video_size: self.behavior_hints.video_size, - }, - deep_links: types::StreamDeepLinks { - player: deep_links.player, - external_player: types::stream_deep_links::ExternalPlayerLink { - download: deep_links.external_player.download, - streaming: deep_links.external_player.streaming, - }, - }, - source: Some(self.source.to_protobuf(&())), - } - } -} diff --git a/src/commonMain/rust/bridge/string.rs b/src/commonMain/rust/bridge/string.rs deleted file mode 100644 index ecbb408..0000000 --- a/src/commonMain/rust/bridge/string.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::bridge::{FromProtobuf, ToProtobuf}; -use url::Url; - -impl FromProtobuf for String { - fn from_protobuf(&self) -> Url { - Url::parse(self).expect("url parse failed") - } -} - -impl ToProtobuf for Url { - fn to_protobuf(&self, _args: &()) -> String { - self.to_string() - } -} diff --git a/src/commonMain/rust/bridge/subtitle.rs b/src/commonMain/rust/bridge/subtitle.rs deleted file mode 100644 index b4a3e18..0000000 --- a/src/commonMain/rust/bridge/subtitle.rs +++ /dev/null @@ -1,23 +0,0 @@ -use stremio_core::types::resource::Subtitles; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::types; - -impl FromProtobuf for types::Subtitle { - fn from_protobuf(&self) -> Subtitles { - Subtitles { - lang: self.lang.to_string(), - url: self.url.from_protobuf(), - } - } -} - -impl ToProtobuf> for Subtitles { - fn to_protobuf(&self, addon_name: &Option<&String>) -> types::Subtitle { - types::Subtitle { - lang: self.lang.to_string(), - url: self.url.to_string(), - name: addon_name.cloned(), - } - } -} diff --git a/src/commonMain/rust/bridge/to_protobuf.rs b/src/commonMain/rust/bridge/to_protobuf.rs deleted file mode 100644 index 1362ef2..0000000 --- a/src/commonMain/rust/bridge/to_protobuf.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub trait ToProtobuf { - fn to_protobuf(&self, args: &A) -> T; -} diff --git a/src/commonMain/rust/lib.rs b/src/commonMain/rust/lib.rs index 43ade1b..d958e85 100644 --- a/src/commonMain/rust/lib.rs +++ b/src/commonMain/rust/lib.rs @@ -2,7 +2,6 @@ pub mod bridge; pub mod env; pub mod model; -#[allow(clippy::all)] -/// Auto-generated module from protobuf files to Rust structus -pub mod protobuf; + pub mod stremio_core_apple; +pub use stremio_core_apple::*; diff --git a/src/commonMain/rust/model/addons.rs b/src/commonMain/rust/model/addons.rs deleted file mode 100644 index 58c9de1..0000000 --- a/src/commonMain/rust/model/addons.rs +++ /dev/null @@ -1,61 +0,0 @@ -use stremio_core::models::catalog_with_filters::CatalogWithFilters; -use stremio_core::models::ctx::Ctx; -use stremio_core::models::installed_addons_with_filters::InstalledAddonsWithFilters; -use stremio_core::runtime::msg::{Action, ActionLoad, Msg}; -use stremio_core::runtime::{Effects, Env, UpdateWithCtx}; -use stremio_core::types::addon::DescriptorPreview; -use stremio_core::types::profile::Profile; - -#[derive(Default, Clone)] -pub struct AddonsWithFilters { - pub remote_addons: CatalogWithFilters, - pub installed_addons: InstalledAddonsWithFilters, -} - -impl AddonsWithFilters { - pub fn new(profile: &Profile) -> (Self, Effects) { - let (remote_addons, remote_addons_effects) = - CatalogWithFilters::::new(profile); - let (installed_addons, installed_addons_effects) = InstalledAddonsWithFilters::new(profile); - let effects = remote_addons_effects.join(installed_addons_effects); - ( - Self { - remote_addons, - installed_addons, - }, - effects, - ) - } -} - -impl UpdateWithCtx for AddonsWithFilters { - fn update(&mut self, msg: &Msg, ctx: &Ctx) -> Effects { - match msg { - Msg::Action(Action::Load(ActionLoad::InstalledAddonsWithFilters(_selected))) => { - let unload_remote_effects = UpdateWithCtx::::update( - &mut self.remote_addons, - &Msg::Action(Action::Unload), - ctx, - ); - let installed_addons_effects = - UpdateWithCtx::::update(&mut self.installed_addons, msg, ctx); - unload_remote_effects.join(installed_addons_effects) - } - Msg::Action(Action::Load(ActionLoad::CatalogWithFilters(_selected))) => { - let unload_installed_effects = UpdateWithCtx::::update( - &mut self.installed_addons, - &Msg::Action(Action::Unload), - ctx, - ); - let remote_effects = UpdateWithCtx::::update(&mut self.remote_addons, msg, ctx); - unload_installed_effects.join(remote_effects) - } - _ => { - let remote_effects = UpdateWithCtx::::update(&mut self.remote_addons, msg, ctx); - let installed_effects = - UpdateWithCtx::::update(&mut self.installed_addons, msg, ctx); - remote_effects.join(installed_effects) - } - } - } -} diff --git a/src/commonMain/rust/model/fields.rs b/src/commonMain/rust/model/fields.rs deleted file mode 100644 index aadbade..0000000 --- a/src/commonMain/rust/model/fields.rs +++ /dev/null @@ -1,18 +0,0 @@ - -//! [`ToProtobuf`] and [`FromProtobuf`] impls for various fields -//! -//! [`ToProtobuf`]: crate::bridge::ToProtobuf -//! [`FromProtobuf`]: crate::bridge::FromProtobuf - -mod addon_detail; -mod addons_with_filters; -mod catalogs_with_extra; -mod continue_watching_preview; -mod ctx; -mod discover; -mod library; -mod library_by_type; -mod link; -mod meta_details; -mod player; -mod streaming_server; diff --git a/src/commonMain/rust/model/fields/addon_detail.rs b/src/commonMain/rust/model/fields/addon_detail.rs deleted file mode 100644 index b462cf7..0000000 --- a/src/commonMain/rust/model/fields/addon_detail.rs +++ /dev/null @@ -1,33 +0,0 @@ -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::models; -use stremio_core::models::addon_details::{AddonDetails, Selected}; -use stremio_core::models::ctx::Ctx; - -impl FromProtobuf for models::addon_details::Selected { - fn from_protobuf(&self) -> Selected { - let mut url = self.transport_url.from_protobuf(); - if url.scheme() == "stremio" { - let replaced_url = url.as_str().replacen("stremio://", "https://", 1); - url = replaced_url.parse().expect("Should be able to parse URL"); - } - Selected { transport_url: url } - } -} - -impl ToProtobuf for Selected { - fn to_protobuf(&self, _args: &()) -> models::addon_details::Selected { - models::addon_details::Selected { - transport_url: self.transport_url.to_string(), - } - } -} - -impl ToProtobuf for AddonDetails { - fn to_protobuf(&self, ctx: &Ctx) -> models::AddonDetails { - models::AddonDetails { - selected: self.selected.to_protobuf(&()), - local_addon: self.local_addon.to_protobuf(ctx), - remote_addon: self.remote_addon.to_protobuf(ctx), - } - } -} diff --git a/src/commonMain/rust/model/fields/addons_with_filters.rs b/src/commonMain/rust/model/fields/addons_with_filters.rs deleted file mode 100644 index a07e32e..0000000 --- a/src/commonMain/rust/model/fields/addons_with_filters.rs +++ /dev/null @@ -1,130 +0,0 @@ -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::model::AddonsWithFilters; -use crate::protobuf::stremio::core::models::LoadableAddonCatalog; -use crate::protobuf::stremio::core::{models, types}; -use stremio_core::models::ctx::Ctx; -use stremio_core::models::installed_addons_with_filters::InstalledAddonsRequest; -use stremio_core::models::{catalog_with_filters, installed_addons_with_filters}; - -impl FromProtobuf for models::addons_with_filters::Selected { - fn from_protobuf(&self) -> catalog_with_filters::Selected { - catalog_with_filters::Selected { - request: self.request.from_protobuf(), - } - } -} - -impl FromProtobuf - for models::addons_with_filters::Selected -{ - fn from_protobuf(&self) -> installed_addons_with_filters::Selected { - installed_addons_with_filters::Selected { - request: self.request.from_protobuf(), - } - } -} - -impl ToProtobuf for InstalledAddonsRequest { - fn to_protobuf(&self, _args: &()) -> types::ResourceRequest { - types::ResourceRequest { - base: "".to_string(), - path: types::ResourcePath { - resource: "".to_string(), - r#type: self.r#type.clone().unwrap_or_default(), - id: "".to_string(), - extra: vec![], - }, - } - } -} - -impl ToProtobuf - for installed_addons_with_filters::Selected -{ - fn to_protobuf(&self, _args: &()) -> models::addons_with_filters::Selected { - models::addons_with_filters::Selected { - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for AddonsWithFilters { - fn to_protobuf(&self, ctx: &Ctx) -> models::AddonsWithFilters { - models::AddonsWithFilters { - selected: self - .remote_addons - .selected - .to_owned() - .map(|selected| models::addons_with_filters::Selected { - request: selected.request.to_protobuf(&()), - }) - .or_else(|| self.installed_addons.selected.to_protobuf(&())), - selectable: models::addons_with_filters::Selectable { - types: match &self.remote_addons.selected.is_some() { - true => self - .remote_addons - .selectable - .types - .iter() - .map( - |selectable_type| models::addons_with_filters::SelectableType { - r#type: selectable_type.r#type.to_string(), - selected: selectable_type.selected, - request: selectable_type.request.to_protobuf(&()), - }, - ) - .collect(), - false => self - .installed_addons - .selectable - .types - .iter() - .map( - |selectable_type| models::addons_with_filters::SelectableType { - r#type: selectable_type.r#type.clone().unwrap_or_default(), - selected: selectable_type.selected, - request: selectable_type.request.to_protobuf(&()), - }, - ) - .collect(), - }, - catalogs: self - .remote_addons - .selectable - .catalogs - .iter() - .map(|catalog| models::addons_with_filters::SelectableCatalog { - name: catalog.catalog.to_owned(), - selected: catalog.selected, - request: catalog.request.to_protobuf(&()), - }) - .chain([models::addons_with_filters::SelectableCatalog { - name: "Installed".to_string(), - selected: self.remote_addons.selected.is_none(), - request: InstalledAddonsRequest { r#type: None }.to_protobuf(&()), - }]) - .collect(), - }, - catalog: match &self.remote_addons.selected { - Some(_) => self - .remote_addons - .catalog - .first() - .map(|page| page.to_protobuf(ctx)), - None => { - self.installed_addons - .selected - .as_ref() - .map(|selected| LoadableAddonCatalog { - request: selected.request.to_protobuf(&()), - content: Some(models::loadable_addon_catalog::Content::Ready( - models::Addons { - items: self.installed_addons.catalog.to_protobuf(ctx), - }, - )), - }) - } - }, - } - } -} diff --git a/src/commonMain/rust/model/fields/catalogs_with_extra.rs b/src/commonMain/rust/model/fields/catalogs_with_extra.rs deleted file mode 100644 index 870ed3c..0000000 --- a/src/commonMain/rust/model/fields/catalogs_with_extra.rs +++ /dev/null @@ -1,51 +0,0 @@ -use stremio_core::deep_links::DiscoverDeepLinks; -use stremio_core::models::catalog_with_filters::Catalog; -use stremio_core::models::catalogs_with_extra::{CatalogsWithExtra, Selected}; -use stremio_core::models::ctx::Ctx; -use stremio_core::types::resource::MetaItemPreview; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::models; - -impl FromProtobuf for models::catalogs_with_extra::Selected { - fn from_protobuf(&self) -> Selected { - Selected { - r#type: self.r#type.clone(), - extra: self.extra.from_protobuf(), - } - } -} - -impl ToProtobuf for Selected { - fn to_protobuf(&self, _args: &()) -> models::catalogs_with_extra::Selected { - models::catalogs_with_extra::Selected { - r#type: self.r#type.clone(), - extra: self.extra.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Catalog { - fn to_protobuf(&self, ctx: &Ctx) -> models::Catalog { - models::Catalog { - pages: self.iter().map(|page| page.to_protobuf(ctx)).collect(), - } - } -} - -impl ToProtobuf for CatalogsWithExtra { - fn to_protobuf(&self, ctx: &Ctx) -> models::CatalogsWithExtra { - models::CatalogsWithExtra { - selected: self.selected.to_protobuf(&()), - catalogs: self.catalogs.to_protobuf(ctx), - } - } -} - -impl ToProtobuf for DiscoverDeepLinks { - fn to_protobuf(&self, _args: &()) -> models::DiscoverDeepLinks { - models::DiscoverDeepLinks { - discover: self.discover.clone(), - } - } -} diff --git a/src/commonMain/rust/model/fields/continue_watching_preview.rs b/src/commonMain/rust/model/fields/continue_watching_preview.rs deleted file mode 100644 index f098d9e..0000000 --- a/src/commonMain/rust/model/fields/continue_watching_preview.rs +++ /dev/null @@ -1,20 +0,0 @@ -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, types}; - -impl ToProtobuf for Item { - fn to_protobuf(&self, ctx: &Ctx) -> types::LibraryItem { - self.library_item - .to_protobuf(&(ctx, Some(self.notifications))) - } -} - -impl ToProtobuf for ContinueWatchingPreview { - fn to_protobuf(&self, ctx: &Ctx) -> models::ContinueWatchingPreview { - models::ContinueWatchingPreview { - library_items: self.items.to_protobuf(ctx), - } - } -} diff --git a/src/commonMain/rust/model/fields/ctx.rs b/src/commonMain/rust/model/fields/ctx.rs deleted file mode 100644 index 19bfb39..0000000 --- a/src/commonMain/rust/model/fields/ctx.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::models; -use stremio_core::models::ctx::Ctx; - -impl ToProtobuf for Ctx { - fn to_protobuf(&self, _args: &()) -> models::Ctx { - models::Ctx { - profile: self.profile.to_protobuf(&()), - events: self.events.to_protobuf(&()), - } - } -} diff --git a/src/commonMain/rust/model/fields/discover.rs b/src/commonMain/rust/model/fields/discover.rs deleted file mode 100644 index 582288e..0000000 --- a/src/commonMain/rust/model/fields/discover.rs +++ /dev/null @@ -1,94 +0,0 @@ -use stremio_core::models::catalog_with_filters::{ - CatalogWithFilters, Selectable, SelectableCatalog, SelectableExtra, SelectableExtraOption, - SelectablePage, SelectableType, Selected, -}; -use stremio_core::models::ctx::Ctx; -use stremio_core::types::resource::MetaItemPreview; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::models; - -impl FromProtobuf for models::catalog_with_filters::Selected { - fn from_protobuf(&self) -> Selected { - Selected { - request: self.request.from_protobuf(), - } - } -} - -impl ToProtobuf for Selected { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::Selected { - models::catalog_with_filters::Selected { - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectableType { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::SelectableType { - models::catalog_with_filters::SelectableType { - r#type: self.r#type.to_string(), - selected: self.selected, - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectableCatalog { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::SelectableCatalog { - models::catalog_with_filters::SelectableCatalog { - name: self.catalog.to_string(), - selected: self.selected, - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectableExtraOption { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::SelectableExtraOption { - models::catalog_with_filters::SelectableExtraOption { - value: self.value.clone(), - selected: self.selected, - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectableExtra { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::SelectableExtra { - models::catalog_with_filters::SelectableExtra { - name: self.name.to_string(), - is_required: self.is_required, - options: self.options.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectablePage { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::SelectablePage { - models::catalog_with_filters::SelectablePage { - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Selectable { - fn to_protobuf(&self, _args: &()) -> models::catalog_with_filters::Selectable { - models::catalog_with_filters::Selectable { - types: self.types.to_protobuf(&()), - catalogs: self.catalogs.to_protobuf(&()), - extra: self.extra.to_protobuf(&()), - next_page: self.next_page.to_protobuf(&()), - } - } -} - -impl ToProtobuf for CatalogWithFilters { - fn to_protobuf(&self, ctx: &Ctx) -> models::CatalogWithFilters { - models::CatalogWithFilters { - selected: self.selected.to_protobuf(&()), - selectable: self.selectable.to_protobuf(&()), - catalog: self.catalog.to_protobuf(ctx), - } - } -} diff --git a/src/commonMain/rust/model/fields/library.rs b/src/commonMain/rust/model/fields/library.rs deleted file mode 100644 index 9c0894f..0000000 --- a/src/commonMain/rust/model/fields/library.rs +++ /dev/null @@ -1,126 +0,0 @@ -use std::cmp; -use std::num::NonZeroUsize; -use stremio_core::models::ctx::Ctx; - -use stremio_core::models::library_with_filters::{ - LibraryRequest, LibraryRequestPage, LibraryWithFilters, Selectable, SelectablePage, - SelectableSort, SelectableType, Selected, Sort, -}; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::models; - -impl FromProtobuf for models::library_with_filters::Sort { - fn from_protobuf(&self) -> Sort { - match self { - models::library_with_filters::Sort::LastWatched => Sort::LastWatched, - models::library_with_filters::Sort::NameReverse => Sort::NameReverse, - models::library_with_filters::Sort::Name => Sort::Name, - models::library_with_filters::Sort::TimesWatched => Sort::TimesWatched, - models::library_with_filters::Sort::Watched => Sort::Watched, - models::library_with_filters::Sort::NotWatched => Sort::NotWatched, - } - } -} - -impl FromProtobuf for models::library_with_filters::LibraryRequest { - fn from_protobuf(&self) -> LibraryRequest { - let page = usize::try_from(cmp::max(self.page, 1)).unwrap_or(usize::MAX); - let page = LibraryRequestPage(NonZeroUsize::new(page).unwrap()); - LibraryRequest { - r#type: self.r#type.to_owned(), - sort: models::library_with_filters::Sort::try_from(self.sort) - .ok() - .from_protobuf() - .unwrap_or(Sort::LastWatched), - page, - } - } -} - -impl FromProtobuf for models::library_with_filters::Selected { - fn from_protobuf(&self) -> Selected { - Selected { - request: self.request.from_protobuf(), - } - } -} - -impl ToProtobuf for Sort { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::Sort { - match self { - Sort::LastWatched => models::library_with_filters::Sort::LastWatched, - Sort::Name => models::library_with_filters::Sort::Name, - Sort::NameReverse => models::library_with_filters::Sort::NameReverse, - Sort::TimesWatched => models::library_with_filters::Sort::TimesWatched, - Sort::Watched => models::library_with_filters::Sort::Watched, - Sort::NotWatched => models::library_with_filters::Sort::NotWatched, - } - } -} - -impl ToProtobuf for LibraryRequest { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::LibraryRequest { - models::library_with_filters::LibraryRequest { - r#type: self.r#type.clone(), - sort: self.sort.to_protobuf(&()) as i32, - page: i64::try_from(self.page.0.get()).unwrap_or(i64::MAX), - } - } -} - -impl ToProtobuf for Selected { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::Selected { - models::library_with_filters::Selected { - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectableType { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::SelectableType { - models::library_with_filters::SelectableType { - r#type: self.r#type.clone(), - selected: self.selected, - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectableSort { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::SelectableSort { - models::library_with_filters::SelectableSort { - sort: self.sort.to_protobuf(&()) as i32, - selected: self.selected, - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for SelectablePage { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::SelectablePage { - models::library_with_filters::SelectablePage { - request: self.request.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Selectable { - fn to_protobuf(&self, _args: &()) -> models::library_with_filters::Selectable { - models::library_with_filters::Selectable { - types: self.types.to_protobuf(&()), - sorts: self.sorts.to_protobuf(&()), - next_page: self.next_page.to_protobuf(&()), - } - } -} - -impl ToProtobuf for LibraryWithFilters { - 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(&(ctx, None)), - } - } -} diff --git a/src/commonMain/rust/model/fields/library_by_type.rs b/src/commonMain/rust/model/fields/library_by_type.rs deleted file mode 100644 index 9d37020..0000000 --- a/src/commonMain/rust/model/fields/library_by_type.rs +++ /dev/null @@ -1,66 +0,0 @@ -use stremio_core::models::ctx::Ctx; -use stremio_core::models::library_by_type::{ - Catalog, LibraryByType, Selectable, SelectableSort, Selected, -}; -use stremio_core::models::library_with_filters::Sort; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::protobuf::stremio::core::models; - -impl FromProtobuf for models::library_by_type::Selected { - fn from_protobuf(&self) -> Selected { - Selected { - sort: models::library_with_filters::Sort::try_from(self.sort) - .ok() - .from_protobuf() - .unwrap_or(Sort::LastWatched), - } - } -} - -impl ToProtobuf for Selected { - fn to_protobuf(&self, _args: &()) -> models::library_by_type::Selected { - models::library_by_type::Selected { - sort: self.sort.to_protobuf(&()) as i32, - } - } -} - -impl ToProtobuf for SelectableSort { - fn to_protobuf(&self, _args: &()) -> models::library_by_type::SelectableSort { - models::library_by_type::SelectableSort { - sort: self.sort.to_protobuf(&()) as i32, - selected: self.selected, - } - } -} - -impl ToProtobuf for Selectable { - fn to_protobuf(&self, _args: &()) -> models::library_by_type::Selectable { - models::library_by_type::Selectable { - sorts: self.sorts.to_protobuf(&()), - } - } -} - -impl ToProtobuf for Catalog { - fn to_protobuf(&self, ctx: &Ctx) -> models::LibraryCatalog { - let items = self - .iter() - .flatten() - .map(|item| item.to_protobuf(&(ctx, None))) - .collect::>(); - let r#type = items.first().map(|item| item.r#type.to_owned()); - models::LibraryCatalog { r#type, items } - } -} - -impl ToProtobuf for LibraryByType { - 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(ctx), - } - } -} diff --git a/src/commonMain/rust/model/fields/link.rs b/src/commonMain/rust/model/fields/link.rs deleted file mode 100644 index ff862cb..0000000 --- a/src/commonMain/rust/model/fields/link.rs +++ /dev/null @@ -1,14 +0,0 @@ -use stremio_core::models::link::Link; -use stremio_core::types::api::LinkAuthKey; - -use crate::bridge::ToProtobuf; -use crate::protobuf::stremio::core::models; - -impl ToProtobuf for Link { - fn to_protobuf(&self, _args: &()) -> models::AuthLink { - models::AuthLink { - code: self.code.to_protobuf(&()), - data: self.data.to_protobuf(&()), - } - } -} diff --git a/src/commonMain/rust/model/fields/meta_details.rs b/src/commonMain/rust/model/fields/meta_details.rs deleted file mode 100644 index 40d2a6b..0000000 --- a/src/commonMain/rust/model/fields/meta_details.rs +++ /dev/null @@ -1,235 +0,0 @@ -use boolinator::Boolinator; -use stremio_core::deep_links::MetaItemDeepLinks; -use stremio_core::models::ctx::Ctx; -use stremio_core::models::meta_details::{MetaDetails, Selected}; -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_watched_bitfield::WatchedBitField; - -use crate::bridge::{FromProtobuf, ToProtobuf}; -use crate::env::AppleEnv; -use crate::protobuf::stremio::core::{models, types}; - -impl FromProtobuf for models::meta_details::Selected { - fn from_protobuf(&self) -> Selected { - Selected { - meta_path: self.meta_path.from_protobuf(), - stream_path: self.stream_path.from_protobuf(), - guess_stream: self.guess_stream_path, - } - } -} - -impl ToProtobuf for Selected { - fn to_protobuf(&self, _args: &()) -> models::meta_details::Selected { - models::meta_details::Selected { - meta_path: self.meta_path.to_protobuf(&()), - stream_path: self.stream_path.to_protobuf(&()), - guess_stream_path: self.guess_stream, - } - } -} - -impl ToProtobuf for SeriesInfo { - fn to_protobuf(&self, _args: &()) -> types::video::SeriesInfo { - types::video::SeriesInfo { - season: self.season as i64, - episode: self.episode as i64, - } - } -} - -impl FromProtobuf 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, - ( - Option<&LibraryItem>, - Option<&WatchedBitField>, - Option<&String>, - ), - > for Video -{ - fn to_protobuf( - &self, - (library_item, watched, addon_name): &( - Option<&LibraryItem>, - Option<&WatchedBitField>, - Option<&String>, - ), - ) -> types::Video { - types::Video { - id: self.id.to_string(), - title: self.title.to_string(), - released: self.released.to_protobuf(&()), - overview: self.overview.clone(), - thumbnail: self.thumbnail.clone(), - streams: self.streams.to_protobuf(&(None, *addon_name, None, None)), - series_info: self.series_info.to_protobuf(&()), - upcoming: self - .released - .map(|released| released > AppleEnv::now()) - .unwrap_or_default(), - watched: watched - .map(|watched| watched.get_video(&self.id)) - .unwrap_or_default(), - current_video: library_item - .and_then(|library_item| library_item.state.video_id.to_owned()) - .map(|current_video_id| current_video_id == self.id) - .unwrap_or_default(), - } - } -} - -impl FromProtobuf