| 55 | } |
| 56 | |
| 57 | pub fn localize_url(url: &str, host: &str) -> String { |
| 58 | if url.starts_with("https://") { |
| 59 | let url = Url::parse(url).unwrap(); |
| 60 | let host = url.host().unwrap().to_string(); |
| 61 | |
| 62 | let mut query = url.query_pairs().into_owned().collect::<BTreeMap<_, _>>(); |
| 63 | |
| 64 | query.insert("host".to_string(), host.clone()); |
| 65 | |
| 66 | return finalize_url(url.path(), query); |
| 67 | } else if url.ends_with(".m3u8") || url.ends_with(".ts") { |
| 68 | let mut query = BTreeMap::new(); |
| 69 | query.insert("host".to_string(), host.to_string()); |
| 70 | |
| 71 | return finalize_url(url, query); |
| 72 | } |
| 73 | |
| 74 | url.to_string() |
| 75 | } |
| 76 | |
| 77 | pub fn escape_xml(raw: &str) -> Cow<'_, str> { |
| 78 | if !raw.contains(&['<', '>', '&', '\'', '"'][..]) { |