From 0e3b8cba615c083fdd748fbeee6ebe9b9e76ae35 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Wed, 13 Sep 2023 11:44:02 +0300 Subject: [PATCH] feat: deeplinks with stream bucket and CW items Signed-off-by: Lachezar Lechev --- src/deep_links/mod.rs | 23 +++++++++++++-- src/models/continue_watching_preview.rs | 37 +++++++++++++++++++++---- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/deep_links/mod.rs b/src/deep_links/mod.rs index b205d1284..b3bbd0097 100644 --- a/src/deep_links/mod.rs +++ b/src/deep_links/mod.rs @@ -143,8 +143,8 @@ pub struct LibraryItemDeepLinks { pub external_player: Option, } -impl From<&LibraryItem> for LibraryItemDeepLinks { - fn from(item: &LibraryItem) -> Self { +impl From<(&LibraryItem, Option<&Stream>)> for LibraryItemDeepLinks { + fn from((item, stream): (&LibraryItem, Option<&Stream>)) -> Self { LibraryItemDeepLinks { meta_details_videos: item .behavior_hints @@ -170,6 +170,25 @@ impl From<&LibraryItem> for LibraryItemDeepLinks { utf8_percent_encode(video_id, URI_COMPONENT_ENCODE_SET) ) }), + // How to build these links using the SteamsBucket?! + // player: stream + // .as_ref() + // .map(|stream| { + // Ok::<_, anyhow::Error>(format!( + // "stremio:///player/{}/{}/{}/{}/{}/{}", + // utf8_percent_encode(&stream.encode()?, URI_COMPONENT_ENCODE_SET), + // utf8_percent_encode(request.base.as_str(), URI_COMPONENT_ENCODE_SET), + // utf8_percent_encode(request.base.as_str(), URI_COMPONENT_ENCODE_SET), + // utf8_percent_encode(&request.path.r#type, URI_COMPONENT_ENCODE_SET), + // utf8_percent_encode(&request.path.id, URI_COMPONENT_ENCODE_SET), + // utf8_percent_encode(&video.id, URI_COMPONENT_ENCODE_SET) + // )) + // }) + // .transpose() + // .unwrap_or_else(|error| Some(ErrorLink::from(error).into())), + // external_player: stream + // .as_ref() + // .map(|stream| ExternalPlayerLink::from((stream, streaming_server_url, settings))), player: None, // TODO use StreamsBucket external_player: None, // TODO use StreamsBucket } diff --git a/src/models/continue_watching_preview.rs b/src/models/continue_watching_preview.rs index 9704b77e9..1fa6bbe93 100644 --- a/src/models/continue_watching_preview.rs +++ b/src/models/continue_watching_preview.rs @@ -11,6 +11,8 @@ use crate::{ types::{ library::{LibraryBucket, LibraryItem}, notifications::NotificationsBucket, + resource::Stream, + streams::{StreamsBucket, StreamsItemKey}, }, }; @@ -19,6 +21,7 @@ use crate::{ pub struct Item { #[serde(flatten)] pub library_item: LibraryItem, + pub stream: Option, /// a count of the total notifications we have for this item pub notifications: usize, } @@ -31,9 +34,13 @@ pub struct ContinueWatchingPreview { } impl ContinueWatchingPreview { - pub fn new(library: &LibraryBucket, notifications: &NotificationsBucket) -> (Self, Effects) { + pub fn new( + library: &LibraryBucket, + streams: &StreamsBucket, + notifications: &NotificationsBucket, + ) -> (Self, Effects) { let mut items = vec![]; - let effects = library_items_update(&mut items, library, notifications); + let effects = library_items_update(&mut items, library, streams, notifications); (Self { items }, effects.unchanged()) } } @@ -46,7 +53,7 @@ impl UpdateWithCtx for ContinueWatchingPreview { Msg::Internal(Internal::LibraryChanged(true)) // notifications have been updated | Msg::Internal(Internal::NotificationsChanged) => { - library_items_update(&mut self.items, &ctx.library, &ctx.notifications) + library_items_update(&mut self.items, &ctx.library, &ctx.streams, &ctx.notifications) } _ => Effects::none().unchanged(), } @@ -56,6 +63,7 @@ impl UpdateWithCtx for ContinueWatchingPreview { fn library_items_update( cw_items: &mut Vec, library: &LibraryBucket, + streams: &StreamsBucket, notifications: &NotificationsBucket, ) -> Effects { let next_cw_items = library @@ -115,9 +123,26 @@ fn library_items_update( b_time.cmp(&a_time) }) .take(CATALOG_PREVIEW_SIZE) - .map(|(library_item, notifications)| Item { - library_item: library_item.clone(), - notifications, + .map(|(library_item, notifications)| { + let stream_key = library_item + .state + .video_id + .clone() + .map(|video_id| StreamsItemKey { + meta_id: library_item.id.clone(), + video_id: video_id, + }); + let stream = stream_key.and_then(|key| { + streams + .items + .get(&key) + .map(|stream_item| stream_item.stream.to_owned()) + }); + Item { + library_item: library_item.clone(), + stream, + notifications, + } }) .collect::>();