add new download field for ExternalPlayerLink
@@ -14,6 +14,7 @@ use serde::Serialize;
#[derive(Default, Serialize, Debug, PartialEq, Eq)]
pub struct ExternalPlayerLink {
pub href: Option<String>,
+ pub download: Option<String>,
pub android_tv: Option<String>,
pub tizen: Option<String>,
pub webos: Option<String>,
@@ -26,6 +27,7 @@ impl From<&Stream> for ExternalPlayerLink {
match &stream.source {
StreamSource::Url { url } if url.scheme() == "magnet" => ExternalPlayerLink {
href: Some(url.as_str().to_owned()),
+ download: Some(url.as_str().to_owned()),
..Default::default()
},
StreamSource::Url { url } => ExternalPlayerLink {
@@ -33,6 +35,7 @@ impl From<&Stream> for ExternalPlayerLink {
"data:application/octet-stream;charset=utf-8;base64,{}",
base64::encode(format!("#EXTM3U\n#EXTINF:0\n{url}"))
)),
+ download: Some(url.as_str().to_owned()),
file_name: Some("playlist.m3u".to_owned()),
..Default::default()
},
@@ -43,6 +46,12 @@ impl From<&Stream> for ExternalPlayerLink {
.map(|magnet_url| magnet_url.to_string())
.expect("Failed to build magnet url for torrent"),
),
+ download: Some(
+ stream
+ .magnet_url()
+ .map(|magnet_url| magnet_url.to_string())
+ .expect("Failed to build magnet url for torrent"),
+ ),
..Default::default()
},
StreamSource::External {
@@ -52,6 +61,7 @@ impl From<&Stream> for ExternalPlayerLink {
webos_url,
} => ExternalPlayerLink {
href: external_url.as_ref().map(|url| url.as_str().to_owned()),
+ download: external_url.as_ref().map(|url| url.as_str().to_owned()),
android_tv: android_tv_url.as_ref().map(|url| url.as_str().to_owned()),
tizen: tizen_url.to_owned(),
webos: webos_url.to_owned(),
@@ -62,10 +72,15 @@ impl From<&Stream> for ExternalPlayerLink {
"https://www.youtube.com/watch?v={}",
utf8_percent_encode(yt_id, URI_COMPONENT_ENCODE_SET)
)),
+ download: Some(format!(
+ "https://www.youtube.com/watch?v={}",
+ utf8_percent_encode(yt_id, URI_COMPONENT_ENCODE_SET)
+ )),
..Default::default()
},
StreamSource::PlayerFrame { player_frame_url } => ExternalPlayerLink {
href: Some(player_frame_url.as_str().to_owned()),
+ download: Some(player_frame_url.as_str().to_owned()),
..Default::default()
},
}
