Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Addon transport url #516

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/addon_transport/http_transport/http_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ use crate::addon_transport::http_transport::legacy::AddonLegacyTransport;
use crate::addon_transport::AddonTransport;
use crate::constants::{ADDON_LEGACY_PATH, ADDON_MANIFEST_PATH, URI_COMPONENT_ENCODE_SET};
use crate::runtime::{Env, EnvError, EnvFutureExt, TryEnvFuture};
use crate::types::addon::{Manifest, ResourcePath, ResourceResponse};
use crate::types::addon::{Manifest, ResourcePath, ResourceResponse, TransportUrl};
use crate::types::query_params_encode;
use futures::future;
use http::Request;
use percent_encoding::utf8_percent_encode;
use std::marker::PhantomData;
use url::Url;

pub struct AddonHTTPTransport<E: Env> {
transport_url: Url,
transport_url: TransportUrl,
env: PhantomData<E>,
}

impl<E: Env> AddonHTTPTransport<E> {
pub fn new(transport_url: Url) -> Self {
pub fn new(transport_url: TransportUrl) -> Self {
AddonHTTPTransport {
transport_url,
env: PhantomData,
Expand Down
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::addon::{Descriptor, ExtraProp, OptionsLimit};
use crate::types::addon::{Descriptor, ExtraProp, OptionsLimit, TransportUrl};
use lazy_static::lazy_static;
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
use std::collections::HashMap;
Expand Down Expand Up @@ -57,7 +57,7 @@ lazy_static! {
.expect("CINEMETA_URL parse failed");

/// Manifest URL for Cinemeta V3
pub static ref CINEMETA_URL: Url = Url::parse("https://v3-cinemeta.strem.io/manifest.json")
pub static ref CINEMETA_URL: TransportUrl = TransportUrl::parse("https://v3-cinemeta.strem.io/manifest.json")
.expect("CINEMETA_URL parse failed");
pub static ref API_URL: Url = Url::parse("https://api.strem.io").expect("API_URL parse failed");
pub static ref LINK_API_URL: Url =
Expand Down
24 changes: 16 additions & 8 deletions src/models/addon_details.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
use crate::models::common::{descriptor_update, eq_update, DescriptorAction, DescriptorLoadable};
use crate::models::ctx::Ctx;
use crate::runtime::msg::{Action, ActionLoad, Internal, Msg};
use crate::runtime::{Effects, Env, UpdateWithCtx};
use crate::types::addon::Descriptor;
use crate::types::profile::Profile;
use serde::{Deserialize, Serialize};
use url::Url;

use crate::{
models::{
common::{descriptor_update, eq_update, DescriptorAction, DescriptorLoadable},
ctx::Ctx,
},
runtime::{
msg::{Action, ActionLoad, Internal, Msg},
Effects, Env, UpdateWithCtx,
},
types::{
addon::{Descriptor, TransportUrl},
profile::Profile,
},
};

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Selected {
pub transport_url: Url,
pub transport_url: TransportUrl,
}

#[derive(Default, Clone, Serialize)]
Expand Down
10 changes: 5 additions & 5 deletions src/models/common/descriptor_loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ use crate::constants::OFFICIAL_ADDONS;
use crate::models::common::Loadable;
use crate::runtime::msg::{Internal, Msg};
use crate::runtime::{EffectFuture, Effects, Env, EnvError, EnvFutureExt};
use crate::types::addon::{Descriptor, Manifest};
use crate::types::addon::{Descriptor, Manifest, TransportUrl};

use futures::FutureExt;
use serde::Serialize;
use url::Url;

/// Fetching addons
#[derive(PartialEq, Serialize, Clone, Debug)]
pub struct DescriptorLoadable {
pub transport_url: Url,
pub transport_url: TransportUrl,
pub content: Loadable<Descriptor, EnvError>,
}

pub enum DescriptorAction<'a> {
/// Requests the addon [`Descriptor`]
DescriptorRequested {
/// The transport_url is unique for every addon.
transport_url: &'a Url,
transport_url: &'a TransportUrl,
},
/// Loads the manifest for the addon of the [`Descriptor`]
ManifestRequestResult {
transport_url: &'a Url,
transport_url: &'a TransportUrl,
result: &'a Result<Manifest, EnvError>,
},
}
Expand Down
7 changes: 4 additions & 3 deletions src/models/ctx/update_trakt_addon.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use percent_encoding::utf8_percent_encode;

use crate::constants::URI_COMPONENT_ENCODE_SET;
use crate::models::common::{
descriptor_update, eq_update, DescriptorAction, DescriptorLoadable, Loadable,
};
use crate::models::ctx::{CtxError, CtxStatus, OtherError};
use crate::runtime::msg::{Action, ActionCtx, Event, Internal, Msg};
use crate::runtime::{Effects, Env};
use crate::types::addon::TransportUrl;
use crate::types::profile::Profile;
use percent_encoding::utf8_percent_encode;
use url::Url;

pub fn update_trakt_addon<E: Env + 'static>(
trakt_addon: &mut Option<DescriptorLoadable>,
Expand All @@ -25,7 +26,7 @@ pub fn update_trakt_addon<E: Env + 'static>(
Some(uid) => descriptor_update::<E>(
trakt_addon,
DescriptorAction::DescriptorRequested {
transport_url: &Url::parse(&format!(
transport_url: &TransportUrl::parse(&format!(
"https://www.strem.io/trakt/addon/{}/manifest.json",
utf8_percent_encode(&uid, URI_COMPONENT_ENCODE_SET)
))
Expand Down
4 changes: 2 additions & 2 deletions src/models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ mod test {
constants::YOUTUBE_ADDON_ID_PREFIX,
models::common::{Loadable, ResourceLoadable},
types::{
addon::{ResourcePath, ResourceRequest},
addon::{ResourcePath, ResourceRequest, TransportUrl},
resource::{SeriesInfo, Stream, Video},
},
unit_tests::TestEnv,
Expand All @@ -833,7 +833,7 @@ mod test {
let next_youtube_stream = Stream::youtube(&next_youtube_1234).unwrap();

let youtube_base = "https://youtube.com"
.parse::<Url>()
.parse::<TransportUrl>()
.expect("Valid youtube url");
let next_streams = ResourceLoadable {
request: ResourceRequest {
Expand Down
20 changes: 11 additions & 9 deletions src/runtime/env.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use std::fmt;

use chrono::{DateTime, Utc};
use futures::{future, Future, TryFutureExt};
use http::Request;
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize, Serializer};

use crate::addon_transport::{AddonHTTPTransport, AddonTransport, UnsupportedTransport};
use crate::constants::{
LIBRARY_RECENT_STORAGE_KEY, LIBRARY_STORAGE_KEY, PROFILE_STORAGE_KEY, SCHEMA_VERSION,
SCHEMA_VERSION_STORAGE_KEY,
};
use crate::models::ctx::Ctx;
use crate::models::streaming_server::StreamingServer;
use chrono::{DateTime, Utc};
use futures::{future, Future, TryFutureExt};
use http::Request;
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize, Serializer};
use std::fmt;
use url::Url;
use crate::types::addon::TransportUrl;

pub use conditional_types::{ConditionalSend, EnvFuture, EnvFutureExt};

Expand Down Expand Up @@ -156,13 +158,13 @@ pub trait Env {
) -> serde_json::Value;
#[cfg(debug_assertions)]
fn log(message: String);
fn addon_transport(transport_url: &Url) -> Box<dyn AddonTransport>
fn addon_transport(transport_url: &TransportUrl) -> Box<dyn AddonTransport>
where
Self: Sized + 'static,
{
match transport_url.scheme() {
"http" | "https" => Box::new(AddonHTTPTransport::<Self>::new(transport_url.to_owned())),
_ => Box::new(UnsupportedTransport::new(transport_url.to_owned())),
_ => Box::new(UnsupportedTransport::new(transport_url.into())),
}
}
fn migrate_storage_schema() -> TryEnvFuture<()>
Expand Down
25 changes: 15 additions & 10 deletions src/runtime/msg/event.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::models::ctx::CtxError;
use crate::models::player::AnalyticsContext as PlayerAnalyticsContext;
use crate::types::api::AuthRequest;
use crate::types::library::LibraryItemId;
use crate::types::profile::{AuthKey, Settings, UID};
use serde::Serialize;
use url::Url;

use crate::{
models::{ctx::CtxError, player::AnalyticsContext as PlayerAnalyticsContext},
types::{
addon::TransportUrl,
api::AuthRequest,
library::LibraryItemId,
profile::{AuthKey, Settings, UID},
},
};

///
/// Those messages are meant to be dispatched by the `stremio-core` crate and
/// handled by the users of the `stremio-core` crate and by the `stremio-core`
Expand Down Expand Up @@ -50,10 +55,10 @@ pub enum Event {
uid: UID,
},
AddonsPulledFromAPI {
transport_urls: Vec<Url>,
transport_urls: Vec<TransportUrl>,
},
AddonsPushedToAPI {
transport_urls: Vec<Url>,
transport_urls: Vec<TransportUrl>,
},
LibrarySyncWithAPIPlanned {
uid: UID,
Expand Down Expand Up @@ -81,15 +86,15 @@ pub enum Event {
uid: UID,
},
AddonInstalled {
transport_url: Url,
transport_url: TransportUrl,
id: String,
},
AddonUpgraded {
transport_url: Url,
transport_url: TransportUrl,
id: String,
},
AddonUninstalled {
transport_url: Url,
transport_url: TransportUrl,
id: String,
},
SettingsUpdated {
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/msg/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::models::streaming_server::{
PlaybackDevice, Settings as StreamingServerSettings, StatisticsRequest,
};
use crate::runtime::EnvError;
use crate::types::addon::{Descriptor, Manifest, ResourceRequest, ResourceResponse};
use crate::types::addon::{Descriptor, Manifest, ResourceRequest, ResourceResponse, TransportUrl};
use crate::types::api::{
APIRequest, AuthRequest, DataExportResponse, DatastoreRequest, LinkCodeResponse,
LinkDataResponse,
Expand Down Expand Up @@ -51,7 +51,7 @@ pub enum Internal {
stream: Stream,
meta_id: Option<String>,
video_id: Option<String>,
transport_url: Option<Url>,
transport_url: Option<TransportUrl>,
},
/// Dispatched when library item needs to be updated in the memory, storage and API.
UpdateLibraryItem(LibraryItem),
Expand Down Expand Up @@ -86,7 +86,7 @@ pub enum Internal {
/// Result for fetching resource from addons.
ResourceRequestResult(ResourceRequest, Box<Result<ResourceResponse, EnvError>>),
/// Result for fetching manifest from addon.
ManifestRequestResult(Url, Result<Manifest, EnvError>),
ManifestRequestResult(TransportUrl, Result<Manifest, EnvError>),
/// TODO: write some obvious comment about what it is
NotificationsRequestResult(ResourceRequest, Box<Result<ResourceResponse, EnvError>>),
/// Result for requesting a `dataExport` of user data.
Expand Down
7 changes: 3 additions & 4 deletions src/types/addon/descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::types::addon::{Manifest, ManifestPreview};
use crate::types::addon::{Manifest, ManifestPreview, TransportUrl};
use serde::{Deserialize, Serialize};
use url::Url;

/// Addon descriptor
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Descriptor {
pub manifest: Manifest,
pub transport_url: Url,
pub transport_url: TransportUrl,
#[serde(default)]
pub flags: DescriptorFlags,
}
Expand All @@ -16,7 +15,7 @@ pub struct Descriptor {
#[serde(rename_all = "camelCase")]
pub struct DescriptorPreview {
pub manifest: ManifestPreview,
pub transport_url: Url,
pub transport_url: TransportUrl,
}

#[derive(Default, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down
11 changes: 0 additions & 11 deletions src/types/addon/mod.rs

This file was deleted.

Loading
Loading