Replaced actix with axum

This commit is contained in:
euzu
2025-03-11 16:07:06 +01:00
parent 988f87173e
commit fe50ecbb23
60 changed files with 1774 additions and 1934 deletions
+13 -17
View File
@@ -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
}
+6 -7
View File
@@ -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"),
+47 -51
View File
@@ -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()))
}
+1 -1
View File
@@ -11,7 +11,7 @@ use crate::utils::file::file_utils::sanitize_filename;
pub fn process_group_watch(cfg: &Config, target_name: &str, pl: &PlaylistGroup) {
let mut new_tree = BTreeSet::new();
pl.channels.iter().for_each(|chan| {
let header = chan.header.borrow();
let header = &chan.header;
let title = if header.title.is_empty() { header.title.to_string() } else { header.name.to_string() };
new_tree.insert(title);
});
+1 -1
View File
@@ -6,7 +6,7 @@ type AffixProcessor<'a> = Box<dyn Fn(&mut PlaylistItem) + 'a>;
fn create_affix_processor(affix: &InputAffix, is_prefix: bool) -> AffixProcessor {
Box::new(move |channel: &mut PlaylistItem| {
let header = &mut channel.header.borrow_mut();
let header = &mut channel.header;
let value = header.get_field(affix.field.as_str()).map_or_else(|| String::from(&affix.value), |field_value| if is_prefix {
format!("{}{}", &affix.value, field_value.as_str())
} else {
+47 -47
View File
@@ -5,16 +5,13 @@ use crate::model::config::{ConfigInput, ConfigRename};
use crate::utils::network::epg;
use crate::utils::network::m3u;
use crate::utils::network::xtream;
use parking_lot::Mutex;
use core::cmp::Ordering;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::{Arc};
use tokio::sync::Mutex;
use std::thread;
use actix_rt::System;
use log::{debug, error, info, log_enabled, trace, warn, Level};
use std::time::Instant;
use unidecode::unidecode;
@@ -37,7 +34,7 @@ use crate::utils::default_utils::default_as_default;
use crate::utils::{debug_if_enabled};
fn is_valid(pli: &PlaylistItem, target: &ConfigTarget) -> bool {
let provider = ValueProvider { pli: RefCell::new(pli) };
let provider = ValueProvider { pli };
target.filter(&provider)
}
@@ -62,8 +59,8 @@ fn filter_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Opt
}
fn playlistgroup_comparator(a: &PlaylistGroup, b: &PlaylistGroup, group_sort: &ConfigSortGroup, match_as_ascii: bool) -> Ordering {
let value_a = if match_as_ascii { Rc::new(unidecode(&a.title)) } else { Rc::clone(&a.title) };
let value_b = if match_as_ascii { Rc::new(unidecode(&b.title)) } else { Rc::clone(&b.title) };
let value_a = if match_as_ascii { unidecode(&a.title) } else { a.title.to_string() };
let value_b = if match_as_ascii { unidecode(&b.title) } else { b.title.to_string() };
let ordering = value_a.partial_cmp(&value_b).unwrap();
match group_sort.order {
Asc => ordering,
@@ -74,8 +71,8 @@ fn playlistgroup_comparator(a: &PlaylistGroup, b: &PlaylistGroup, group_sort: &C
fn playlistitem_comparator(a: &PlaylistItem, b: &PlaylistItem, channel_sort: &ConfigSortChannel, match_as_ascii: bool) -> Ordering {
let raw_value_a = get_field_value(a, &channel_sort.field);
let raw_value_b = get_field_value(b, &channel_sort.field);
let value_a = if match_as_ascii { Rc::new(unidecode(&raw_value_a)) } else { raw_value_a };
let value_b = if match_as_ascii { Rc::new(unidecode(&raw_value_b)) } else { raw_value_b };
let value_a = if match_as_ascii { unidecode(&raw_value_a) } else { raw_value_a };
let value_b = if match_as_ascii { unidecode(&raw_value_b) } else { raw_value_b };
channel_sort.sequence.as_ref().map_or_else(|| {
let ordering = value_a.partial_cmp(&value_b).unwrap();
match channel_sort.order {
@@ -84,8 +81,8 @@ fn playlistitem_comparator(a: &PlaylistItem, b: &PlaylistItem, channel_sort: &Co
}
}, |custom_order| {
// Check indices in the custom order vector
let index_a = custom_order.iter().position(|s| s == value_a.as_ref());
let index_b = custom_order.iter().position(|s| s == value_b.as_ref());
let index_a = custom_order.iter().position(|s| s == &value_a);
let index_b = custom_order.iter().position(|s| s == &value_b);
match (index_a, index_b) {
(Some(idx_a), Some(idx_b)) => {
@@ -122,7 +119,7 @@ fn sort_playlist(target: &ConfigTarget, new_playlist: &mut [PlaylistGroup]) {
for channel_sort in channel_sorts {
let regexp = channel_sort.re.as_ref().unwrap();
for group in new_playlist.iter_mut() {
let group_title = if match_as_ascii { Rc::new(unidecode(&group.title)) } else { Rc::clone(&group.title) };
let group_title = if match_as_ascii { unidecode(&group.title) } else { group.title.to_string() };
if regexp.is_match(group_title.as_str()) {
group.channels.sort_by(|chan1, chan2| playlistitem_comparator(chan1, chan2, channel_sort, match_as_ascii));
}
@@ -132,17 +129,17 @@ fn sort_playlist(target: &ConfigTarget, new_playlist: &mut [PlaylistGroup]) {
}
}
fn channel_no_playlist(new_playlist: &[PlaylistGroup]) {
fn channel_no_playlist(new_playlist: &mut [PlaylistGroup]) {
let mut chno = 1;
for group in new_playlist {
for chan in &group.channels {
chan.header.borrow_mut().chno = Rc::new(chno.to_string());
for chan in &mut group.channels {
chan.header.chno = chno.to_string();
chno += 1;
}
}
}
fn exec_rename(pli: &PlaylistItem, rename: Option<&Vec<ConfigRename>>) {
fn exec_rename(pli: &mut PlaylistItem, rename: Option<&Vec<ConfigRename>>) {
if let Some(renames) = rename {
if !renames.is_empty() {
let result = pli;
@@ -153,7 +150,7 @@ fn exec_rename(pli: &PlaylistItem, rename: Option<&Vec<ConfigRename>>) {
debug_if_enabled!("Renamed {}={} to {}", &r.field, value, cap);
}
let value = cap.into_owned();
set_field_value(result, &r.field, Rc::new(value));
set_field_value(result, &r.field, value);
}
}
}
@@ -170,7 +167,7 @@ fn rename_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Opt
if matches!(r.field, ItemField::Group) {
let cap = r.re.as_ref().unwrap().replace_all(&grp.title, &r.new_name);
debug_if_enabled!("Renamed group {} to {} for {}", &grp.title, cap, target.name);
grp.title = Rc::new(cap.into_owned());
grp.title = cap.into_owned();
}
}
@@ -193,19 +190,20 @@ macro_rules! apply_pattern {
}};
}
fn map_channel(channel: PlaylistItem, mapping: &Mapping) -> PlaylistItem {
fn map_channel(mut channel: PlaylistItem, mapping: &Mapping) -> PlaylistItem {
if !mapping.mapper.is_empty() {
let header = channel.header.borrow();
let channel_name = if mapping.match_as_ascii { Rc::new(unidecode(&header.name)) } else { header.name.clone() };
let header = &channel.header;
let channel_name = if mapping.match_as_ascii { unidecode(&header.name) } else { header.name.to_string() };
if mapping.match_as_ascii && log_enabled!(Level::Trace) { trace!("Decoded {} for matching to {}", &header.name, &channel_name); };
drop(header);
let ref_chan = RefCell::new(&channel);
let provider = ValueProvider { pli: ref_chan.clone() };
// let ref_chan = &mut channel;
let ref_chan = &mut channel;
let mut mock_processor = MockValueProcessor {};
for m in &mapping.mapper {
let mut processor = MappingValueProcessor { pli: ref_chan.clone(), mapper: m };
let provider = ValueProvider { pli: &ref_chan.clone() };
let mut processor = MappingValueProcessor { pli: ref_chan, mapper: m };
match &m.t_filter {
Some(filter) => {
if filter.filter(&provider, &mut mock_processor) {
apply_pattern!(&m.t_pattern, &provider, &mut processor);
}
@@ -235,15 +233,15 @@ fn map_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Option
let mut grp_id: u32 = 0;
for playlist_group in new_playlist {
for channel in &playlist_group.channels {
let cluster = &channel.header.borrow().xtream_cluster;
let title = &channel.header.borrow().group;
let cluster = &channel.header.xtream_cluster;
let title = &channel.header.group;
if let Some(grp) = new_groups.iter_mut().find(|x| *x.title == **title) {
grp.channels.push(channel.clone());
} else {
grp_id += 1;
new_groups.push(PlaylistGroup {
id: grp_id,
title: Rc::clone(title),
title: title.to_string(),
channels: vec![channel.clone()],
xtream_cluster: *cluster,
});
@@ -256,29 +254,29 @@ fn map_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Option
}
}
fn map_playlist_counter(target: &ConfigTarget, playlist: &[PlaylistGroup]) {
fn map_playlist_counter(target: &ConfigTarget, playlist: &mut [PlaylistGroup]) {
if target.t_mapping.is_some() {
let mut mock_processor = MockValueProcessor {};
let mappings = target.t_mapping.as_ref().unwrap();
for mapping in mappings {
if let Some(counter_list) = &mapping.t_counter {
for counter in counter_list {
for plg in playlist {
for channel in &plg.channels {
let provider = ValueProvider { pli: RefCell::new(channel) };
for plg in &mut *playlist {
for channel in &mut plg.channels {
let provider = ValueProvider { pli: channel };
if counter.filter.filter(&provider, &mut mock_processor) {
let cntval = counter.value.load(core::sync::atomic::Ordering::SeqCst);
let new_value = if counter.modifier == CounterModifier::Assign {
cntval.to_string()
} else {
let value = channel.header.borrow_mut().get_field(&counter.field).map_or_else(String::new, |field_value| field_value.to_string());
let value = channel.header.get_field(&counter.field).map_or_else(String::new, |field_value| field_value.to_string());
if counter.modifier == CounterModifier::Suffix {
format!("{value}{}{cntval}", counter.concat)
} else {
format!("{cntval}{}{value}", counter.concat)
}
};
channel.header.borrow_mut().set_field(&counter.field, new_value.as_str());
channel.header.set_field(&counter.field, new_value.as_str());
counter.value.fetch_add(1, core::sync::atomic::Ordering::SeqCst);
}
}
@@ -401,7 +399,7 @@ async fn process_sources(client: Arc<reqwest::Client>, config: Arc<Config>, user
for (index, _) in config.sources.iter().enumerate() {
// We're using the file lock this way on purpose
let source_lock_path = PathBuf::from(format!("source_{index}"));
let Ok(update_lock) = config.file_locks.try_write_lock(&source_lock_path) else {
let Ok(update_lock) = config.file_locks.try_write_lock(&source_lock_path).await else {
warn!("The update operation for the source at index {index} was skipped because an update is already in progress.");
continue;
};
@@ -414,11 +412,13 @@ async fn process_sources(client: Arc<reqwest::Client>, config: Arc<Config>, user
let http_client = Arc::clone(&client);
let handles = &mut handle_list;
let process = move || {
System::new().block_on(async {
// TODO better way ?
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let (input_stats, target_stats, mut res_errors) = process_source(Arc::clone(&http_client), cfg, index, usr_trgts).await;
shared_errors.lock().append(&mut res_errors);
shared_errors.lock().await.append(&mut res_errors);
let process_stats = SourceStats::new(input_stats, target_stats);
shared_stats.lock().push(process_stats);
shared_stats.lock().await.push(process_stats);
});
};
handles.push(thread::spawn(process));
@@ -427,9 +427,9 @@ async fn process_sources(client: Arc<reqwest::Client>, config: Arc<Config>, user
}
} else {
let (input_stats, target_stats, mut res_errors) = process_source(Arc::clone(&client), cfg, index, usr_trgts).await;
shared_errors.lock().append(&mut res_errors);
shared_errors.lock().await.append(&mut res_errors);
let process_stats = SourceStats::new(input_stats, target_stats);
shared_stats.lock().push(process_stats);
shared_stats.lock().await.push(process_stats);
}
drop(update_lock);
}
@@ -482,9 +482,9 @@ fn execute_pipe<'a>(target: &ConfigTarget, pipe: &ProcessingPipe, fpl: &FetchedP
fn flatten_groups(playlistgroups: Vec<PlaylistGroup>) -> Vec<PlaylistGroup> {
let mut sort_order: Vec<PlaylistGroup> = vec![];
let mut idx: usize = 0;
let mut group_map: HashMap<(Rc<String>, XtreamCluster), usize> = HashMap::new();
let mut group_map: HashMap<(String, XtreamCluster), usize> = HashMap::new();
for group in playlistgroups {
let key = (Rc::clone(&group.title), group.xtream_cluster);
let key = (group.title.to_string(), group.xtream_cluster);
match group_map.entry(key) {
std::collections::hash_map::Entry::Vacant(v) => {
v.insert(idx);
@@ -513,7 +513,7 @@ async fn process_playlist_for_target(client: Arc<reqwest::Client>,
for provider_fpl in playlists.iter_mut() {
let mut processed_fpl = execute_pipe(target, &pipe, provider_fpl, &mut duplicates);
playlist_resolve_series(Arc::clone(&client), cfg, target, errors, &pipe, provider_fpl, &mut processed_fpl).await;
playlist_resolve_vod(Arc::clone(&client), cfg, target, errors, &processed_fpl).await;
playlist_resolve_vod(Arc::clone(&client), cfg, target, errors, &mut processed_fpl).await;
// stats
let input_stats = stats.get_mut(&processed_fpl.input.name);
if let Some(stat) = input_stats {
@@ -535,7 +535,7 @@ async fn process_playlist_for_target(client: Arc<reqwest::Client>,
for mut fp in processed_fetched_playlists {
// collect all epg_channel ids
let epg_channel_ids: HashSet<_> = fp.playlistgroups.iter().flat_map(|g| &g.channels)
.filter_map(|c| c.header.borrow().epg_channel_id.clone()).collect();
.filter_map(|c| c.header.epg_channel_id.clone()).collect();
new_playlist.append(&mut fp.playlistgroups);
if epg_channel_ids.is_empty() {
@@ -554,8 +554,8 @@ async fn process_playlist_for_target(client: Arc<reqwest::Client>,
} else {
let mut flat_new_playlist = flatten_groups(new_playlist);
sort_playlist(target, &mut flat_new_playlist);
channel_no_playlist(&flat_new_playlist);
map_playlist_counter(target, &flat_new_playlist);
channel_no_playlist(&mut flat_new_playlist);
map_playlist_counter(target, &mut flat_new_playlist);
process_watch(target, cfg, &flat_new_playlist);
persist_playlist(&mut flat_new_playlist, flatten_tvguide(&new_epg).as_ref(), target, cfg).await
}
+4 -4
View File
@@ -33,7 +33,7 @@ pub(in crate::processing) async fn playlist_resolve_download_playlist_item(clien
};
}
if resolve_delay > 0 {
actix_web::rt::time::sleep(std::time::Duration::new(u64::from(resolve_delay), 0)).await;
tokio::time::sleep(std::time::Duration::new(u64::from(resolve_delay), 0)).await;
}
result
}
@@ -79,9 +79,9 @@ pub(in crate::processing) fn create_resolve_info_wal_files(cfg: &Config, input:
}
}
pub(in crate::processing) fn should_update_info(pli: &PlaylistItem, processed_provider_ids: &HashMap<u32, u64>, field: &str) -> (bool, u32, u64) {
let Some(provider_id) = pli.header.borrow_mut().get_provider_id() else { return (false, 0, 0) };
let last_modified = pli.header.borrow().get_additional_property_as_u64(field);
pub(in crate::processing) fn should_update_info(pli: &mut PlaylistItem, processed_provider_ids: &HashMap<u32, u64>, field: &str) -> (bool, u32, u64) {
let Some(provider_id) = pli.header.get_provider_id() else { return (false, 0, 0) };
let last_modified = pli.header.get_additional_property_as_u64(field);
let old_timestamp = processed_provider_ids.get(&provider_id);
(old_timestamp.is_none()
|| last_modified.is_none()
+17 -11
View File
@@ -52,7 +52,7 @@ fn write_series_episode_record_to_wal_file(
Ok(())
}
fn should_update_series_info(pli: &PlaylistItem, processed_provider_ids: &HashMap<u32, u64>) -> (bool, u32, u64) {
fn should_update_series_info(pli: &mut PlaylistItem, processed_provider_ids: &HashMap<u32, u64>) -> (bool, u32, u64) {
should_update_info(pli, processed_provider_ids, TAG_SERIES_INFO_LAST_MODIFIED)
}
@@ -69,12 +69,18 @@ async fn playlist_resolve_series_info(client: Arc<reqwest::Client>, cfg: &Config
let mut record_writer = file_writer(&wal_record_file);
let mut content_updated = false;
let series_info_iter = fpl.playlistgroups.iter()
// TODO merge both filters to one
let series_info_count = fpl.playlistgroups.iter()
.filter(|&plg| plg.xtream_cluster == XtreamCluster::Series)
.flat_map(|plg| &plg.channels)
.filter(|&pli| pli.header.borrow().item_type == PlaylistItemType::SeriesInfo);
.filter(|&pli| pli.header.item_type == PlaylistItemType::SeriesInfo).count();
let series_info_iter = fpl.playlistgroups.iter_mut()
.filter(|plg| plg.xtream_cluster == XtreamCluster::Series)
.flat_map(|plg| &mut plg.channels)
.filter(|pli| pli.header.item_type == PlaylistItemType::SeriesInfo);
let series_info_count = series_info_iter.clone().count();
info!("Found {series_info_count} series info to resolve");
let start_time = Instant::now();
let mut processed_series_info_count = 0;
@@ -160,21 +166,21 @@ async fn process_series_info(
for pli in plg
.channels
.iter()
.filter(|pli| pli.header.borrow().item_type == PlaylistItemType::SeriesInfo)
.iter_mut()
.filter(|pli| pli.header.item_type == PlaylistItemType::SeriesInfo)
{
let Some(provider_id) = pli.header.borrow_mut().get_provider_id() else { continue; };
let Some(provider_id) = pli.header.get_provider_id() else { continue; };
let Ok(content) = info_reader.get(&provider_id) else { continue; };
match serde_json::from_str::<serde_json::Value>(&content) {
Ok(series_content) => {
let (group, series_name) = {
let header = pli.header.borrow();
let header = &pli.header;
(header.group.clone(), if header.name.is_empty() {header.title.clone()} else { header.name.clone()})
};
match parse_xtream_series_info(&series_content, &group, &series_name, input) {
Ok(Some(series)) => {
for (episode, pli_episode) in &series {
let Some(provider_id) = &pli_episode.header.borrow_mut().get_provider_id() else { continue; };
Ok(Some(mut series)) => {
for (episode, pli_episode) in &mut series {
let Some(provider_id) = &pli_episode.header.get_provider_id() else { continue; };
handle_error!(write_series_episode_record_to_wal_file(&mut wal_writer, *provider_id, episode),
|err| errors.push(info_err!(format!("Failed to write to series episode wal file: {err}"))));
}
+8 -5
View File
@@ -62,11 +62,11 @@ fn write_vod_info_record_to_wal_file(
Ok(())
}
fn should_update_vod_info(pli: &PlaylistItem, processed_provider_ids: &HashMap<u32, u64>) -> (bool, u32, u64) {
fn should_update_vod_info(pli: &mut PlaylistItem, processed_provider_ids: &HashMap<u32, u64>) -> (bool, u32, u64) {
should_update_info(pli, processed_provider_ids, TAG_VOD_INFO_ADDED)
}
pub async fn playlist_resolve_vod(client: Arc<reqwest::Client>, cfg: &Config, target: &ConfigTarget, errors: &mut Vec<M3uFilterError>, fpl: &FetchedPlaylist<'_>) {
pub async fn playlist_resolve_vod(client: Arc<reqwest::Client>, cfg: &Config, target: &ConfigTarget, errors: &mut Vec<M3uFilterError>, fpl: &mut FetchedPlaylist<'_>) {
let (resolve_movies, resolve_delay) = get_resolve_vod_options(target, fpl);
if !resolve_movies { return; }
@@ -81,11 +81,14 @@ pub async fn playlist_resolve_vod(client: Arc<reqwest::Client>, cfg: &Config, ta
let mut record_writer = file_writer(&wal_record_file);
let mut content_updated = false;
let vod_info_iter = fpl.playlistgroups.iter()
// TODO merge both filters to one
let vod_info_count = fpl.playlistgroups.iter()
.flat_map(|plg| &plg.channels)
.filter(|&pli| pli.header.borrow().xtream_cluster == XtreamCluster::Video);
.filter(|&pli| pli.header.xtream_cluster == XtreamCluster::Video).count();
let vod_info_count = vod_info_iter.clone().count();
let vod_info_iter = fpl.playlistgroups.iter_mut()
.flat_map(|plg| plg.channels.iter_mut())
.filter(|pli| pli.header.xtream_cluster == XtreamCluster::Video);
info!("Found {vod_info_count} vod info to resolve");
let start_time = Instant::now();