mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-08 17:02:22 +02:00
fixed clippy warnings
This commit is contained in:
@@ -8,36 +8,44 @@ use crate::utils::string_utils::replace_after_last_slash;
|
||||
|
||||
pub const HLS_PREFIX: &str = "hls";
|
||||
|
||||
pub fn rewrite_hls(base_url: &str, content: &str, hls_url: &str, virtual_id: u32,
|
||||
token: u32,
|
||||
user: &ProxyUserCredentials,
|
||||
target_type: &TargetType, input_id: u16) -> (HlsEntry, String) {
|
||||
|
||||
pub struct RewriteHlsProps<'a> {
|
||||
pub base_url: &'a str,
|
||||
pub content: &'a str,
|
||||
pub hls_url: &'a str,
|
||||
pub virtual_id: u32,
|
||||
pub token: u32,
|
||||
pub target_type: TargetType,
|
||||
pub input_id: u16
|
||||
}
|
||||
|
||||
pub fn rewrite_hls(user: &ProxyUserCredentials, props: &RewriteHlsProps ) -> (HlsEntry, String) {
|
||||
let username = &user.username;
|
||||
let password = &user.password;
|
||||
let mut chunk: u32 = 1;
|
||||
let mut chunks = HashMap::new();
|
||||
let mut result = Vec::new();
|
||||
for line in content.lines() {
|
||||
for line in props.content.lines() {
|
||||
if line.starts_with('#') {
|
||||
result.push(line.to_string());
|
||||
} else {
|
||||
let url = if line.starts_with("http") {
|
||||
line.to_string()
|
||||
} else {
|
||||
replace_after_last_slash(hls_url, line)
|
||||
replace_after_last_slash(props.hls_url, line)
|
||||
};
|
||||
chunks.insert(chunk, url);
|
||||
result.push(format!("{base_url}/{HLS_PREFIX}/{token}/{username}/{password}/{virtual_id}/{chunk}"));
|
||||
result.push(format!("{}/{HLS_PREFIX}/{}/{username}/{password}/{}/{chunk}", props.base_url, props.token, props.virtual_id));
|
||||
chunk += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let hls = HlsEntry {
|
||||
ts: Instant::now(),
|
||||
token,
|
||||
target_type: target_type.clone(),
|
||||
input_id,
|
||||
virtual_id,
|
||||
token: props.token,
|
||||
target_type: props.target_type,
|
||||
input_id: props.input_id,
|
||||
virtual_id: props.virtual_id,
|
||||
chunk,
|
||||
chunks,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::model::xmltv::{Epg, TVGuide, XmlTag, EPG_ATTRIB_CHANNEL, EPG_ATTRIB_ID, EPG_TAG_CHANNEL, EPG_TAG_DISPLAY_NAME, EPG_TAG_ICON, EPG_TAG_PROGRAMME, EPG_TAG_TV};
|
||||
use crate::utils::compression::compressed_file_reader::CompressedFileReader;
|
||||
use quick_xml::events::Event;
|
||||
use quick_xml::events::{BytesStart, Event};
|
||||
use quick_xml::Reader;
|
||||
use regex::Regex;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -94,25 +94,8 @@ where
|
||||
Ok(Event::Eof) => break,
|
||||
Ok(Event::Start(e)) => {
|
||||
let name = String::from_utf8_lossy(e.name().as_ref()).as_ref().to_owned();
|
||||
let (is_tv_tag, is_channel, is_program) = match name.as_str() {
|
||||
EPG_TAG_TV => (true, false, false),
|
||||
EPG_TAG_CHANNEL => (false, true, false),
|
||||
EPG_TAG_PROGRAMME => (false, false, true),
|
||||
_ => (false, false, false)
|
||||
};
|
||||
let attributes = e.attributes().filter_map(Result::ok)
|
||||
.filter_map(|a| {
|
||||
let key = String::from_utf8_lossy(a.key.as_ref()).to_string();
|
||||
let mut value = String::from(a.unescape_value().unwrap().as_ref());
|
||||
if (is_channel && key == EPG_ATTRIB_ID) || (is_program && key == EPG_ATTRIB_CHANNEL) {
|
||||
value = value.to_lowercase().to_string();
|
||||
}
|
||||
if value.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((key, value))
|
||||
}
|
||||
}).collect::<HashMap<String, String>>();
|
||||
let (is_tv_tag, is_channel, is_program) = get_tag_types(&name);
|
||||
let attributes = collect_tag_attributes(&e, is_channel, is_program);
|
||||
let attribs = if attributes.is_empty() { None } else { Some(Arc::new(attributes)) };
|
||||
let tag = XmlTag {
|
||||
name,
|
||||
@@ -193,6 +176,33 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn get_tag_types(name: &str) -> (bool, bool, bool) {
|
||||
let (is_tv_tag, is_channel, is_program) = match name {
|
||||
EPG_TAG_TV => (true, false, false),
|
||||
EPG_TAG_CHANNEL => (false, true, false),
|
||||
EPG_TAG_PROGRAMME => (false, false, true),
|
||||
_ => (false, false, false)
|
||||
};
|
||||
(is_tv_tag, is_channel, is_program)
|
||||
}
|
||||
|
||||
fn collect_tag_attributes(e: &BytesStart, is_channel: bool, is_program: bool) -> HashMap<String, String> {
|
||||
let attributes = e.attributes().filter_map(Result::ok)
|
||||
.filter_map(|a| {
|
||||
let key = String::from_utf8_lossy(a.key.as_ref()).to_string();
|
||||
let mut value = String::from(a.unescape_value().unwrap().as_ref());
|
||||
if (is_channel && key == EPG_ATTRIB_ID) || (is_program && key == EPG_ATTRIB_CHANNEL) {
|
||||
value = value.to_lowercase().to_string();
|
||||
}
|
||||
if value.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((key, value))
|
||||
}
|
||||
}).collect::<HashMap<String, String>>();
|
||||
attributes
|
||||
}
|
||||
|
||||
pub fn flatten_tvguide(tv_guides: &[Epg]) -> Option<Epg> {
|
||||
if tv_guides.is_empty() {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user