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

Fix external player link streaming server url #557

Merged
merged 5 commits into from
Nov 20, 2023
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
2 changes: 2 additions & 0 deletions src/deep_links/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl From<(&Stream, Option<&Url>, &Settings)> for ExternalPlayerLink {
///
/// [`StreamingServer::base_url`]: crate::models::streaming_server::StreamingServer::base_url
fn from((stream, streaming_server_url, settings): (&Stream, Option<&Url>, &Settings)) -> Self {
// Use streaming_server_url from settings if streaming_server is reachable
let streaming_server_url = streaming_server_url.map(|_| &settings.streaming_server_url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let streaming_server_url = streaming_server_url.map(|_| &settings.streaming_server_url);
// Only if the streaming server is available, make sure to use the settings url
// as it might contain a remote url of the server,
// otherwise, deeplinks will be broken for remote server
let streaming_server_url = streaming_server_url.map(|_| &settings.streaming_server_url);

let http_regex = Regex::new(r"https?://").unwrap();
let download = stream.download_url();
let streaming = stream.streaming_url(streaming_server_url);
Expand Down
9 changes: 3 additions & 6 deletions src/types/resource/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,9 @@ impl Stream {
}
pub fn streaming_url(&self, streaming_server_url: Option<&Url>) -> Option<String> {
match (&self.source, streaming_server_url) {
(StreamSource::Url { url }, _) if url.scheme() != "magnet" => {
match (streaming_server_url, &self.behavior_hints.proxy_headers) {
(
Some(streaming_server_url),
Some(StreamProxyHeaders { request, response }),
) => {
(StreamSource::Url { url }, Some(streaming_server_url)) if url.scheme() != "magnet" => {
match &self.behavior_hints.proxy_headers {
Some(StreamProxyHeaders { request, response }) => {
let mut streaming_url = streaming_server_url.to_owned();
let mut proxy_query = form_urlencoded::Serializer::new(String::new());
let origin = format!("{}://{}", url.scheme(), url.authority());
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/deep_links/external_player_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use url::Url;
const MAGNET_STR_URL: &str = "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce";
const HTTP_STR_URL: &str = "http://domain.root/path";
const BASE64_HTTP_URL: &str = "data:application/octet-stream;charset=utf-8;base64,I0VYVE0zVQojRVhUSU5GOjAKaHR0cDovL2RvbWFpbi5yb290L3BhdGg=";
const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11471";
const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11470";

#[test]
fn external_player_link_magnet() {
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/deep_links/stream_deep_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MAGNET_STR_URL: &str = "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d870
const HTTP_STR_URL: &str = "http://domain.root/path";
const HTTP_WITH_QUERY_STR_URL: &str = "http://domain.root/path?param=some&foo=bar";
const BASE64_HTTP_URL: &str = "data:application/octet-stream;charset=utf-8;base64,I0VYVE0zVQojRVhUSU5GOjAKaHR0cDovL2RvbWFpbi5yb290L3BhdGg=";
const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11471";
const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11470";
const YT_ID: &str = "aqz-KE-bpKQ";

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/deep_links/video_deep_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::convert::TryFrom;
use std::str::FromStr;
use url::Url;

const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11471/";
const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11470/";
const YT_ID: &str = "aqz-KE-bpKQ";

#[test]
Expand Down