mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-09 09:22:18 +02:00
Replaced actix with axum
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
use std::borrow::BorrowMut;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::model::config::{Config, ConfigInput};
|
||||
use crate::model::playlist::{PlaylistGroup, PlaylistItem, PlaylistItemHeader, PlaylistItemType, XtreamCluster};
|
||||
use crate::utils::hash_utils::extract_id_from_url;
|
||||
@@ -76,9 +73,9 @@ fn skip_digit(it: &mut std::str::Chars) -> Option<char> {
|
||||
|
||||
fn create_empty_playlistitem_header(input_name: &str, url: &str) -> PlaylistItemHeader {
|
||||
PlaylistItemHeader {
|
||||
url: Rc::new(url.to_owned()),
|
||||
url: url.to_owned(),
|
||||
category_id: 0,
|
||||
input_name: Rc::new(input_name.to_string()),
|
||||
input_name: input_name.to_string(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
@@ -87,7 +84,7 @@ macro_rules! process_header_fields {
|
||||
($header:expr, $token:expr, $(($prop:ident, $field:expr)),*; $val:expr) => {
|
||||
match $token {
|
||||
$(
|
||||
$field => $header.$prop = Rc::new($val),
|
||||
$field => $header.$prop = $val,
|
||||
)*
|
||||
_ => {}
|
||||
}
|
||||
@@ -105,7 +102,7 @@ fn process_header(input: &ConfigInput, video_suffixes: &[&str], content: &str, u
|
||||
break;
|
||||
}
|
||||
if c.unwrap() == ',' {
|
||||
plih.title = Rc::new(get_value(&mut it));
|
||||
plih.title = get_value(&mut it);
|
||||
} else {
|
||||
let token = token_till(&mut it, '=', true);
|
||||
if let Some(t) = token {
|
||||
@@ -127,11 +124,11 @@ fn process_header(input: &ConfigInput, video_suffixes: &[&str], content: &str, u
|
||||
}
|
||||
if plih.id.is_empty() {
|
||||
if let Some(chanid) = extract_id_from_url(url) {
|
||||
plih.id = Rc::new(chanid);
|
||||
plih.id = chanid;
|
||||
}
|
||||
}
|
||||
// plih.virtual_id = plih.id;
|
||||
plih.epg_channel_id = Some(Rc::clone(&plih.id));
|
||||
plih.epg_channel_id = Some(plih.id.to_string());
|
||||
}
|
||||
|
||||
if video_suffixes.iter().any(|suffix| url.ends_with(suffix)) {
|
||||
@@ -177,17 +174,16 @@ where
|
||||
continue;
|
||||
}
|
||||
if let Some(header_value) = header {
|
||||
let item = PlaylistItem { header: RefCell::new(process_header(input, &video_suffixes, &header_value, line)) };
|
||||
let mut header = item.header.borrow_mut();
|
||||
let mut item = PlaylistItem { header: process_header(input, &video_suffixes, &header_value, line) };
|
||||
let header = &mut item.header;
|
||||
if header.group.is_empty() {
|
||||
if let Some(group_value) = group {
|
||||
header.group = Rc::new(group_value);
|
||||
header.group = group_value;
|
||||
} else {
|
||||
let current_title = header.title.clone();
|
||||
header.group = Rc::new(string_utils::get_title_group(current_title.as_str()));
|
||||
header.group = string_utils::get_title_group(current_title.as_str());
|
||||
}
|
||||
}
|
||||
drop(header);
|
||||
visit(item);
|
||||
}
|
||||
header = None;
|
||||
@@ -205,7 +201,7 @@ where
|
||||
consume_m3u(cfg, input, lines, |item| {
|
||||
// keep the original sort order for groups and group the playlist items
|
||||
let key = {
|
||||
let header = item.header.borrow();
|
||||
let header = &item.header;
|
||||
format!("{}{}", &header.xtream_cluster, &header.group)
|
||||
};
|
||||
match group_map.entry(key) {
|
||||
@@ -224,9 +220,9 @@ where
|
||||
// create a group based on the first playlist item
|
||||
let channel = channels.first();
|
||||
let (cluster, group_title) = channel.map(|pli|
|
||||
(pli.header.borrow().xtream_cluster, Rc::clone(&pli.header.borrow().group))).unwrap();
|
||||
(pli.header.xtream_cluster, &pli.header.group)).unwrap();
|
||||
grp_id += 1;
|
||||
PlaylistGroup { id: grp_id, xtream_cluster: cluster, title: Rc::clone(&group_title), channels }
|
||||
PlaylistGroup { id: grp_id, xtream_cluster: cluster, title: group_title.to_string(), channels }
|
||||
}).collect();
|
||||
result
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
|
||||
use std::sync::Arc;
|
||||
use quick_xml::events::Event;
|
||||
use quick_xml::Reader;
|
||||
|
||||
@@ -8,14 +7,14 @@ use crate::model::xmltv::{Epg, EPG_ATTRIB_CHANNEL, EPG_ATTRIB_ID, EPG_TAG_TV, EP
|
||||
use crate::utils::compression::compressed_file_reader::CompressedFileReader;
|
||||
|
||||
impl TVGuide {
|
||||
pub fn filter(&self, channel_ids: &HashSet<Rc<String>>) -> Option<Epg> {
|
||||
pub fn filter(&self, channel_ids: &HashSet<String>) -> Option<Epg> {
|
||||
if channel_ids.is_empty() {
|
||||
return None;
|
||||
}
|
||||
match CompressedFileReader::new(&self.file) {
|
||||
Ok(mut reader) => {
|
||||
let mut children: Vec<XmlTag> = vec![];
|
||||
let mut tv_attributes: Option<Rc<HashMap<String, String>>> = None;
|
||||
let mut tv_attributes: Option<Arc<HashMap<String, String>>> = None;
|
||||
let mut filter_tags = |tag: XmlTag| {
|
||||
if match tag.name.as_str() {
|
||||
EPG_TAG_CHANNEL => {
|
||||
@@ -76,7 +75,7 @@ where
|
||||
let tag = XmlTag {
|
||||
name,
|
||||
value: None,
|
||||
attributes: if attributes.is_empty() { None } else { Some(Rc::new(attributes)) },
|
||||
attributes: if attributes.is_empty() { None } else { Some(Arc::new(attributes)) },
|
||||
children: None,
|
||||
};
|
||||
|
||||
@@ -103,7 +102,7 @@ where
|
||||
}
|
||||
} else if !stack.is_empty() {
|
||||
if let Some(old_tag) = stack.pop().map(|mut r| {
|
||||
let rc_tag = Rc::new(tag);
|
||||
let rc_tag = Arc::new(tag);
|
||||
r.children = Some(
|
||||
r.children.map_or_else(|| vec![rc_tag.clone()], |mut c| {
|
||||
c.push(rc_tag.clone());
|
||||
@@ -182,7 +181,7 @@ mod tests {
|
||||
let tv_guide = TVGuide { file: PathBuf::from(file_path) };
|
||||
|
||||
let channel_ids = vec!["channel.1", "channel.2", "channel.3"];
|
||||
let channel_ids : HashSet<Rc<String>> = channel_ids.into_iter().map(|s| Rc::new(s.to_string())).collect();
|
||||
let channel_ids : HashSet<Arc<String>> = channel_ids.into_iter().map(|s| Arc::new(s.to_string())).collect();
|
||||
|
||||
match tv_guide.filter(&channel_ids) {
|
||||
None => assert!(false, "No epg filtered"),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use std::sync::Arc;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::m3u_filter_error::{M3uFilterError, M3uFilterErrorKind, create_m3u_filter_error_result};
|
||||
@@ -29,13 +27,13 @@ fn map_to_xtream_streams(xtream_cluster: XtreamCluster, streams: &Value) -> Resu
|
||||
}
|
||||
}
|
||||
|
||||
fn create_xtream_series_episode_url(url: &str, username: &str, password: &str, episode: &XtreamSeriesInfoEpisode) -> Rc<String> {
|
||||
fn create_xtream_series_episode_url(url: &str, username: &str, password: &str, episode: &XtreamSeriesInfoEpisode) -> Arc<String> {
|
||||
if episode.direct_source.is_empty() {
|
||||
let ext = episode.container_extension.clone();
|
||||
let stream_base_url = format!("{url}/series/{username}/{password}/{}.{ext}", episode.id);
|
||||
Rc::new(stream_base_url)
|
||||
Arc::new(stream_base_url)
|
||||
} else {
|
||||
Rc::new(episode.direct_source.clone())
|
||||
Arc::new(episode.direct_source.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,21 +49,21 @@ pub fn parse_xtream_series_info(info: &Value, group_title: &str, series_name: &s
|
||||
let episode_url = create_xtream_series_episode_url(url, username, password, episode);
|
||||
(episode.clone(),
|
||||
PlaylistItem {
|
||||
header: RefCell::new(PlaylistItemHeader {
|
||||
id: Rc::new(episode.id.to_string()),
|
||||
uuid: Rc::new(generate_playlist_uuid(&input.name, &episode.id, PlaylistItemType::Series, &episode_url)),
|
||||
name: Rc::new(series_name.to_string()),
|
||||
logo: Rc::new(episode.info.as_ref().map_or_else(String::new, |info| info.movie_image.to_string())),
|
||||
group: Rc::new(group_title.to_string()),
|
||||
title: Rc::new(episode.title.clone()),
|
||||
url: episode_url,
|
||||
header: PlaylistItemHeader {
|
||||
id: episode.id.to_string(),
|
||||
uuid: generate_playlist_uuid(&input.name, &episode.id, PlaylistItemType::Series, &episode_url),
|
||||
name: series_name.to_string(),
|
||||
logo: episode.info.as_ref().map_or_else(String::new, |info| info.movie_image.to_string()),
|
||||
group: group_title.to_string(),
|
||||
title: episode.title.clone(),
|
||||
url: episode_url.to_string(),
|
||||
item_type: PlaylistItemType::Series,
|
||||
xtream_cluster: XtreamCluster::Series,
|
||||
additional_properties: episode.get_additional_properties(&series_info),
|
||||
category_id: 0,
|
||||
input_name: Rc::new(input.name.to_string()),
|
||||
input_name: input.name.to_string(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
})
|
||||
}).collect();
|
||||
return if result.is_empty() { Ok(None) } else { Ok(Some(result)) };
|
||||
@@ -100,13 +98,13 @@ pub fn get_xtream_url(xtream_cluster: XtreamCluster, url: &str,
|
||||
}
|
||||
|
||||
pub fn create_xtream_url(xtream_cluster: XtreamCluster, url: &str, username: &str, password: &str,
|
||||
stream: &XtreamStream, live_stream_use_prefix: bool, live_stream_without_extension: bool) -> Rc<String> {
|
||||
stream: &XtreamStream, live_stream_use_prefix: bool, live_stream_without_extension: bool) -> String {
|
||||
if stream.direct_source.is_empty() {
|
||||
Rc::new(get_xtream_url(xtream_cluster, url, username, password, stream.get_stream_id(),
|
||||
get_xtream_url(xtream_cluster, url, username, password, stream.get_stream_id(),
|
||||
stream.container_extension.as_ref().map(std::string::ToString::to_string).as_ref(),
|
||||
live_stream_use_prefix, live_stream_without_extension))
|
||||
live_stream_use_prefix, live_stream_without_extension)
|
||||
} else {
|
||||
Rc::clone(&stream.direct_source)
|
||||
stream.direct_source.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,65 +114,63 @@ pub fn parse_xtream(input: &ConfigInput,
|
||||
streams: &Value) -> Result<Option<Vec<PlaylistGroup>>, M3uFilterError> {
|
||||
match map_to_xtream_category(categories) {
|
||||
Ok(xtream_categories) => {
|
||||
let input_name = Rc::new(input.name.to_string());
|
||||
let input_name = Arc::new(input.name.to_string());
|
||||
let url = input.url.as_str();
|
||||
let username = input.username.as_ref().map_or("", |v| v);
|
||||
let password = input.password.as_ref().map_or("", |v| v);
|
||||
|
||||
match map_to_xtream_streams(xtream_cluster, streams) {
|
||||
Ok(xtream_streams) => {
|
||||
let mut group_map: HashMap::<Rc<String>, RefCell<XtreamCategory>> =
|
||||
Ok(mut xtream_streams) => {
|
||||
let mut group_map: HashMap::<String, XtreamCategory> =
|
||||
xtream_categories.into_iter().map(|category|
|
||||
(Rc::clone(&category.category_id), RefCell::new(category))
|
||||
(category.category_id.to_string(), category)
|
||||
).collect();
|
||||
let unknown_grp = RefCell::new(XtreamCategory {
|
||||
category_id: Rc::new("0".to_string()),
|
||||
category_name: Rc::new("Unknown".to_string()),
|
||||
let mut unknown_grp = XtreamCategory {
|
||||
category_id: "0".to_string(),
|
||||
category_name: "Unknown".to_string(),
|
||||
channels: vec![],
|
||||
});
|
||||
};
|
||||
|
||||
let (live_stream_use_prefix, live_stream_without_extension) = input.options.as_ref()
|
||||
.map_or((true, false), |o| (o.xtream_live_stream_use_prefix, o.xtream_live_stream_without_extension));
|
||||
|
||||
for stream in xtream_streams {
|
||||
let group = group_map.get(&stream.category_id).unwrap_or(&unknown_grp);
|
||||
let mut grp = group.borrow_mut();
|
||||
let category_name = &grp.category_name;
|
||||
let stream_url = create_xtream_url(xtream_cluster, url, username, password, &stream, live_stream_use_prefix, live_stream_without_extension);
|
||||
for stream in &mut xtream_streams {
|
||||
let group = group_map.get_mut(&stream.category_id).unwrap_or(&mut unknown_grp);
|
||||
let category_name = &group.category_name;
|
||||
let stream_url = create_xtream_url(xtream_cluster, url, username, password, stream, live_stream_use_prefix, live_stream_without_extension);
|
||||
let item_type = PlaylistItemType::from(xtream_cluster);
|
||||
let item = PlaylistItem {
|
||||
header: RefCell::new(PlaylistItemHeader {
|
||||
id: Rc::new(stream.get_stream_id().to_string()),
|
||||
uuid: Rc::new(generate_playlist_uuid(&input_name, &stream.get_stream_id().to_string(), item_type, &stream_url)),
|
||||
name: Rc::clone(&stream.name),
|
||||
logo: Rc::clone(&stream.stream_icon),
|
||||
group: Rc::clone(category_name),
|
||||
title: Rc::clone(&stream.name),
|
||||
url: stream_url,
|
||||
header: PlaylistItemHeader {
|
||||
id: stream.get_stream_id().to_string(),
|
||||
uuid: generate_playlist_uuid(&input_name, &stream.get_stream_id().to_string(), item_type, &stream_url),
|
||||
name: stream.name.to_string(),
|
||||
logo: stream.stream_icon.to_string(),
|
||||
group: category_name.to_string(),
|
||||
title: stream.name.to_string(),
|
||||
url: stream_url.to_string(),
|
||||
epg_channel_id: stream.epg_channel_id.clone(),
|
||||
item_type,
|
||||
xtream_cluster,
|
||||
additional_properties: stream.get_additional_properties(),
|
||||
category_id: 0,
|
||||
input_name: Rc::clone(&input_name),
|
||||
input_name: input_name.to_string(),
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
};
|
||||
grp.add(item);
|
||||
group.add(item);
|
||||
}
|
||||
let has_channels = !unknown_grp.borrow().channels.is_empty();
|
||||
let has_channels = !unknown_grp.channels.is_empty();
|
||||
if has_channels {
|
||||
group_map.insert(Rc::new("0".to_string()), unknown_grp);
|
||||
group_map.insert("0".to_string(), unknown_grp);
|
||||
}
|
||||
|
||||
Ok(Some(group_map.values().filter(|category| !category.borrow().channels.is_empty())
|
||||
Ok(Some(group_map.values().filter(|category| !category.channels.is_empty())
|
||||
.map(|category| {
|
||||
let cat = category.borrow();
|
||||
PlaylistGroup {
|
||||
id: cat.category_id.parse::<u32>().unwrap_or(0),
|
||||
id: category.category_id.parse::<u32>().unwrap_or(0),
|
||||
xtream_cluster,
|
||||
title: Rc::clone(&cat.category_name),
|
||||
channels: cat.channels.clone(),
|
||||
title: category.category_name.to_string(),
|
||||
channels: category.channels.clone(),
|
||||
}
|
||||
}).collect()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user