Skip to content

Commit

Permalink
Merge branch 'development' into feat/get-skip-gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
elpiel committed Jan 3, 2024
2 parents a35d577 + 3f6e890 commit a225c2e
Show file tree
Hide file tree
Showing 52 changed files with 1,197 additions and 142 deletions.
3 changes: 2 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub const LIBRARY_RECENT_STORAGE_KEY: &str = "library_recent";
pub const STREAMS_STORAGE_KEY: &str = "streams";
pub const SEARCH_HISTORY_STORAGE_KEY: &str = "search_history";
pub const NOTIFICATIONS_STORAGE_KEY: &str = "notifications";
pub const DISMISSED_EVENTS_STORAGE_KEY: &str = "dismissed_events";
pub const LIBRARY_COLLECTION_NAME: &str = "libraryItem";
pub const SEARCH_EXTRA_NAME: &str = "search";
/// `https://{ADDON_UR}/meta/...` resource
Expand All @@ -32,7 +33,7 @@ pub const NOTIFICATION_ITEMS_COUNT: usize = 100;
pub const WATCHED_THRESHOLD_COEF: f64 = 0.7;
pub const CREDITS_THRESHOLD_COEF: f64 = 0.9;
/// The latest migration scheme version
pub const SCHEMA_VERSION: u32 = 11;
pub const SCHEMA_VERSION: u32 = 12;
pub const IMDB_LINK_CATEGORY: &str = "imdb";
pub const GENRES_LINK_CATEGORY: &str = "Genres";
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";
Expand Down
65 changes: 54 additions & 11 deletions src/deep_links/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ pub struct OpenPlayerLink {
#[derive(Default, Serialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ExternalPlayerLink {
pub href: Option<String>,
pub download: Option<String>,
pub streaming: Option<String>,
/// m3u data URI
pub playlist: Option<String>,
/// Filename of the playlist
pub file_name: Option<String>,
pub open_player: Option<OpenPlayerLink>,
pub android_tv: Option<String>,
/// External URL for Web
pub web: Option<Url>,
/// External URI for Android TV
pub android_tv: Option<Url>,
/// External payload for Tizen
pub tizen: Option<String>,
/// External payload for webOS
pub webos: Option<String>,
pub file_name: Option<String>,
}

/// Using `&Option<Url>` is not encouraged, use `.as_ref()` to get an `Option<&Url>` instead!
Expand All @@ -69,9 +76,8 @@ impl From<(&Stream, Option<&Url>, &Settings)> for ExternalPlayerLink {
let http_regex = Regex::new(r"https?://").unwrap();
let download = stream.download_url();
let streaming = stream.streaming_url(streaming_server_url);
let m3u_uri = stream.m3u_data_uri(streaming_server_url);
let file_name = m3u_uri.as_ref().map(|_| "playlist.m3u".to_owned());
let href = m3u_uri.or_else(|| download.to_owned());
let playlist = stream.m3u_data_uri(streaming_server_url);
let file_name = playlist.as_ref().map(|_| "playlist.m3u".to_owned());
let open_player = match &streaming {
Some(url) => match settings.player_type.as_ref() {
Some(player_type) => match player_type.as_str() {
Expand Down Expand Up @@ -126,28 +132,31 @@ impl From<(&Stream, Option<&Url>, &Settings)> for ExternalPlayerLink {
},
None => None,
};
let (android_tv, tizen, webos) = match &stream.source {
let (web, android_tv, tizen, webos) = match &stream.source {
StreamSource::External {
external_url,
android_tv_url,
tizen_url,
webos_url,
..
} => (
android_tv_url.as_ref().map(|url| url.to_string()),
external_url.to_owned(),
android_tv_url.to_owned(),
tizen_url.to_owned(),
webos_url.to_owned(),
),
_ => (None, None, None),
_ => (None, None, None, None),
};
ExternalPlayerLink {
href,
download,
streaming,
playlist,
file_name,
open_player,
web,
android_tv,
tizen,
webos,
file_name,
}
}
}
Expand Down Expand Up @@ -539,3 +548,37 @@ impl From<(&String, &LibraryRequest)> for LibraryDeepLinks {
}
}
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SearchHistoryItemDeepLinks {
pub search: String,
}

impl From<&String> for SearchHistoryItemDeepLinks {
fn from(query: &String) -> Self {
SearchHistoryItemDeepLinks {
search: format!(
"stremio:///search?query={}",
utf8_percent_encode(query, URI_COMPONENT_ENCODE_SET),
),
}
}
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LocalSearchItemDeepLinks {
pub search: String,
}

impl From<&String> for LocalSearchItemDeepLinks {
fn from(query: &String) -> Self {
LocalSearchItemDeepLinks {
search: format!(
"stremio:///search?query={}",
utf8_percent_encode(query, URI_COMPONENT_ENCODE_SET),
),
}
}
}
29 changes: 24 additions & 5 deletions src/models/ctx/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::constants::LIBRARY_COLLECTION_NAME;
use crate::models::common::{DescriptorLoadable, ResourceLoadable};
use crate::models::common::{DescriptorLoadable, Loadable, ResourceLoadable};
use crate::models::ctx::{
update_library, update_notifications, update_profile, update_search_history, update_streams,
update_trakt_addon, CtxError,
update_events, update_library, update_notifications, update_profile, update_search_history,
update_streams, update_trakt_addon, CtxError,
};
use crate::runtime::msg::{Action, ActionCtx, Event, Internal, Msg};
use crate::runtime::{Effect, EffectFuture, Effects, Env, EnvFutureExt, Update};
use crate::types::api::{
fetch_api, APIRequest, APIResult, AuthRequest, AuthResponse, CollectionResponse,
DatastoreCommand, DatastoreRequest, LibraryItemsResponse, SuccessResponse,
};
use crate::types::events::{DismissedEventsBucket, Events};
use crate::types::library::LibraryBucket;
use crate::types::notifications::NotificationsBucket;
use crate::types::profile::{Auth, AuthKey, Profile};
Expand All @@ -21,7 +22,7 @@ use crate::types::streams::StreamsBucket;
use derivative::Derivative;
use enclose::enclose;
use futures::{future, FutureExt, TryFutureExt};
use serde::{Deserialize, Serialize};
use serde::Serialize;

use tracing::{event, trace, Level};

Expand All @@ -32,7 +33,7 @@ pub enum CtxStatus {
Ready,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Clone, Debug)]
#[cfg_attr(test, derive(Derivative))]
#[cfg_attr(test, derivative(Default))]
pub struct Ctx {
Expand All @@ -47,13 +48,16 @@ pub struct Ctx {
#[serde(skip)]
pub search_history: SearchHistoryBucket,
#[serde(skip)]
pub dismissed_events: DismissedEventsBucket,
#[serde(skip)]
#[cfg_attr(test, derivative(Default(value = "CtxStatus::Ready")))]
pub status: CtxStatus,
#[serde(skip)]
/// Used only for loading the Descriptor and then the descriptor will be discarded
pub trakt_addon: Option<DescriptorLoadable>,
#[serde(skip)]
pub notification_catalogs: Vec<ResourceLoadable<Vec<MetaItem>>>,
pub events: Events,
}

impl Ctx {
Expand All @@ -63,16 +67,22 @@ impl Ctx {
streams: StreamsBucket,
notifications: NotificationsBucket,
search_history: SearchHistoryBucket,
dismissed_events: DismissedEventsBucket,
) -> Self {
Self {
profile,
library,
streams,
search_history,
dismissed_events,
notifications,
trakt_addon: None,
notification_catalogs: vec![],
status: CtxStatus::Ready,
events: Events {
modal: Loadable::Loading,
notification: Loadable::Loading,
},
}
}
}
Expand All @@ -97,6 +107,8 @@ impl<E: Env + 'static> Update<E> for Ctx {
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
let search_history_effects =
update_search_history::<E>(&mut self.search_history, &self.status, msg);
let events_effects =
update_events::<E>(&mut self.events, &mut self.dismissed_events, msg);
let trakt_addon_effects = update_trakt_addon::<E>(
&mut self.trakt_addon,
&self.profile,
Expand All @@ -119,6 +131,7 @@ impl<E: Env + 'static> Update<E> for Ctx {
.join(library_effects)
.join(streams_effects)
.join(search_history_effects)
.join(events_effects)
.join(trakt_addon_effects)
.join(notifications_effects)
}
Expand All @@ -144,6 +157,8 @@ impl<E: Env + 'static> Update<E> for Ctx {
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
let search_history_effects =
update_search_history::<E>(&mut self.search_history, &self.status, msg);
let events_effects =
update_events::<E>(&mut self.events, &mut self.dismissed_events, msg);
let ctx_effects = match &self.status {
CtxStatus::Loading(loading_auth_request)
if loading_auth_request == auth_request =>
Expand Down Expand Up @@ -171,6 +186,7 @@ impl<E: Env + 'static> Update<E> for Ctx {
.join(trakt_addon_effects)
.join(notifications_effects)
.join(search_history_effects)
.join(events_effects)
.join(ctx_effects)
}
_ => {
Expand All @@ -195,12 +211,15 @@ impl<E: Env + 'static> Update<E> for Ctx {
);
let search_history_effects =
update_search_history::<E>(&mut self.search_history, &self.status, msg);
let events_effects =
update_events::<E>(&mut self.events, &mut self.dismissed_events, msg);
profile_effects
.join(library_effects)
.join(streams_effects)
.join(trakt_addon_effects)
.join(notifications_effects)
.join(search_history_effects)
.join(events_effects)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/models/ctx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod update_events;
use update_events::*;

mod update_library;
use update_library::*;

Expand Down
Loading

0 comments on commit a225c2e

Please sign in to comment.