Skip to content

Commit

Permalink
feat: deeplinks with stream bucket and CW items
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Sep 13, 2023
1 parent e523982 commit 0e3b8cb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
23 changes: 21 additions & 2 deletions src/deep_links/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ pub struct LibraryItemDeepLinks {
pub external_player: Option<ExternalPlayerLink>,
}

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
Expand All @@ -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
}
Expand Down
37 changes: 31 additions & 6 deletions src/models/continue_watching_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::{
types::{
library::{LibraryBucket, LibraryItem},
notifications::NotificationsBucket,
resource::Stream,
streams::{StreamsBucket, StreamsItemKey},
},
};

Expand All @@ -19,6 +21,7 @@ use crate::{
pub struct Item {
#[serde(flatten)]
pub library_item: LibraryItem,
pub stream: Option<Stream>,
/// a count of the total notifications we have for this item
pub notifications: usize,
}
Expand All @@ -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())
}
}
Expand All @@ -46,7 +53,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> 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(),
}
Expand All @@ -56,6 +63,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for ContinueWatchingPreview {
fn library_items_update(
cw_items: &mut Vec<Item>,
library: &LibraryBucket,
streams: &StreamsBucket,
notifications: &NotificationsBucket,
) -> Effects {
let next_cw_items = library
Expand Down Expand Up @@ -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::<Vec<_>>();

Expand Down

0 comments on commit 0e3b8cb

Please sign in to comment.