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

refactor: update streams item logic #523

Merged
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
19 changes: 5 additions & 14 deletions src/deep_links/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
Expand Down
15 changes: 11 additions & 4 deletions src/models/ctx/update_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ pub fn update_streams<E: Env + 'static>(
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(),
};

Expand Down
10 changes: 7 additions & 3 deletions src/types/streams/streams_item.rs
Original file line number Diff line number Diff line change
@@ -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<Utc>,
Expand Down
33 changes: 9 additions & 24 deletions src/unit_tests/deep_links/library_item_deep_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,28 +40,15 @@ const TORRENT_STREAMS_ITEM: Lazy<StreamsItem> = 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(),
}
});
Expand Down