Skip to content

Commit

Permalink
bump core again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Nov 10, 2023
1 parent 409dd35 commit 9371d36
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 52 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/commonMain/rust/bridge/loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ impl
}
}

impl
ToProtobuf<
models::loadable_stream::Content,
(&Ctx, &String, &ResourceRequest, Option<&ResourceRequest>),
> for Loadable<Option<Stream>, 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<models::loadable_subtitles::Content, Option<&String>>
for Loadable<Vec<Subtitles>, ResourceError>
{
Expand Down
55 changes: 31 additions & 24 deletions src/commonMain/rust/bridge/resource_loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use stremio_core::types::addon::{DescriptorPreview, ResourceRequest};
use stremio_core::types::library::LibraryItem;
use stremio_core::types::resource::{MetaItem, MetaItemPreview, Stream, Subtitles};
use stremio_watched_bitfield::WatchedBitField;
use url::Url;

use crate::bridge::ToProtobuf;
use crate::protobuf::stremio::core::models;
Expand Down Expand Up @@ -54,14 +55,7 @@ impl ToProtobuf<models::LoadableMetaItem, (&Ctx, Option<&LibraryItem>, Option<&W
&self,
(ctx, library_item, watched): &(&Ctx, Option<&LibraryItem>, Option<&WatchedBitField>),
) -> models::LoadableMetaItem {
let addon_name = ctx
.profile
.addons
.iter()
.find(|addon| addon.transport_url == self.request.base)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default();
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableMetaItem {
title: addon_name.to_string(),
request: self.request.to_protobuf(&()),
Expand All @@ -82,14 +76,7 @@ impl ToProtobuf<models::LoadableStreams, (&Ctx, Option<&ResourceRequest>)>
&self,
(ctx, meta_request): &(&Ctx, Option<&ResourceRequest>),
) -> models::LoadableStreams {
let addon_name = ctx
.profile
.addons
.iter()
.find(|addon| addon.transport_url == self.request.base)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default();
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableStreams {
title: addon_name.to_owned(),
request: self.request.to_protobuf(&()),
Expand All @@ -100,16 +87,26 @@ impl ToProtobuf<models::LoadableStreams, (&Ctx, Option<&ResourceRequest>)>
}
}

impl ToProtobuf<models::LoadableStream, (&Ctx, Option<&ResourceRequest>)>
for ResourceLoadable<Option<Stream>>
{
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<models::LoadableSubtitles, Ctx> for ResourceLoadable<Vec<Subtitles>> {
fn to_protobuf(&self, ctx: &Ctx) -> models::LoadableSubtitles {
let addon_name = ctx
.profile
.addons
.iter()
.find(|addon| addon.transport_url == self.request.base)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default();
let addon_name = get_addon_name(ctx, &self.request.base);
models::LoadableSubtitles {
title: addon_name.to_owned(),
request: self.request.to_protobuf(&()),
Expand All @@ -135,3 +132,13 @@ impl ToProtobuf<models::LoadableDescriptor, Ctx> for DescriptorLoadable {
}
}
}

fn get_addon_name(ctx: &Ctx, addon_url: &Url) -> String {
ctx.profile
.addons
.iter()
.find(|addon| &addon.transport_url == addon_url)
.map(|addon| &addon.manifest.name)
.cloned()
.unwrap_or_default()
}
25 changes: 1 addition & 24 deletions src/commonMain/rust/model/fields/meta_details.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use boolinator::Boolinator;
use stremio_core::deep_links::MetaItemDeepLinks;
use stremio_core::models::common::Loadable;
use stremio_core::models::ctx::Ctx;
use stremio_core::models::meta_details::{MetaDetails, Selected};
use stremio_core::runtime::Env;
Expand Down Expand Up @@ -218,23 +217,6 @@ impl ToProtobuf<models::MetaDetails, Ctx> for MetaDetails {
})
.unwrap_or_else(|| meta_item.preview.name.to_owned())
});
let suggested_stream_request =
self.suggested_stream.as_ref().and_then(|suggested_stream| {
streams
.iter()
.find(|resource| match &resource.content {
Some(Loadable::Ready(streams)) => streams.contains(suggested_stream),
_ => false,
})
.map(|resource| &resource.request)
});
let suggested_stream_addon_name = suggested_stream_request.and_then(|stream_request| {
ctx.profile
.addons
.iter()
.find(|addon| addon.transport_url == stream_request.base)
.map(|addon| &addon.manifest.name)
});
models::MetaDetails {
selected: self.selected.to_protobuf(&()),
title,
Expand All @@ -244,12 +226,7 @@ impl ToProtobuf<models::MetaDetails, Ctx> for MetaDetails {
self.watched.as_ref(),
)),
streams: streams.to_protobuf(&(ctx, meta_request)),
suggested_stream: self.suggested_stream.to_protobuf(&(
Some(ctx),
suggested_stream_addon_name,
suggested_stream_request,
meta_request,
)),
suggested_stream: self.suggested_stream.to_protobuf(&(ctx, meta_request)),
}
}
}
15 changes: 14 additions & 1 deletion src/main/proto/stremio/core/models/meta_details.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ message MetaDetails {
optional string title = 2;
optional LoadableMetaItem meta_item = 3;
repeated LoadableStreams streams = 4;
optional stremio.core.types.Stream suggested_stream = 5;
optional LoadableStream suggested_stream = 5;

message Selected {
required stremio.core.types.ResourcePath meta_path = 1;
Expand Down Expand Up @@ -45,4 +45,17 @@ message LoadableStreams {

message Streams {
repeated stremio.core.types.Stream streams = 1;
}

message LoadableStream {
required stremio.core.types.ResourceRequest request = 1;
oneof content {
Loading loading = 2;
Error error = 3;
OptionStream ready = 4;
}
}

message OptionStream {
optional stremio.core.types.Stream stream = 1;
}

0 comments on commit 9371d36

Please sign in to comment.