From 42685477b288366c0295cddc2de1cffb4306d038 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 15 Sep 2023 16:37:31 +0200 Subject: [PATCH] refactor: update streams item logic --- src/deep_links/mod.rs | 19 +++-------- src/models/ctx/update_streams.rs | 15 ++++++--- src/types/streams/streams_item.rs | 10 ++++-- .../deep_links/library_item_deep_links.rs | 33 +++++-------------- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/deep_links/mod.rs b/src/deep_links/mod.rs index 7ff64fdaa..2e864fbe7 100644 --- a/src/deep_links/mod.rs +++ b/src/deep_links/mod.rs @@ -191,25 +191,16 @@ impl From<(&LibraryItem, Option<&StreamsItem>, Option<&Url>, &Settings)> for Lib "stremio:///player/{}/{}/{}/{}/{}/{}", utf8_percent_encode(&encoded_stream, URI_COMPONENT_ENCODE_SET), utf8_percent_encode( - streams_item.stream_request.base.as_str(), + streams_item.stream_transport_url.as_str(), URI_COMPONENT_ENCODE_SET ), utf8_percent_encode( - streams_item.meta_request.base.as_str(), + streams_item.meta_transport_url.as_str(), URI_COMPONENT_ENCODE_SET ), - utf8_percent_encode( - &streams_item.meta_request.path.r#type, - URI_COMPONENT_ENCODE_SET - ), - utf8_percent_encode( - &streams_item.meta_request.path.id, - URI_COMPONENT_ENCODE_SET - ), - utf8_percent_encode( - &streams_item.stream_request.path.id, - URI_COMPONENT_ENCODE_SET - ) + utf8_percent_encode(&streams_item.r#type, URI_COMPONENT_ENCODE_SET), + utf8_percent_encode(&streams_item.meta_id, URI_COMPONENT_ENCODE_SET), + utf8_percent_encode(&streams_item.video_id, URI_COMPONENT_ENCODE_SET) ), Err(error) => ErrorLink::from(error).into(), }), diff --git a/src/models/ctx/update_streams.rs b/src/models/ctx/update_streams.rs index bb9ea4459..3e8655e9a 100644 --- a/src/models/ctx/update_streams.rs +++ b/src/models/ctx/update_streams.rs @@ -27,14 +27,21 @@ pub fn update_streams( stream_request: Some(stream_request), meta_request: Some(meta_request), }) => { + let meta_id = &meta_request.path.id; + let video_id = &stream_request.path.id; + let key = StreamsItemKey { - meta_id: meta_request.path.id.to_owned(), - video_id: stream_request.path.id.to_owned(), + meta_id: meta_id.to_owned(), + video_id: video_id.to_owned(), }; + let streams_item = StreamsItem { stream: stream.to_owned(), - meta_request: meta_request.to_owned(), - stream_request: stream_request.to_owned(), + r#type: meta_request.path.r#type.to_owned(), + meta_id: meta_id.to_owned(), + video_id: video_id.to_owned(), + meta_transport_url: meta_request.base.to_owned(), + stream_transport_url: stream_request.base.to_owned(), mtime: E::now(), }; diff --git a/src/types/streams/streams_item.rs b/src/types/streams/streams_item.rs index 9bf58293d..d0e91a665 100644 --- a/src/types/streams/streams_item.rs +++ b/src/types/streams/streams_item.rs @@ -1,16 +1,20 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use url::Url; -use crate::types::{addon::ResourceRequest, resource::Stream}; +use crate::types::resource::Stream; #[serde_as] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct StreamsItem { pub stream: Stream, - pub stream_request: ResourceRequest, - pub meta_request: ResourceRequest, + pub r#type: String, + pub meta_id: String, + pub video_id: String, + pub meta_transport_url: Url, + pub stream_transport_url: Url, /// Modification time #[serde(rename = "_mtime")] pub mtime: DateTime, diff --git a/src/unit_tests/deep_links/library_item_deep_links.rs b/src/unit_tests/deep_links/library_item_deep_links.rs index f021ccc20..90637f5c7 100644 --- a/src/unit_tests/deep_links/library_item_deep_links.rs +++ b/src/unit_tests/deep_links/library_item_deep_links.rs @@ -5,8 +5,6 @@ use stremio_serde_hex::{SerHex, Strict}; use crate::constants::STREAMING_SERVER_URL; use crate::deep_links::LibraryItemDeepLinks; use crate::deep_links::OpenPlayerLink; -use crate::types::addon::ResourcePath; -use crate::types::addon::ResourceRequest; use crate::types::library::LibraryItem; use crate::types::library::LibraryItemState; use crate::types::profile::Settings; @@ -42,28 +40,15 @@ const TORRENT_STREAMS_ITEM: Lazy = Lazy::new(|| { StreamsItem { stream, - stream_request: ResourceRequest { - base: "https://torrentio.strem.fun/qualityfilter=1080p,720p/manifest.json" - .parse() - .unwrap(), - path: ResourcePath { - resource: "stream".to_owned(), - r#type: "series".to_owned(), - id: "tt13622776:1:5".to_owned(), - extra: vec![], - }, - }, - meta_request: ResourceRequest { - base: "https://v3-cinemeta.strem.io/manifest.json" - .parse() - .unwrap(), - path: ResourcePath { - resource: "meta".to_owned(), - r#type: "series".to_owned(), - id: "tt13622776".to_owned(), - extra: vec![], - }, - }, + r#type: "series".to_owned(), + meta_id: "tt13622776".to_owned(), + video_id: "tt13622776:1:5".to_owned(), + meta_transport_url: "https://v3-cinemeta.strem.io/manifest.json" + .parse() + .unwrap(), + stream_transport_url: "https://torrentio.strem.fun/qualityfilter=1080p,720p/manifest.json" + .parse() + .unwrap(), mtime: Utc::now(), } });