Small code improvements.

This commit is contained in:
Kavin 2023-09-29 13:10:48 +01:00
parent 899997a1ec
commit 59eb2a1db8
No known key found for this signature in database
GPG key ID: 6E4598CA5C92C41F

View file

@ -322,8 +322,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
}
if content_type == "video/vnd.mpeg.dash.mpd" || content_type == "application/dash+xml" {
let mut resp_str = resp.text().await.unwrap();
let clone_resp = resp_str.clone();
let captures = RE_DASH_MANIFEST.captures_iter(&clone_resp);
let captures = RE_DASH_MANIFEST.captures_iter(&resp_str);
for capture in captures {
let url = capture.get(1).unwrap().as_str();
let new_url = localize_url(url, host.as_str());
@ -352,11 +351,7 @@ fn localize_url(url: &str, host: &str) -> String {
return format!("{}?{}", url.path(), url.query().unwrap());
} else if url.ends_with(".m3u8") || url.ends_with(".ts") {
return if url.contains('?') {
format!("{}&host={}", url, host)
} else {
format!("{}?host={}", url, host)
};
format!("{}{}host={}", url, if url.contains('?') { "&" } else { "?" }, host)
}
url.to_string()