Skip to content

Commit

Permalink
Merge branch 'development' into feat/streming-server-urls-bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
kKaskak authored Nov 14, 2024
2 parents 8ee6557 + 645d6ec commit ee5b125
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 41 deletions.
16 changes: 14 additions & 2 deletions src/models/catalog_with_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::models::ctx::Ctx;
use crate::runtime::msg::{Action, ActionCatalogWithFilters, ActionLoad, Internal, Msg};
use crate::runtime::{Effects, Env, UpdateWithCtx};
use crate::types::addon::{
DescriptorPreview, ExtraExt, Manifest, ManifestCatalog, ResourcePath, ResourceRequest,
ResourceResponse,
Descriptor, DescriptorPreview, ExtraExt, Manifest, ManifestCatalog, ResourcePath,
ResourceRequest, ResourceResponse,
};
use crate::types::profile::Profile;
use crate::types::resource::MetaItemPreview;
Expand Down Expand Up @@ -54,6 +54,18 @@ impl CatalogResourceAdapter for DescriptorPreview {
}
}

impl CatalogResourceAdapter for Descriptor {
fn resource() -> &'static str {
"addon_catalog"
}
fn catalogs(manifest: &Manifest) -> &[ManifestCatalog] {
&manifest.addon_catalogs
}
fn selectable_priority() -> SelectablePriority {
SelectablePriority::Catalog
}
}

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct Selected {
pub request: ResourceRequest,
Expand Down
20 changes: 4 additions & 16 deletions src/models/installed_addons_with_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::models::common::{compare_with_priorities, eq_update};
use crate::models::ctx::Ctx;
use crate::runtime::msg::{Action, ActionLoad, Internal, Msg};
use crate::runtime::{Effects, Env, UpdateWithCtx};
use crate::types::addon::{DescriptorPreview, ManifestPreview};
use crate::types::addon::Descriptor;
use crate::types::profile::Profile;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct Selectable {
pub struct InstalledAddonsWithFilters {
pub selected: Option<Selected>,
pub selectable: Selectable,
pub catalog: Vec<DescriptorPreview>,
pub catalog: Vec<Descriptor>,
}

impl InstalledAddonsWithFilters {
Expand Down Expand Up @@ -130,7 +130,7 @@ fn selectable_update(
}

fn catalog_update(
catalog: &mut Vec<DescriptorPreview>,
catalog: &mut Vec<Descriptor>,
selected: &Option<Selected>,
profile: &Profile,
) -> Effects {
Expand All @@ -142,19 +142,7 @@ fn catalog_update(
Some(r#type) => addon.manifest.types.contains(r#type),
None => true,
})
.map(|addon| DescriptorPreview {
transport_url: addon.transport_url.to_owned(),
manifest: ManifestPreview {
id: addon.manifest.id.to_owned(),
version: addon.manifest.version.to_owned(),
name: addon.manifest.name.to_owned(),
description: addon.manifest.description.to_owned(),
logo: addon.manifest.logo.to_owned(),
background: addon.manifest.background.to_owned(),
types: addon.manifest.types.to_owned(),
behavior_hints: addon.manifest.behavior_hints.to_owned(),
},
})
.cloned()
.collect::<Vec<_>>(),
_ => vec![],
};
Expand Down
9 changes: 9 additions & 0 deletions src/types/addon/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ pub struct DescriptorPreview {
pub transport_url: Url,
}

impl From<&Descriptor> for DescriptorPreview {
fn from(value: &Descriptor) -> Self {
Self {
manifest: (&value.manifest).into(),
transport_url: value.transport_url.clone(),
}
}
}

#[derive(Default, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct DescriptorFlags {
Expand Down
15 changes: 15 additions & 0 deletions src/types/addon/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ pub struct ManifestPreview {
pub behavior_hints: ManifestBehaviorHints,
}

impl From<&Manifest> for ManifestPreview {
fn from(manifest_full: &Manifest) -> Self {
Self {
id: manifest_full.id.clone(),
version: manifest_full.version.clone(),
name: manifest_full.name.clone(),
description: manifest_full.description.clone(),
logo: manifest_full.logo.clone(),
background: manifest_full.background.clone(),
types: manifest_full.types.clone(),
behavior_hints: manifest_full.behavior_hints.clone(),
}
}
}

/// Resources supported by the addon.
///
/// # Examples
Expand Down
4 changes: 2 additions & 2 deletions src/types/addon/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{de::Deserializer, Deserialize, Serialize};
use serde_with::{serde_as, VecSkipError};

use crate::types::{
addon::DescriptorPreview,
addon::Descriptor,
resource::{MetaItem, MetaItemPreview, Stream, Subtitles},
};

Expand Down Expand Up @@ -118,7 +118,7 @@ pub enum ResourceResponse {
subtitles: Vec<Subtitles>,
},
Addons {
addons: Vec<DescriptorPreview>,
addons: Vec<Descriptor>,
},
}

Expand Down
18 changes: 12 additions & 6 deletions src/types/streams/streams_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,25 @@ pub struct StreamsItem {
#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StreamItemState {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subtitle_track: Option<SubtitleTrack>,
/// In milliseconds
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subtitle_delay: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
/// Subtitles size, platform dependent units
pub subtitle_size: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
/// Vertical offset of the subtitles, platform dependent units
pub subtitle_offset: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub audio_track: Option<AudioTrack>,
/// In milliseconds
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub audio_delay: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub playback_speed: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub player_type: Option<String>,
}

Expand Down
6 changes: 3 additions & 3 deletions stremio-core-web/src/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use stremio_core::{
},
runtime::Effects,
types::{
addon::DescriptorPreview, api::LinkAuthKey, events::DismissedEventsBucket,
addon::Descriptor, api::LinkAuthKey, events::DismissedEventsBucket,
library::LibraryBucket, notifications::NotificationsBucket, profile::Profile,
resource::MetaItemPreview, search_history::SearchHistoryBucket,
server_urls::ServerUrlsBucket, streams::StreamsBucket,
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct WebModel {
/// Pre-loaded results for local search
pub local_search: LocalSearch,
pub meta_details: MetaDetails,
pub remote_addons: CatalogWithFilters<DescriptorPreview>,
pub remote_addons: CatalogWithFilters<Descriptor>,
pub installed_addons: InstalledAddonsWithFilters,
pub addon_details: AddonDetails,
pub streaming_server: StreamingServer,
Expand All @@ -78,7 +78,7 @@ impl WebModel {
let (continue_watching, continue_watching_effects) =
LibraryWithFilters::<ContinueWatchingFilter>::new(&library, &notifications);
let (remote_addons, remote_addons_effects) =
CatalogWithFilters::<DescriptorPreview>::new(&profile);
CatalogWithFilters::<Descriptor>::new(&profile);
let (installed_addons, installed_addons_effects) =
InstalledAddonsWithFilters::new(&profile);
let (streaming_server, streaming_server_effects) = StreamingServer::new::<WebEnv>(&profile);
Expand Down
23 changes: 17 additions & 6 deletions stremio-core-web/src/model/serialize_installed_addons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ use {
pub use model::*;
mod model {
use serde::Serialize;
use url::Url;

use stremio_core::{
deep_links::AddonsDeepLinks, models::installed_addons_with_filters::Selected,
models::installed_addons_with_filters::Selected,
types::addon::{DescriptorFlags, ManifestPreview},
};

use super::*;

/// Descriptor Preview serializing the [`ManifestPreview`] and
/// [`DescriptorFlags`] of an addon.
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DescriptorPreview<'a> {
#[serde(flatten)]
pub addon: &'a stremio_core::types::addon::DescriptorPreview,
pub struct DescriptorPreview {
pub manifest: ManifestPreview,
pub transport_url: Url,
#[serde(default)]
pub flags: DescriptorFlags,
/// All addons in this model are installed by default!
pub installed: bool,
}
#[derive(Serialize)]
Expand Down Expand Up @@ -44,7 +53,7 @@ mod model {
pub struct InstalledAddonsWithFilters<'a> {
pub selected: &'a Option<Selected>,
pub selectable: Selectable<'a>,
pub catalog: Vec<DescriptorPreview<'a>>,
pub catalog: Vec<DescriptorPreview>,
}
}

Expand Down Expand Up @@ -81,7 +90,9 @@ pub fn serialize_installed_addons(
.catalog
.iter()
.map(|addon| model::DescriptorPreview {
addon,
manifest: (&addon.manifest).into(),
transport_url: addon.transport_url.clone(),
flags: addon.flags.clone(),
installed: true,
})
.collect(),
Expand Down
12 changes: 6 additions & 6 deletions stremio-core-web/src/model/serialize_remote_addons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use stremio_core::deep_links::AddonsDeepLinks;
use stremio_core::models::catalog_with_filters::{CatalogWithFilters, Selected};
use stremio_core::models::common::Loadable;
use stremio_core::models::ctx::Ctx;
use stremio_core::types::addon::DescriptorPreview;
use stremio_core::types::addon::Descriptor;
#[cfg(feature = "wasm")]
use wasm_bindgen::JsValue;

Expand Down Expand Up @@ -35,15 +35,15 @@ mod model {
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DescriptorPreview<'a> {
pub struct Descriptor<'a> {
#[serde(flatten)]
pub addon: &'a stremio_core::types::addon::DescriptorPreview,
pub addon: &'a stremio_core::types::addon::Descriptor,
pub installed: bool,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ResourceLoadable<'a> {
pub content: Loadable<Vec<DescriptorPreview<'a>>, String>,
pub content: Loadable<Vec<Descriptor<'a>>, String>,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -55,7 +55,7 @@ mod model {
}
#[cfg(feature = "wasm")]
pub fn serialize_remote_addons(
remote_addons: &CatalogWithFilters<DescriptorPreview>,
remote_addons: &CatalogWithFilters<Descriptor>,
ctx: &Ctx,
) -> JsValue {
<JsValue as JsValueSerdeExt>::from_serde(&model::CatalogWithFilters {
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn serialize_remote_addons(
Some(Loadable::Ready(addons)) => Loadable::Ready(
addons
.iter()
.map(|addon| model::DescriptorPreview {
.map(|addon| model::Descriptor {
addon,
installed: ctx
.profile
Expand Down

0 comments on commit ee5b125

Please sign in to comment.