diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a8789c50..316d2a11a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -321,7 +321,7 @@ server: message: Welcome to tuliprox - name: external protocol: https - host: m3ufilter.mydomain.tv + host: tuliprox.mydomain.tv port: '443' timezone: Europe/Paris message: Welcome to tuliprox diff --git a/README.md b/README.md index 03d88a802..44f9595d7 100644 --- a/README.md +++ b/README.md @@ -1150,7 +1150,7 @@ server: message: Welcome to tuliprox - name: external protocol: https - host: m3ufilter.mydomain.tv + host: tuliprox.mydomain.tv port: '443' timezone: Europe/Paris message: Welcome to tuliprox @@ -1233,7 +1233,7 @@ server: message: Welcome to tuliprox - name: external protocol: https - host: m3ufilter.mydomain.tv + host: tuliprox.mydomain.tv port: '443' timezone: Europe/Paris message: Welcome to tuliprox diff --git a/src/api/endpoints/v1_api.rs b/src/api/endpoints/v1_api.rs index 5df4570bf..afe42fde6 100644 --- a/src/api/endpoints/v1_api.rs +++ b/src/api/endpoints/v1_api.rs @@ -6,7 +6,7 @@ use crate::api::model::config::{ServerConfig, ServerInputConfig, ServerSourceCon use crate::api::model::request::{PlaylistRequest, PlaylistRequestType}; use crate::auth::access_token::create_access_token; use crate::auth::authenticator::validator_admin; -use crate::tuliprox_error::M3uFilterError; +use crate::tuliprox_error::TuliProxError; use crate::model::StatusCheck; use crate::model::XtreamPlaylistItem; use crate::model::{validate_targets, Config, ConfigDto, ConfigInput, ConfigInputOptions, ConfigSource, ConfigTarget, InputType}; @@ -23,7 +23,7 @@ use serde_json::json; use std::collections::{BTreeMap, HashSet}; use std::sync::Arc; -fn intern_save_config_api_proxy(backup_dir: &str, api_proxy: &ApiProxyConfig, file_path: &str) -> Option { +fn intern_save_config_api_proxy(backup_dir: &str, api_proxy: &ApiProxyConfig, file_path: &str) -> Option { match config_reader::save_api_proxy(file_path, backup_dir, api_proxy) { Ok(()) => {} Err(err) => { @@ -34,7 +34,7 @@ fn intern_save_config_api_proxy(backup_dir: &str, api_proxy: &ApiProxyConfig, fi None } -fn intern_save_config_main(file_path: &str, backup_dir: &str, cfg: &ConfigDto) -> Option { +fn intern_save_config_main(file_path: &str, backup_dir: &str, cfg: &ConfigDto) -> Option { match config_reader::save_main_config(file_path, backup_dir, cfg) { Ok(()) => {} Err(err) => { diff --git a/src/api/endpoints/xtream_api.rs b/src/api/endpoints/xtream_api.rs index c954b0a4d..c18556c13 100644 --- a/src/api/endpoints/xtream_api.rs +++ b/src/api/endpoints/xtream_api.rs @@ -12,7 +12,7 @@ use crate::api::model::streams::provider_stream::{create_custom_video_stream_res use crate::api::model::xtream::XtreamAuthorizationResponse; use crate::tuliprox_error::create_tuliprox_error_result; use crate::tuliprox_error::info_err; -use crate::tuliprox_error::{str_to_io_error, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{str_to_io_error, TuliProxError, TuliProxErrorKind}; use crate::model::{ProxyType, ProxyUserCredentials, UserConnectionPermission}; use crate::model::TargetType; use crate::model::{Config, ConfigInput, ConfigTarget}; @@ -80,15 +80,15 @@ impl TryFrom for XtreamApiStreamContext { } impl FromStr for XtreamApiStreamContext { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { match s.to_lowercase().as_str() { Self::LIVE => Ok(Self::Live), Self::MOVIE => Ok(Self::Movie), Self::SERIES => Ok(Self::Series), Self::TIMESHIFT => Ok(Self::Timeshift), - _ => create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown CounterModifier: {}", s) + _ => create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown CounterModifier: {}", s) } } } diff --git a/src/foundation/filter.rs b/src/foundation/filter.rs index 1753f4750..4640a8aa2 100644 --- a/src/foundation/filter.rs +++ b/src/foundation/filter.rs @@ -6,7 +6,7 @@ use log::{debug, error, log_enabled, trace, Level}; use pest::iterators::Pair; use pest::Parser; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::ItemField; use crate::model::{PlaylistItem, PlaylistItemType}; use crate::tools::directed_graph::DirectedGraph; @@ -234,7 +234,7 @@ impl std::fmt::Display for Filter { } } -fn get_parser_item_field(expr: &Pair) -> Result { +fn get_parser_item_field(expr: &Pair) -> Result { if expr.as_rule() == Rule::field { let field_text = expr.as_str(); for item in all::() { @@ -243,13 +243,13 @@ fn get_parser_item_field(expr: &Pair) -> Result } } } - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "unknown field: {}", expr.as_str()) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "unknown field: {}", expr.as_str()) } fn get_parser_regexp( expr: &Pair, templates: &Vec, -) -> Result { +) -> Result { if expr.as_rule() == Rule::regexp { let mut parsed_text = String::from(expr.as_str()); parsed_text.pop(); @@ -257,7 +257,7 @@ fn get_parser_regexp( let regstr = apply_templates_to_pattern(&parsed_text, templates); let re = regex::Regex::new(regstr.as_str()); if re.is_err() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant parse regex: {}", regstr); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant parse regex: {}", regstr); } let regexp = re.unwrap(); let captures = regexp @@ -275,13 +275,13 @@ fn get_parser_regexp( captures, }); } - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "unknown field: {}", expr.as_str()) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "unknown field: {}", expr.as_str()) } fn get_parser_field_comparison( expr: Pair, templates: &Vec, -) -> Result { +) -> Result { let mut expr_inner = expr.into_inner(); match get_parser_item_field(&expr_inner.next().unwrap()) { Ok(field) => match get_parser_regexp(&expr_inner.next().unwrap(), templates) { @@ -311,11 +311,11 @@ fn get_filter_item_type(text_item_type: &str) -> Option { } } -fn get_parser_type_comparison(expr: Pair) -> Result { +fn get_parser_type_comparison(expr: Pair) -> Result { let expr_inner = expr.into_inner(); let text_item_type = expr_inner.as_str(); let item_type = get_filter_item_type(text_item_type); - item_type.map_or_else(|| create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant parse item type: {text_item_type}"), |itype| Ok(Filter::TypeComparison(ItemField::Type, itype))) + item_type.map_or_else(|| create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant parse item type: {text_item_type}"), |itype| Ok(Filter::TypeComparison(ItemField::Type, itype))) } macro_rules! handle_expr { @@ -396,12 +396,12 @@ fn get_parser_expression( stmts.pop().unwrap() } -fn get_parser_binary_op(expr: &Pair) -> Result { +fn get_parser_binary_op(expr: &Pair) -> Result { match expr.as_rule() { Rule::and => Ok(BinaryOperator::And), Rule::or => Ok(BinaryOperator::Or), _ => create_tuliprox_error_result!( - M3uFilterErrorKind::Info, + TuliProxErrorKind::Info, "Unknown binary operator {}", expr.as_str() ), @@ -411,7 +411,7 @@ fn get_parser_binary_op(expr: &Pair) -> Result>, -) -> Result { +) -> Result { let empty_list = Vec::with_capacity(0); let template_list: &Vec = templates.unwrap_or(&empty_list); let source = apply_templates_to_pattern(filter_text, template_list); @@ -472,7 +472,7 @@ pub fn get_filter( result.map_or_else( || { create_tuliprox_error_result!( - M3uFilterErrorKind::Info, + TuliProxErrorKind::Info, "Unable to parse filter: {}", &filter_text ) @@ -480,13 +480,13 @@ pub fn get_filter( Ok, ) } - Err(err) => create_tuliprox_error_result!(M3uFilterErrorKind::Info, "{}", err), + Err(err) => create_tuliprox_error_result!(TuliProxErrorKind::Info, "{}", err), } } fn build_dependency_graph( templates: &Vec, -) -> Result, M3uFilterError> { +) -> Result, TuliProxError> { let mut graph = DirectedGraph::::new(); for template in templates { graph.add_node(&template.name); @@ -509,7 +509,7 @@ fn build_dependency_graph( } if !cycles.is_empty() { return create_tuliprox_error_result!( - M3uFilterErrorKind::Info, + TuliProxErrorKind::Info, "Cyclic dependencies in templates detected!" ); } @@ -518,7 +518,7 @@ fn build_dependency_graph( pub fn prepare_templates( templates: &Vec, -) -> Result, M3uFilterError> { +) -> Result, TuliProxError> { let graph = build_dependency_graph(templates)?; let mut template_values = HashMap::::new(); let mut template_map: HashMap = templates @@ -535,7 +535,7 @@ pub fn prepare_templates( if let Some(depends_on) = dependencies.get(&template_name) { let mut templ_value = template_values.get(&template_name).unwrap().to_string(); for dep_templ_name in depends_on { - let dep_value = template_values.get(dep_templ_name).ok_or_else(|| M3uFilterError::new(M3uFilterErrorKind::Info, format!("Failed to load template {dep_templ_name}")))?; + let dep_value = template_values.get(dep_templ_name).ok_or_else(|| TuliProxError::new(TuliProxErrorKind::Info, format!("Failed to load template {dep_templ_name}")))?; templ_value = templ_value.replace(format!("!{dep_templ_name}!").as_str(), dep_value); } diff --git a/src/m3u_filter_error.rs b/src/m3u_filter_error.rs index ce7c57857..6e92015c7 100644 --- a/src/m3u_filter_error.rs +++ b/src/m3u_filter_error.rs @@ -9,7 +9,7 @@ macro_rules! get_errors_notify_message { } else { let text = $errors .iter() - .filter(|&err| err.kind == M3uFilterErrorKind::Notify) + .filter(|&err| err.kind == TuliProxErrorKind::Notify) .map(|err| err.message.as_str()) .collect::>() .join("\r\n"); @@ -27,7 +27,7 @@ pub use get_errors_notify_message; #[macro_export] macro_rules! notify_err { ($text:expr) => { - M3uFilterError::new(M3uFilterErrorKind::Notify, $text) + TuliProxError::new(TuliProxErrorKind::Notify, $text) }; } @@ -36,7 +36,7 @@ pub use notify_err; #[macro_export] macro_rules! info_err { ($text:expr) => { - M3uFilterError::new(M3uFilterErrorKind::Info, $text) + TuliProxError::new(TuliProxErrorKind::Info, $text) }; } pub use info_err; @@ -45,7 +45,7 @@ pub use info_err; #[macro_export] macro_rules! create_tuliprox_error { ($kind: expr, $($arg:tt)*) => { - M3uFilterError::new($kind, format!($($arg)*)) + TuliProxError::new($kind, format!($($arg)*)) } } pub use create_tuliprox_error; @@ -53,7 +53,7 @@ pub use create_tuliprox_error; #[macro_export] macro_rules! create_tuliprox_error_result { ($kind: expr, $($arg:tt)*) => { - Err(M3uFilterError::new($kind, format!($($arg)*))) + Err(TuliProxError::new($kind, format!($($arg)*))) } } pub use create_tuliprox_error_result; @@ -71,7 +71,7 @@ macro_rules! handle_tuliprox_error_result_list { }) .collect::>(); if !&errors.is_empty() { - return Err(M3uFilterError::new($kind, errors.join("\n"))); + return Err(TuliProxError::new($kind, errors.join("\n"))); } } } @@ -82,7 +82,7 @@ pub use handle_tuliprox_error_result_list; macro_rules! handle_tuliprox_error_result { ($kind:expr, $result: expr) => { if let Err(err) = $result { - return Err(M3uFilterError::new($kind, err.to_string())); + return Err(TuliProxError::new($kind, err.to_string())); } } } @@ -91,31 +91,31 @@ pub use handle_tuliprox_error_result; #[derive(Debug, PartialEq, Eq)] -pub enum M3uFilterErrorKind { +pub enum TuliProxErrorKind { // do not send with messaging Info, Notify, // send with messaging } #[derive(Debug)] -pub struct M3uFilterError { - pub kind: M3uFilterErrorKind, +pub struct TuliProxError { + pub kind: TuliProxErrorKind, pub message: String, } -impl M3uFilterError { - pub const fn new(kind: M3uFilterErrorKind, message: String) -> Self { +impl TuliProxError { + pub const fn new(kind: TuliProxErrorKind, message: String) -> Self { Self { kind, message } } } -impl Display for M3uFilterError { +impl Display for TuliProxError { fn fmt(&self, f: &mut Formatter) -> Result { - write!(f, "M3uFilter error: {}", self.message) + write!(f, "TuliProx error: {}", self.message) } } -impl Error for M3uFilterError {} +impl Error for TuliProxError {} pub fn to_io_error(err: E) -> std::io::Error where diff --git a/src/model/api_proxy.rs b/src/model/api_proxy.rs index 6012c5e3f..9517f18b1 100644 --- a/src/model/api_proxy.rs +++ b/src/model/api_proxy.rs @@ -1,5 +1,5 @@ use crate::api::model::app_state::AppState; -use crate::tuliprox_error::{create_tuliprox_error_result, info_err, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error_result, info_err, TuliProxError, TuliProxErrorKind}; use crate::model::{Config, ClusterFlags}; use crate::repository::user_repository::{backup_api_user_db_file, get_api_user_db_path, load_api_user, merge_api_user}; use crate::utils::default_as_true; @@ -75,9 +75,9 @@ impl Display for ProxyType { } impl FromStr for ProxyType { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { if s == Self::REDIRECT { return Ok(Self::Redirect); } @@ -95,7 +95,7 @@ impl FromStr for ProxyType { } } - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown ProxyType: {}", s) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown ProxyType: {}", s) } } @@ -170,16 +170,16 @@ impl Display for ProxyUserStatus { } impl FromStr for ProxyUserStatus { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { match s { Self::EXPIRED => Ok(Self::Expired), Self::BANNED => Ok(Self::Banned), Self::TRIAL => Ok(Self::Trial), Self::DISABLED => Ok(Self::Disabled), Self::PENDING => Ok(Self::Pending), - _ => create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown ProxyType: {}", s) + _ => create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown ProxyType: {}", s) } } } @@ -238,12 +238,12 @@ impl ProxyUserCredentials { } } - pub fn validate(&self) -> Result<(), M3uFilterError> { + pub fn validate(&self) -> Result<(), TuliProxError> { if self.username.is_empty() { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Username required".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Username required".to_string())); } if self.password.is_empty() { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Password required".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Password required".to_string())); } Ok(()) } @@ -323,7 +323,7 @@ pub struct ApiProxyServerInfo { impl ApiProxyServerInfo { - pub fn prepare(&mut self ) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self ) -> Result<(), TuliProxError> { self.name = self.name.trim().to_string(); if self.name.is_empty() { return Err(info_err!("Server info name is empty ".to_string())); @@ -505,7 +505,7 @@ impl ApiProxyConfig { } } - pub fn prepare(&mut self, cfg: &Config) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, cfg: &Config) -> Result<(), TuliProxError> { let mut errors = Vec::new(); if self.server.is_empty() { errors.push("No server info defined".to_string()); diff --git a/src/model/config.rs b/src/model/config.rs index ae1499ef1..21780a534 100644 --- a/src/model/config.rs +++ b/src/model/config.rs @@ -11,7 +11,7 @@ use path_clean::PathClean; use rand::Rng; use crate::foundation::filter::{prepare_templates, PatternTemplate}; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{ApiProxyConfig, ApiProxyServerInfo, ProxyUserCredentials, Mappings}; use crate::utils::{default_as_default, default_connect_timeout_secs, default_grace_period_millis, default_grace_period_timeout_secs}; use crate::utils::file_lock_manager::FileLockManager; @@ -244,12 +244,12 @@ pub struct StreamConfig { } impl StreamConfig { - fn prepare(&mut self) -> Result<(), M3uFilterError> { + fn prepare(&mut self) -> Result<(), TuliProxError> { if let Some(buffer) = self.buffer.as_mut() { buffer.prepare(); } if let Some(throttle) = &self.throttle { - self.throttle_kbps = parse_to_kbps(throttle).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err))?; + self.throttle_kbps = parse_to_kbps(throttle).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err))?; } if self.grace_period_millis > 0 { @@ -257,7 +257,7 @@ impl StreamConfig { let triple_ms = self.grace_period_millis * 3; self.grace_period_timeout_secs = std::cmp::max(1, triple_ms.div_ceil(1000)); } else if self.grace_period_millis / 1000 > self.grace_period_timeout_secs { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, format!("Grace time period timeout {} sec should be more than grace time period {} ms", self.grace_period_timeout_secs, self.grace_period_millis))); + return Err(TuliProxError::new(TuliProxErrorKind::Info, format!("Grace time period timeout {} sec should be more than grace time period {} ms", self.grace_period_timeout_secs, self.grace_period_millis))); } } @@ -274,12 +274,12 @@ pub struct RateLimitConfig { } impl RateLimitConfig { - fn prepare(&self) -> Result<(), M3uFilterError> { + fn prepare(&self) -> Result<(), TuliProxError> { if self.period_millis == 0 { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Rate limiter period can't be 0".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Rate limiter period can't be 0".to_string())); } if self.burst_size == 0 { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Rate limiter bust can't be 0".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Rate limiter bust can't be 0".to_string())); } Ok(()) } @@ -300,7 +300,7 @@ pub struct ReverseProxyConfig { } impl ReverseProxyConfig { - fn prepare(&mut self, working_dir: &str) -> Result<(), M3uFilterError> { + fn prepare(&mut self, working_dir: &str) -> Result<(), TuliProxError> { if let Some(stream) = self.stream.as_mut() { stream.prepare()?; } @@ -398,26 +398,26 @@ pub struct Config { } impl Config { - pub async fn set_api_proxy(&mut self, api_proxy: Option) -> Result<(), M3uFilterError> { + pub async fn set_api_proxy(&mut self, api_proxy: Option) -> Result<(), TuliProxError> { self.t_api_proxy = Arc::new(RwLock::new(api_proxy)); self.check_target_user().await } - async fn check_username(&self, output_username: Option<&str>, target_name: &str) -> Result<(), M3uFilterError> { + async fn check_username(&self, output_username: Option<&str>, target_name: &str) -> Result<(), TuliProxError> { if let Some(username) = output_username { if let Some((_, config_target)) = self.get_target_for_username(username).await { if config_target.name != target_name { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "User:{username} does not belong to target: {}", target_name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "User:{username} does not belong to target: {}", target_name); } } else { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "User: {username} does not exist"); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "User: {username} does not exist"); } Ok(()) } else { Ok(()) } } - async fn check_target_user(&mut self) -> Result<(), M3uFilterError> { + async fn check_target_user(&mut self) -> Result<(), TuliProxError> { let check_homerun = self.hdhomerun.as_ref().is_some_and(|h| h.enabled); for source in &self.sources { for target in &source.targets { @@ -566,26 +566,26 @@ impl Config { } } - fn check_unique_input_names(&mut self) -> Result<(), M3uFilterError> { + fn check_unique_input_names(&mut self) -> Result<(), TuliProxError> { let mut seen_names = HashSet::new(); for source in &mut self.sources { for input in &source.inputs { let input_name = input.name.trim().to_string(); if input_name.is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "input name required"); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "input name required"); } if seen_names.contains(input_name.as_str()) { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "input names should be unique: {}", input_name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "input names should be unique: {}", input_name); } seen_names.insert(input_name); if let Some(aliases) = &input.aliases { for alias in aliases { let input_name = alias.name.trim().to_string(); if input_name.is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "input name required"); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "input name required"); } if seen_names.contains(input_name.as_str()) { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "input names should be unique: {}", input_name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "input names should be unique: {}", input_name); } seen_names.insert(input_name); } @@ -595,7 +595,7 @@ impl Config { Ok(()) } - fn check_unique_target_names(&mut self) -> Result, M3uFilterError> { + fn check_unique_target_names(&mut self) -> Result, TuliProxError> { let mut seen_names = HashSet::new(); let default_target_name = default_as_default(); for source in &self.sources { @@ -603,11 +603,11 @@ impl Config { // check target name is unique let target_name = target.name.trim().to_string(); if target_name.is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "target name required"); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "target name required"); } if !default_target_name.eq_ignore_ascii_case(target_name.as_str()) { if seen_names.contains(target_name.as_str()) { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "target names should be unique: {}", target_name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "target names should be unique: {}", target_name); } seen_names.insert(target_name); } @@ -616,13 +616,13 @@ impl Config { Ok(seen_names) } - fn check_scheduled_targets(&mut self, target_names: &HashSet) -> Result<(), M3uFilterError> { + fn check_scheduled_targets(&mut self, target_names: &HashSet) -> Result<(), TuliProxError> { if let Some(schedules) = &self.schedules { for schedule in schedules { if let Some(targets) = &schedule.targets { for target_name in targets { if !target_names.contains(target_name) { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown target name in scheduler: {}", target_name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown target name in scheduler: {}", target_name); } } } @@ -634,12 +634,12 @@ impl Config { /** * if `include_computed` set to true for `app_state` */ - pub fn prepare(&mut self, include_computed: bool) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, include_computed: bool) -> Result<(), TuliProxError> { let work_dir = &self.working_dir; self.working_dir = file_utils::get_working_path(work_dir); if include_computed { self.t_access_token_secret = generate_secret(); - self.t_encrypt_secret = <&[u8] as TryInto<[u8; 16]>>::try_into(&generate_secret()[0..16]).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; + self.t_encrypt_secret = <&[u8] as TryInto<[u8; 16]>>::try_into(&generate_secret()[0..16]).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; self.prepare_custom_stream_response(); } self.prepare_directories(); @@ -678,7 +678,7 @@ impl Config { set_directory(&mut self.user_config_dir, "user_config", &self.working_dir); } - fn prepare_hdhomerun(&mut self) -> Result<(), M3uFilterError> { + fn prepare_hdhomerun(&mut self) -> Result<(), TuliProxError> { if let Some(hdhomerun) = self.hdhomerun.as_mut() { if hdhomerun.enabled { hdhomerun.prepare(self.api.port)?; @@ -687,7 +687,7 @@ impl Config { Ok(()) } - fn prepare_sources(&mut self, include_computed: bool) -> Result<(), M3uFilterError> { + fn prepare_sources(&mut self, include_computed: bool) -> Result<(), TuliProxError> { // prepare sources and set id's let mut source_index: u16 = 1; let mut target_index: u16 = 1; @@ -706,7 +706,7 @@ impl Config { Ok(()) } - fn prepare_templates(&mut self) -> Result<(), M3uFilterError> { + fn prepare_templates(&mut self) -> Result<(), TuliProxError> { if let Some(templates) = &mut self.templates { match prepare_templates(templates) { Ok(tmplts) => { @@ -720,14 +720,14 @@ impl Config { Ok(()) } - fn prepare_web(&mut self) -> Result<(), M3uFilterError> { + fn prepare_web(&mut self) -> Result<(), TuliProxError> { if let Some(web_ui_config) = self.web_ui.as_mut() { web_ui_config.prepare(&self.t_config_path)?; } Ok(()) } - fn prepare_video_config(&mut self) -> Result<(), M3uFilterError> { + fn prepare_video_config(&mut self) -> Result<(), TuliProxError> { match &mut self.video { None => { self.video = Some(VideoConfig { @@ -793,7 +793,7 @@ impl Config { /// * `target_args` the program parameters given with `-target` parameter. /// * `sources` configured sources in config file /// -pub fn validate_targets(target_args: Option<&Vec>, sources: &Vec) -> Result { +pub fn validate_targets(target_args: Option<&Vec>, sources: &Vec) -> Result { let mut enabled = true; let mut inputs: Vec = vec![]; let mut targets: Vec = vec![]; @@ -820,7 +820,7 @@ pub fn validate_targets(target_args: Option<&Vec>, sources: &Vec = check_targets.iter().filter(|&(_, v)| *v == 0).map(|(k, _)| k.to_string()).collect(); if !missing_targets.is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "No target found for {}", missing_targets.join(", ")); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "No target found for {}", missing_targets.join(", ")); } // let processing_targets: Vec = check_targets.iter().filter(|&(_, v)| *v != 0).map(|(k, _)| k.to_string()).collect(); // info!("Processing targets {}", processing_targets.join(", ")); diff --git a/src/model/config_download.rs b/src/model/config_download.rs index e901f4613..0ed50f053 100644 --- a/src/model/config_download.rs +++ b/src/model/config_download.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{create_tuliprox_error_result, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error_result, TuliProxError, TuliProxErrorKind}; use regex::Regex; use std::borrow::BorrowMut; use std::collections::HashMap; @@ -35,7 +35,7 @@ impl VideoConfig { /// # Panics /// /// Will panic if default `RegEx` gets invalid - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { if self.extensions.is_empty() { self.extensions = ["mkv", "avi", "mp4", "mpeg", "divx", "mov"] .iter() @@ -57,7 +57,7 @@ impl VideoConfig { downl.t_re_episode_pattern = Some(pattern); } Err(err) => { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant parse regex: {episode_pattern} {err}"); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant parse regex: {episode_pattern} {err}"); } } } diff --git a/src/model/config_epg.rs b/src/model/config_epg.rs index 19ce5cd55..3bbdb0ce8 100644 --- a/src/model/config_epg.rs +++ b/src/model/config_epg.rs @@ -1,6 +1,6 @@ use log::warn; use regex::Regex; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind, create_tuliprox_error_result}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind, create_tuliprox_error_result}; use crate::utils::CONSTANTS; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] @@ -57,7 +57,7 @@ impl EpgSmartMatchConfig { /// let config = EpgSmartMatchConfig::new().unwrap(); /// assert!(config.enabled); /// ``` - pub fn new() -> Result { + pub fn new() -> Result { let mut this = Self { enabled: true, ..Self::default() }; this.prepare()?; Ok(this) @@ -71,8 +71,8 @@ impl EpgSmartMatchConfig { /// /// # Returns /// - /// `Ok(())` if preparation succeeds, or an `M3uFilterError` if regex compilation fails. - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + /// `Ok(())` if preparation succeeds, or an `TuliProxError` if regex compilation fails. + pub fn prepare(&mut self) -> Result<(), TuliProxError> { if !self.enabled { return Ok(()); } @@ -99,7 +99,7 @@ impl EpgSmartMatchConfig { Some(regstr) => { let re = regex::Regex::new(regstr.as_str()); if re.is_err() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant parse regex: {}", regstr); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant parse regex: {}", regstr); } Some(re.unwrap()) } @@ -148,7 +148,7 @@ pub struct EpgConfig { } impl EpgConfig { - pub fn prepare(&mut self, include_computed: bool) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, include_computed: bool) -> Result<(), TuliProxError> { if include_computed { self.t_urls = self.url.as_ref().map_or_else(Vec::new, |epg_url| { match epg_url { diff --git a/src/model/config_input.rs b/src/model/config_input.rs index 538a12811..a3c5415c3 100644 --- a/src/model/config_input.rs +++ b/src/model/config_input.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{create_tuliprox_error_result, handle_tuliprox_error_result_list, info_err, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error_result, handle_tuliprox_error_result_list, info_err, TuliProxError, TuliProxErrorKind}; use crate::model::EpgConfig; use crate::utils::config_reader::csv_read_inputs; use crate::utils::default_as_true; @@ -82,9 +82,9 @@ impl Display for InputType { } impl FromStr for InputType { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { if s.eq(Self::M3U) { Ok(Self::M3u) } else if s.eq(Self::XTREAM) { @@ -94,7 +94,7 @@ impl FromStr for InputType { } else if s.eq(Self::XTREAM_BATCH) { Ok(Self::XtreamBatch) } else { - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown InputType: {}", s) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown InputType: {}", s) } } } @@ -131,15 +131,15 @@ impl Display for InputFetchMethod { } impl FromStr for InputFetchMethod { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { if s.eq(Self::GET_METHOD) { Ok(Self::GET) } else if s.eq(Self::POST_METHOD) { Ok(Self::POST) } else { - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown Fetch Method: {}", s) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown Fetch Method: {}", s) } } } @@ -213,7 +213,7 @@ pub struct ConfigInputAlias { impl ConfigInputAlias { - pub fn prepare(&mut self, index: u16, input_type: &InputType) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, index: u16, input_type: &InputType) -> Result<(), TuliProxError> { self.id = index; self.name = self.name.trim().to_string(); if self.name.is_empty() { @@ -275,7 +275,7 @@ pub struct ConfigInput { impl ConfigInput { #[allow(clippy::cast_possible_truncation)] - pub fn prepare(&mut self, index: u16, include_computed: bool) -> Result { + pub fn prepare(&mut self, index: u16, include_computed: bool) -> Result { self.id = index; self.check_url()?; self.prepare_batch()?; @@ -318,12 +318,12 @@ impl ConfigInput { if let Some(aliases) = self.aliases.as_mut() { let input_type = &self.input_type; - handle_tuliprox_error_result_list!(M3uFilterErrorKind::Info, aliases.iter_mut().enumerate().map(|(idx, i)| i.prepare(index+1+(idx as u16), input_type))); + handle_tuliprox_error_result_list!(TuliProxErrorKind::Info, aliases.iter_mut().enumerate().map(|(idx, i)| i.prepare(index+1+(idx as u16), input_type))); } Ok(index + self.aliases.as_ref().map_or(0, std::vec::Vec::len) as u16) } - fn check_url(&mut self) -> Result<(), M3uFilterError> { + fn check_url(&mut self) -> Result<(), TuliProxError> { self.url = self.url.trim().to_string(); if self.url.is_empty() { return Err(info_err!("url for input is mandatory".to_string())); @@ -331,7 +331,7 @@ impl ConfigInput { Ok(()) } - fn prepare_batch(&mut self) -> Result<(), M3uFilterError> { + fn prepare_batch(&mut self) -> Result<(), TuliProxError> { if self.input_type == InputType::M3uBatch || self.input_type == InputType::XtreamBatch { let input_type = if self.input_type == InputType::M3uBatch { InputType::M3u @@ -364,7 +364,7 @@ impl ConfigInput { } } Err(err) => { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, err.to_string())); } } self.input_type = input_type; diff --git a/src/model/config_ip_check.rs b/src/model/config_ip_check.rs index 29f69378c..5444efe0a 100644 --- a/src/model/config_ip_check.rs +++ b/src/model/config_ip_check.rs @@ -1,5 +1,5 @@ use regex::Regex; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default)] #[serde(deny_unknown_fields)] @@ -31,7 +31,7 @@ pub struct IpCheckConfig { } impl IpCheckConfig { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { if let Some(url) = &self.url { let url = url.trim(); if url.is_empty() { @@ -58,22 +58,22 @@ impl IpCheckConfig { } if self.url.is_none() && self.url_ipv4.is_none() && self.url_ipv6.is_none() { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "No url provided!".to_owned())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "No url provided!".to_owned())); } // TODO allow or do not allow ? // if self.url.is_some() && (self.url_ipv4.is_some() || self.url_ipv6.is_some()) { - // return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "url in combination with ipv4 and/or ipv6 url not allowed!".to_owned())); + // return Err(TuliProxError::new(TuliProxErrorKind::Info, "url in combination with ipv4 and/or ipv6 url not allowed!".to_owned())); // } if let Some(p4) = &self.pattern_ipv4 { self.t_pattern_ipv4 = Some( - Regex::new(p4).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, format!("Invalid IPv4 regex: {p4} {err}")))?, + Regex::new(p4).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, format!("Invalid IPv4 regex: {p4} {err}")))?, ); } if let Some(p6) = &self.pattern_ipv6 { self.t_pattern_ipv6 = Some( - Regex::new(p6).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, format!("Invalid IPv6 regex: {p6} {err}")))?, + Regex::new(p6).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, format!("Invalid IPv6 regex: {p6} {err}")))?, ); } Ok(()) diff --git a/src/model/config_proxy.rs b/src/model/config_proxy.rs index c10a4afb3..9052044d1 100644 --- a/src/model/config_proxy.rs +++ b/src/model/config_proxy.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default)] #[serde(deny_unknown_fields)] @@ -9,24 +9,24 @@ pub struct ProxyConfig { } impl ProxyConfig { - pub(crate) fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub(crate) fn prepare(&mut self) -> Result<(), TuliProxError> { if self.username.is_some() || self.password.is_some() { if let (Some(username), Some(password)) = (self.username.as_ref(), self.password.as_ref()) { let uname = username.trim(); let pwd = password.trim(); if uname.is_empty() || pwd.is_empty() { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Proxy credentials missing".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Proxy credentials missing".to_string())); } self.username = Some(uname.to_string()); self.password = Some(pwd.to_string()); } else { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Proxy credentials missing".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Proxy credentials missing".to_string())); } } self.url = self.url.trim().to_string(); if self.url.is_empty() { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Proxy url missing".to_string())); + return Err(TuliProxError::new(TuliProxErrorKind::Info, "Proxy url missing".to_string())); } Ok(()) } diff --git a/src/model/config_rename.rs b/src/model/config_rename.rs index efe1fb322..04f296f1a 100644 --- a/src/model/config_rename.rs +++ b/src/model/config_rename.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind, create_tuliprox_error_result}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind, create_tuliprox_error_result}; use crate::model::ItemField; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] @@ -12,13 +12,13 @@ pub struct ConfigRename { } impl ConfigRename { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { match regex::Regex::new(&self.pattern) { Ok(pattern) => { self.re = Some(pattern); Ok(()) } - Err(err) => create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant parse regex: {} {err}", &self.pattern), + Err(err) => create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant parse regex: {} {err}", &self.pattern), } } } \ No newline at end of file diff --git a/src/model/config_sort.rs b/src/model/config_sort.rs index 04b1b643c..deee771db 100644 --- a/src/model/config_sort.rs +++ b/src/model/config_sort.rs @@ -1,5 +1,5 @@ use regex::Regex; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind, create_tuliprox_error, handle_tuliprox_error_result_list}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind, create_tuliprox_error, handle_tuliprox_error_result_list}; use crate::model::{ItemField}; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] @@ -10,12 +10,12 @@ pub enum SortOrder { Desc, } -fn compile_regex_vec(patterns: Option<&Vec>) -> Result>, M3uFilterError> { +fn compile_regex_vec(patterns: Option<&Vec>) -> Result>, TuliProxError> { patterns.as_ref() .map(|seq| { seq.iter() .map(|s| Regex::new(s).map_err(|err| { - create_tuliprox_error!(M3uFilterErrorKind::Info, "cant parse regex: {s} {err}") + create_tuliprox_error!(TuliProxErrorKind::Info, "cant parse regex: {s} {err}") })) .collect::, _>>() }) @@ -34,7 +34,7 @@ pub struct ConfigSortGroup { impl ConfigSortGroup { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { // Compile sequence patterns, if any self.t_sequence = compile_regex_vec(self.sequence.as_ref())?; Ok(()) @@ -58,11 +58,11 @@ pub struct ConfigSortChannel { } impl ConfigSortChannel { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { // Compile group_pattern self.t_re_group_pattern = Some( Regex::new(&self.group_pattern).map_err(|err| { - create_tuliprox_error!(M3uFilterErrorKind::Info, "cant parse regex: {} {err}", &self.group_pattern) + create_tuliprox_error!(TuliProxErrorKind::Info, "cant parse regex: {} {err}", &self.group_pattern) })? ); @@ -84,12 +84,12 @@ pub struct ConfigSort { } impl ConfigSort { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { if let Some(group) = self.groups.as_mut() { group.prepare()?; } if let Some(channels) = self.channels.as_mut() { - handle_tuliprox_error_result_list!(M3uFilterErrorKind::Info, channels.iter_mut().map(ConfigSortChannel::prepare)); + handle_tuliprox_error_result_list!(TuliProxErrorKind::Info, channels.iter_mut().map(ConfigSortChannel::prepare)); } Ok(()) } diff --git a/src/model/config_source.rs b/src/model/config_source.rs index 68e1a87b7..2e8a7e8e2 100644 --- a/src/model/config_source.rs +++ b/src/model/config_source.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind, handle_tuliprox_error_result_list}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind, handle_tuliprox_error_result_list}; use crate::model::ConfigInput; use crate::model::config_target::ConfigTarget; @@ -11,8 +11,8 @@ pub struct ConfigSource { impl ConfigSource { #[allow(clippy::cast_possible_truncation)] - pub fn prepare(&mut self, index: u16, include_computed: bool) -> Result { - handle_tuliprox_error_result_list!(M3uFilterErrorKind::Info, self.inputs.iter_mut().enumerate().map(|(idx, i)| i.prepare(index+(idx as u16), include_computed))); + pub fn prepare(&mut self, index: u16, include_computed: bool) -> Result { + handle_tuliprox_error_result_list!(TuliProxErrorKind::Info, self.inputs.iter_mut().enumerate().map(|(idx, i)| i.prepare(index+(idx as u16), include_computed))); Ok(index + (self.inputs.len() as u16)) } diff --git a/src/model/config_target.rs b/src/model/config_target.rs index 4d818a5c6..40b57288c 100644 --- a/src/model/config_target.rs +++ b/src/model/config_target.rs @@ -1,5 +1,5 @@ use crate::foundation::filter::{get_filter, Filter, MockValueProcessor, PatternTemplate, ValueProvider}; -use crate::tuliprox_error::{create_tuliprox_error_result, handle_tuliprox_error_result, handle_tuliprox_error_result_list, info_err, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error_result, handle_tuliprox_error_result, handle_tuliprox_error_result_list, info_err, TuliProxError, TuliProxErrorKind}; use crate::model::cluster_flags::ClusterFlags; use crate::model::config_rename::ConfigRename; use crate::model::config_sort::ConfigSort; @@ -190,7 +190,7 @@ pub struct ConfigTarget { } impl ConfigTarget { - pub fn prepare(&mut self, id: u16, templates: Option<&Vec>) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, id: u16, templates: Option<&Vec>) -> Result<(), TuliProxError> { self.id = id; if self.output.is_empty() { return Err(info_err!(format!("Missing output format for {}", self.name))); @@ -208,7 +208,7 @@ impl ConfigTarget { TargetOutput::Xtream(_) => { xtream_cnt += 1; if default_as_default().eq_ignore_ascii_case(&self.name) { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "unique target name is required for xtream type output: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "unique target name is required for xtream type output: {}", self.name); } } TargetOutput::M3u(m3u_output) => { @@ -219,7 +219,7 @@ impl ConfigTarget { strm_cnt += 1; strm_output.directory = strm_output.directory.trim().to_string(); if strm_output.directory.trim().is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "directory is required for strm type: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "directory is required for strm type: {}", self.name); } if let Some(username) = &mut strm_output.username { *username = username.trim().to_string(); @@ -234,19 +234,19 @@ impl ConfigTarget { hdhr_cnt += 1; hdhomerun_output.username = hdhomerun_output.username.trim().to_string(); if hdhomerun_output.username.is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Username is required for HdHomeRun type: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Username is required for HdHomeRun type: {}", self.name); } hdhomerun_output.device = hdhomerun_output.device.trim().to_string(); if hdhomerun_output.device.is_empty() { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Device is required for HdHomeRun type: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Device is required for HdHomeRun type: {}", self.name); } if let Some(use_output) = hdhomerun_output.use_output.as_ref() { match &use_output { TargetType::M3u => { hdhomerun_needs_m3u = true; } TargetType::Xtream => { hdhomerun_needs_xtream = true; } - _ => return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "HdHomeRun output option `use_output` only accepts `m3u` or `xtream` for target: {}", self.name), + _ => return create_tuliprox_error_result!(TuliProxErrorKind::Info, "HdHomeRun output option `use_output` only accepts `m3u` or `xtream` for target: {}", self.name), } } } @@ -254,22 +254,22 @@ impl ConfigTarget { } if m3u_cnt > 1 || strm_cnt > 1 || xtream_cnt > 1 || hdhr_cnt > 1 { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Multiple output formats with same type : {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Multiple output formats with same type : {}", self.name); } if strm_cnt > 0 && strm_needs_xtream && xtream_cnt == 0 { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "strm output with a username is only permitted when used in combination with xtream output: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "strm output with a username is only permitted when used in combination with xtream output: {}", self.name); } if hdhr_cnt > 0 { if xtream_cnt == 0 && m3u_cnt == 0 { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "HdHomeRun output is only permitted when used in combination with xtream or m3u output: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "HdHomeRun output is only permitted when used in combination with xtream or m3u output: {}", self.name); } if hdhomerun_needs_m3u && m3u_cnt == 0 { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "HdHomeRun output has `use_output=m3u` but no `m3u` output defined: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "HdHomeRun output has `use_output=m3u` but no `m3u` output defined: {}", self.name); } if hdhomerun_needs_xtream && xtream_cnt == 0 { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "HdHomeRun output has `use_output=xtream` but no `xtream` output defined: {}", self.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "HdHomeRun output has `use_output=xtream` but no `xtream` output defined: {}", self.name); } } @@ -278,7 +278,7 @@ impl ConfigTarget { match regexps { Ok(watch_re) => self.t_watch_re = Some(watch_re), Err(err) => { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Invalid watch regular expression: {}", err); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Invalid watch regular expression: {}", err); } } } @@ -288,10 +288,10 @@ impl ConfigTarget { // debug!("Filter: {}", fltr); self.t_filter = Some(fltr); if let Some(renames) = self.rename.as_mut() { - handle_tuliprox_error_result_list!(M3uFilterErrorKind::Info, renames.iter_mut().map(ConfigRename::prepare)); + handle_tuliprox_error_result_list!(TuliProxErrorKind::Info, renames.iter_mut().map(ConfigRename::prepare)); } if let Some(sort) = self.sort.as_mut() { - handle_tuliprox_error_result!(M3uFilterErrorKind::Info, sort.prepare()); + handle_tuliprox_error_result!(TuliProxErrorKind::Info, sort.prepare()); } Ok(()) } diff --git a/src/model/config_web_auth.rs b/src/model/config_web_auth.rs index a80ff1d14..c917bd88f 100644 --- a/src/model/config_web_auth.rs +++ b/src/model/config_web_auth.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io::BufRead; use std::path::PathBuf; use crate::auth::user::UserCredential; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind, create_tuliprox_error_result}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind, create_tuliprox_error_result}; use crate::utils::file_utils; use crate::utils::file_utils::file_reader; @@ -21,7 +21,7 @@ pub struct WebAuthConfig { } impl WebAuthConfig { - pub fn prepare(&mut self, config_path: &str) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, config_path: &str) -> Result<(), TuliProxError> { let userfile_name = self.userfile.as_ref().map_or_else(|| file_utils::get_default_user_file_path(config_path), std::borrow::ToOwned::to_owned); self.userfile = Some(userfile_name.clone()); @@ -29,7 +29,7 @@ impl WebAuthConfig { if !file_utils::path_exists(&userfile_path) { userfile_path = PathBuf::from(config_path).join(&userfile_name); if !file_utils::path_exists(&userfile_path) { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Could not find userfile {}", &userfile_name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Could not find userfile {}", &userfile_name); } } @@ -50,7 +50,7 @@ impl WebAuthConfig { self.t_users = Some(users); } else { - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Could not read userfile {:?}", &userfile_path); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "Could not read userfile {:?}", &userfile_path); } Ok(()) } diff --git a/src/model/config_webui.rs b/src/model/config_webui.rs index c397b976e..1ad0210dc 100644 --- a/src/model/config_webui.rs +++ b/src/model/config_webui.rs @@ -1,5 +1,5 @@ use crate::utils::default_as_true; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::WebAuthConfig; const RESERVED_PATHS: &[&str] = &[ @@ -24,7 +24,7 @@ pub struct WebUiConfig { } impl WebUiConfig { - pub fn prepare(&mut self, config_path: &str) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, config_path: &str) -> Result<(), TuliProxError> { if !self.enabled { self.auth = None; } @@ -36,7 +36,7 @@ impl WebUiConfig { } else { let web_path = web_path.trim().trim_start_matches('/').trim_end_matches('/').to_string(); if RESERVED_PATHS.contains(&web_path.to_lowercase().as_str()) { - return Err(M3uFilterError::new(M3uFilterErrorKind::Info, format!("web ui path is a reserved path. Do not use {RESERVED_PATHS:?}"))); + return Err(TuliProxError::new(TuliProxErrorKind::Info, format!("web ui path is a reserved path. Do not use {RESERVED_PATHS:?}"))); } self.path = Some(web_path); } diff --git a/src/model/hdhomerun_config.rs b/src/model/hdhomerun_config.rs index c6da24217..158df31b9 100644 --- a/src/model/hdhomerun_config.rs +++ b/src/model/hdhomerun_config.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use log::warn; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind, create_tuliprox_error_result}; -fn default_friendly_name() -> String { String::from("M3uFilterTV") } +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind, create_tuliprox_error_result}; +fn default_friendly_name() -> String { String::from("TuliProxTV") } fn default_manufacturer() -> String { String::from("Silicondust") } fn default_model_name() -> String { String::from("HDTC-2US") } fn default_firmware_name() -> String { String::from("hdhomeruntc_atsc") } @@ -72,7 +72,7 @@ pub struct HdHomeRunConfig { } impl HdHomeRunConfig { - pub fn prepare(&mut self, api_port: u16) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, api_port: u16) -> Result<(), TuliProxError> { let mut names = HashSet::new(); let mut ports = HashSet::new(); ports.insert(api_port); @@ -80,11 +80,11 @@ impl HdHomeRunConfig { device.prepare(device_num); if names.contains(&device.name) { names.insert(&device.name); - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "HdHomeRun duplicate device name {}", device.name); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "HdHomeRun duplicate device name {}", device.name); } if device.port > 0 && ports.contains(&device.port) { ports.insert(device.port); - return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "HdHomeRun duplicate port {}", device.port); + return create_tuliprox_error_result!(TuliProxErrorKind::Info, "HdHomeRun duplicate port {}", device.port); } } let mut current_port = api_port + 1; diff --git a/src/model/mapping.rs b/src/model/mapping.rs index 96310e3b8..9b13abf51 100644 --- a/src/model/mapping.rs +++ b/src/model/mapping.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use crate::foundation::filter::{apply_templates_to_pattern, get_filter, prepare_templates, Filter, PatternTemplate, RegexWithCaptures, ValueProcessor}; use crate::tuliprox_error::{create_tuliprox_error_result, handle_tuliprox_error_result, info_err}; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::valid_property; use crate::model::{ItemField}; use crate::model::{FieldGetAccessor, FieldSetAccessor, PlaylistItem}; @@ -74,9 +74,9 @@ impl Display for CounterModifier { } impl FromStr for CounterModifier { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { if s.eq("assign") { Ok(Self::Assign) } else if s.eq("suffix") { @@ -84,7 +84,7 @@ impl FromStr for CounterModifier { } else if s.eq("prefix") { Ok(Self::Prefix) } else { - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown CounterModifier: {}", s) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown CounterModifier: {}", s) } } } @@ -146,9 +146,9 @@ impl Display for TransformModifier { } impl FromStr for TransformModifier { - type Err = M3uFilterError; + type Err = TuliProxError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { if s.eq("lowercase") { Ok(Self::Lowercase) } else if s.eq("uppercase") { @@ -156,7 +156,7 @@ impl FromStr for TransformModifier { } else if s.eq("capitalize") { Ok(Self::Capitalize) } else { - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "Unknown TransformModifier: {}", s) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "Unknown TransformModifier: {}", s) } } } @@ -171,7 +171,7 @@ pub struct MapperTransform { } impl MapperTransform { - pub fn prepare(&mut self, templates: Option<&Vec>) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, templates: Option<&Vec>) -> Result<(), TuliProxError> { match &self.pattern { None => self.t_pattern = None, Some(pattern) => { @@ -184,7 +184,7 @@ impl MapperTransform { } match Regex::new(&new_pattern) { Ok(pattern) => self.t_pattern = Some(pattern), - Err(err) => return create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant parse regex: {new_pattern} {err}"), + Err(err) => return create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant parse regex: {new_pattern} {err}"), } } } @@ -218,7 +218,7 @@ impl Mapper { /// # Panics /// /// Will panic if default `RegEx` gets invalid - pub fn prepare(&mut self, templates: Option<&Vec>, tags: Option<&Vec>) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self, templates: Option<&Vec>, tags: Option<&Vec>) -> Result<(), TuliProxError> { for key in self.attributes.keys() { if !valid_property!(key.as_str(), MAPPER_ATTRIBUTE_FIELDS) { return Err(info_err!(format!("Invalid mapper attribute field {key}"))); @@ -453,9 +453,9 @@ pub struct Mapping { impl Mapping { pub fn prepare(&mut self, templates: Option<&Vec>, - tags: Option<&Vec>) -> Result<(), M3uFilterError> { + tags: Option<&Vec>) -> Result<(), TuliProxError> { for mapper in &mut self.mapper { - handle_tuliprox_error_result!(M3uFilterErrorKind::Info, mapper.prepare(templates, tags)); + handle_tuliprox_error_result!(TuliProxErrorKind::Info, mapper.prepare(templates, tags)); } if let Some(counter_def_list) = &self.counter { @@ -493,7 +493,7 @@ pub struct MappingDefinition { } impl MappingDefinition { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { if let Some(templates) = &mut self.templates { match prepare_templates(templates) { Ok(tmplts) => { @@ -505,7 +505,7 @@ impl MappingDefinition { for mapping in &mut self.mapping { let template_list = self.templates.as_ref(); let tag_list = self.tags.as_ref(); - handle_tuliprox_error_result!(M3uFilterErrorKind::Info, mapping.prepare(template_list, tag_list)); + handle_tuliprox_error_result!(TuliProxErrorKind::Info, mapping.prepare(template_list, tag_list)); } Ok(()) } @@ -517,7 +517,7 @@ pub struct Mappings { } impl Mappings { - pub fn prepare(&mut self) -> Result<(), M3uFilterError> { + pub fn prepare(&mut self) -> Result<(), TuliProxError> { self.mappings.prepare() } diff --git a/src/processing/parser/xmltv.rs b/src/processing/parser/xmltv.rs index 0f07b77a4..64a4c3885 100644 --- a/src/processing/parser/xmltv.rs +++ b/src/processing/parser/xmltv.rs @@ -450,7 +450,7 @@ mod tests { /// ``` /// parse_normalize().unwrap(); /// ``` - fn parse_normalize() -> Result<(), M3uFilterError> { + fn parse_normalize() -> Result<(), TuliProxError> { let epg_normalize = EpgSmartMatchConfig::new()?; let normalized = normalize_channel_name("Love Nature", &epg_normalize); assert_eq!(normalized, "lovenature".to_string()); @@ -500,7 +500,7 @@ mod tests { assert_eq!("odisea.bg", normalize_channel_name("BG | ODISEA ᵁᴴᴰ ³⁸⁴⁰ᴾ", &epg_smart_cfg)); } - use crate::tuliprox_error::M3uFilterError; + use crate::tuliprox_error::TuliProxError; use rphonetic::{Encoder, Metaphone}; #[test] diff --git a/src/processing/parser/xtream.rs b/src/processing/parser/xtream.rs index 4a22a0029..cb7a3b83c 100644 --- a/src/processing/parser/xtream.rs +++ b/src/processing/parser/xtream.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{create_tuliprox_error_result, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error_result, TuliProxError, TuliProxErrorKind}; use crate::model::ConfigInput; use crate::model::{PlaylistGroup, PlaylistItem, PlaylistItemHeader, PlaylistItemType, XtreamCluster}; use crate::model::{XtreamCategory, XtreamSeriesInfo, XtreamSeriesInfoEpisode, XtreamStream}; @@ -8,20 +8,20 @@ use serde_json::Value; use std::collections::HashMap; use std::sync::Arc; -fn map_to_xtream_category(categories: &Value) -> Result, M3uFilterError> { +fn map_to_xtream_category(categories: &Value) -> Result, TuliProxError> { match serde_json::from_value::>(categories.to_owned()) { Ok(xtream_categories) => Ok(xtream_categories), Err(err) => { - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to process categories {}", &err) + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to process categories {}", &err) } } } -fn map_to_xtream_streams(xtream_cluster: XtreamCluster, streams: &Value) -> Result, M3uFilterError> { +fn map_to_xtream_streams(xtream_cluster: XtreamCluster, streams: &Value) -> Result, TuliProxError> { match serde_json::from_value::>(streams.to_owned()) { Ok(stream_list) => Ok(stream_list), Err(err) => { - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to map to xtream streams {:?}: {}", xtream_cluster, &err) + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to map to xtream streams {:?}: {}", xtream_cluster, &err) } } } @@ -36,7 +36,7 @@ fn create_xtream_series_episode_url(url: &str, username: &str, password: &str, e } } -pub fn parse_xtream_series_info(info: &Value, group_title: &str, series_name: &str, input: &ConfigInput) -> Result>, M3uFilterError> { +pub fn parse_xtream_series_info(info: &Value, group_title: &str, series_name: &str, input: &ConfigInput) -> Result>, TuliProxError> { 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); @@ -70,7 +70,7 @@ pub fn parse_xtream_series_info(info: &Value, group_title: &str, series_name: &s Ok(None) } Err(err) => { - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to process series info for {series_name} {err}") + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to process series info for {series_name} {err}") } } } @@ -110,7 +110,7 @@ pub fn create_xtream_url(xtream_cluster: XtreamCluster, url: &str, username: &st pub fn parse_xtream(input: &ConfigInput, xtream_cluster: XtreamCluster, categories: &Value, - streams: &Value) -> Result>, M3uFilterError> { + streams: &Value) -> Result>, TuliProxError> { match map_to_xtream_category(categories) { Ok(xtream_categories) => { let input_name = Arc::new(input.name.to_string()); diff --git a/src/processing/processor/playlist.rs b/src/processing/processor/playlist.rs index d9473d099..d94e979b3 100644 --- a/src/processing/processor/playlist.rs +++ b/src/processing/processor/playlist.rs @@ -10,7 +10,7 @@ use std::thread; use tokio::sync::Mutex; use crate::foundation::filter::{get_field_value, set_field_value, MockValueProcessor, ValueProvider}; -use crate::tuliprox_error::{get_errors_notify_message, notify_err, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{get_errors_notify_message, notify_err, TuliProxError, TuliProxErrorKind}; use crate::messaging::{send_message, MsgKind}; use crate::model::{ConfigTarget, InputType, ItemField, ProcessTargets, ProcessingOrder}; use crate::model::{CounterModifier, Mapping, MappingValueProcessor}; @@ -245,7 +245,7 @@ fn is_target_enabled(target: &ConfigTarget, user_targets: &ProcessTargets) -> bo (!user_targets.enabled && target.enabled) || (user_targets.enabled && user_targets.has_target(target.id)) } -async fn process_source(client: Arc, cfg: Arc, source_idx: usize, user_targets: Arc) -> (Vec, Vec, Vec) { +async fn process_source(client: Arc, cfg: Arc, source_idx: usize, user_targets: Arc) -> (Vec, Vec, Vec) { let source = cfg.sources.get(source_idx).unwrap(); let mut errors = vec![]; let mut input_stats = HashMap::::new(); @@ -330,14 +330,14 @@ fn create_input_stat(group_count: usize, channel_count: usize, error_count: usiz } } -async fn process_sources(client: Arc, config: Arc, user_targets: Arc) -> (Vec, Vec) { +async fn process_sources(client: Arc, config: Arc, user_targets: Arc) -> (Vec, Vec) { let mut handle_list = vec![]; let thread_num = config.threads; let process_parallel = thread_num > 1 && config.sources.len() > 1; if process_parallel && log_enabled!(Level::Debug) { debug!("Using {thread_num} threads"); } - let errors = Arc::new(Mutex::>::new(vec![])); + let errors = Arc::new(Mutex::>::new(vec![])); let stats = Arc::new(Mutex::>::new(vec![])); for (index, _) in config.sources.iter().enumerate() { // We're using the file lock this way on purpose @@ -447,7 +447,7 @@ async fn process_playlist_for_target(client: Arc, target: &ConfigTarget, cfg: &Config, stats: &mut HashMap, - errors: &mut Vec) -> Result<(), Vec> { + errors: &mut Vec) -> Result<(), Vec> { let pipe = get_processing_pipe(target); debug_if_enabled!("Processing order is {}", &target.processing_order); diff --git a/src/processing/processor/xtream.rs b/src/processing/processor/xtream.rs index 0513c45b3..a00dcdf71 100644 --- a/src/processing/processor/xtream.rs +++ b/src/processing/processor/xtream.rs @@ -1,5 +1,5 @@ use crate::tuliprox_error::{info_err, notify_err}; -use crate::tuliprox_error::{str_to_io_error, to_io_error, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{str_to_io_error, to_io_error, TuliProxError, TuliProxErrorKind}; use crate::model::{Config, ConfigInput}; use crate::model::{FetchedPlaylist, PlaylistEntry, PlaylistItem, PlaylistItemType, XtreamCluster}; use crate::repository::storage::get_input_storage_path; @@ -15,7 +15,7 @@ use crate::repository::xtream_repository::xtream_get_record_file_path; use crate::utils::file_utils::append_or_crate_file; use crate::utils::xtream; -pub(in crate::processing) async fn playlist_resolve_download_playlist_item(client: Arc, pli: &PlaylistItem, input: &ConfigInput, errors: &mut Vec, resolve_delay: u16, cluster: XtreamCluster) -> Option { +pub(in crate::processing) async fn playlist_resolve_download_playlist_item(client: Arc, pli: &PlaylistItem, input: &ConfigInput, errors: &mut Vec, resolve_delay: u16, cluster: XtreamCluster) -> Option { let mut result = None; let provider_id = pli.get_provider_id()?; if let Some(info_url) = xtream::get_xtream_player_api_info_url(input, cluster, provider_id) { @@ -83,7 +83,7 @@ pub(in crate::processing) fn should_update_info(pli: &mut PlaylistItem, processe || *old_timestamp.unwrap() != last_modified.unwrap(), provider_id, last_modified.unwrap_or(0)) } -pub(in crate::processing) async fn read_processed_info_ids(cfg: &Config, errors: &mut Vec, fpl: &FetchedPlaylist<'_>, +pub(in crate::processing) async fn read_processed_info_ids(cfg: &Config, errors: &mut Vec, fpl: &FetchedPlaylist<'_>, item_type: PlaylistItemType, extract_ts: F) -> HashMap where F: Fn(&V) -> u64, diff --git a/src/processing/processor/xtream_series.rs b/src/processing/processor/xtream_series.rs index da36c9aba..f561dafca 100644 --- a/src/processing/processor/xtream_series.rs +++ b/src/processing/processor/xtream_series.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{Config, ConfigTarget, InputType}; use crate::model::{FetchedPlaylist, PlaylistGroup, PlaylistItem, PlaylistItemType, XtreamCluster}; use crate::processing::processor::playlist::ProcessingPipe; @@ -21,7 +21,7 @@ use crate::utils::file_utils::file_writer; create_resolve_options_function_for_xtream_target!(series); -async fn read_processed_series_info_ids(cfg: &Config, errors: &mut Vec, fpl: &FetchedPlaylist<'_>) -> HashMap { +async fn read_processed_series_info_ids(cfg: &Config, errors: &mut Vec, fpl: &FetchedPlaylist<'_>) -> HashMap { read_processed_info_ids(cfg, errors, fpl, PlaylistItemType::SeriesInfo, |ts: &u64| *ts).await } @@ -54,7 +54,7 @@ fn should_update_series_info(pli: &mut PlaylistItem, processed_provider_ids: &Ha should_update_info(pli, processed_provider_ids, crate::model::XC_TAG_SERIES_INFO_LAST_MODIFIED) } -async fn playlist_resolve_series_info(client: Arc, cfg: &Config, errors: &mut Vec, +async fn playlist_resolve_series_info(client: Arc, cfg: &Config, errors: &mut Vec, fpl: &mut FetchedPlaylist<'_>, resolve_delay: u16) -> bool { let mut processed_info_ids = read_processed_series_info_ids(cfg, errors, fpl).await; // we cant write to the indexed-document directly because of the write lock and time-consuming operation. @@ -132,7 +132,7 @@ async fn playlist_resolve_series_info(client: Arc, cfg: &Config async fn process_series_info( cfg: &Config, fpl: &mut FetchedPlaylist<'_>, - errors: &mut Vec, + errors: &mut Vec, ) -> Vec { let mut result: Vec = vec![]; let input = fpl.input; @@ -214,7 +214,7 @@ async fn process_series_info( pub async fn playlist_resolve_series(client: Arc, cfg: &Config, target: &ConfigTarget, - errors: &mut Vec, + errors: &mut Vec, pipe: &ProcessingPipe, provider_fpl: &mut FetchedPlaylist<'_>, processed_fpl: &mut FetchedPlaylist<'_>, diff --git a/src/processing/processor/xtream_vod.rs b/src/processing/processor/xtream_vod.rs index b904f0dec..8d7d7a2b3 100644 --- a/src/processing/processor/xtream_vod.rs +++ b/src/processing/processor/xtream_vod.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{Config, ConfigTarget, InputType}; use crate::model::{FetchedPlaylist, PlaylistItem, PlaylistItemType, XtreamCluster}; use crate::processing::processor::xtream::{create_resolve_info_wal_files, playlist_resolve_download_playlist_item, read_processed_info_ids, should_update_info, write_info_content_to_wal_file}; @@ -17,7 +17,7 @@ use crate::utils::file_utils::file_writer; create_resolve_options_function_for_xtream_target!(vod); -async fn read_processed_vod_info_ids(cfg: &Config, errors: &mut Vec, fpl: &FetchedPlaylist<'_>) -> HashMap { +async fn read_processed_vod_info_ids(cfg: &Config, errors: &mut Vec, fpl: &FetchedPlaylist<'_>) -> HashMap { read_processed_info_ids(cfg, errors, fpl, PlaylistItemType::Video, |record: &InputVodInfoRecord| record.ts).await } @@ -60,7 +60,7 @@ fn should_update_vod_info(pli: &mut PlaylistItem, processed_provider_ids: &HashM should_update_info(pli, processed_provider_ids, crate::model::XC_TAG_VOD_INFO_ADDED) } -pub async fn playlist_resolve_vod(client: Arc, cfg: &Config, target: &ConfigTarget, errors: &mut Vec, fpl: &mut FetchedPlaylist<'_>) { +pub async fn playlist_resolve_vod(client: Arc, cfg: &Config, target: &ConfigTarget, errors: &mut Vec, fpl: &mut FetchedPlaylist<'_>) { let (resolve_movies, resolve_delay) = get_resolve_vod_options(target, fpl); if !resolve_movies { return; } diff --git a/src/repository/epg_repository.rs b/src/repository/epg_repository.rs index d2234f02d..1724cd945 100644 --- a/src/repository/epg_repository.rs +++ b/src/repository/epg_repository.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{notify_err, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{notify_err, TuliProxError, TuliProxErrorKind}; use crate::model::{Config, ConfigTarget, TargetOutput}; use crate::model::Epg; use crate::repository::m3u_repository::m3u_get_epg_file_path; @@ -9,7 +9,7 @@ use std::fs::File; use std::io::{Cursor, Write}; use std::path::Path; -fn epg_write_file(target: &ConfigTarget, epg: &Epg, path: &Path) -> Result<(), M3uFilterError> { +fn epg_write_file(target: &ConfigTarget, epg: &Epg, path: &Path) -> Result<(), TuliProxError> { let mut writer = Writer::new(Cursor::new(vec![])); match epg.write_to(&mut writer) { Ok(()) => { @@ -35,7 +35,7 @@ fn epg_write_file(target: &ConfigTarget, epg: &Epg, path: &Path) -> Result<(), M Ok(()) } -pub fn epg_write(target: &ConfigTarget, cfg: &Config, target_path: &Path, epg: Option<&Epg>, output: &TargetOutput) -> Result<(), M3uFilterError> { +pub fn epg_write(target: &ConfigTarget, cfg: &Config, target_path: &Path, epg: Option<&Epg>, output: &TargetOutput) -> Result<(), TuliProxError> { if let Some(epg_data) = epg { match output { TargetOutput::Xtream(_) => { diff --git a/src/repository/kodi_repository.rs b/src/repository/kodi_repository.rs index a1977c6f2..42f13a48c 100644 --- a/src/repository/kodi_repository.rs +++ b/src/repository/kodi_repository.rs @@ -1,5 +1,5 @@ use crate::tuliprox_error::{create_tuliprox_error_result, info_err}; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{ApiProxyServerInfo, ProxyUserCredentials}; use crate::model::{ClusterFlags, Config, ConfigTarget, StrmTargetOutput}; use crate::model::{ @@ -404,12 +404,12 @@ fn extract_item_info(pli: &mut PlaylistItem) -> StrmItemInfo { } } -async fn prepare_strm_output_directory(path: &Path) -> Result<(), M3uFilterError> { +async fn prepare_strm_output_directory(path: &Path) -> Result<(), TuliProxError> { // Ensure the directory exists if let Err(e) = tokio::fs::create_dir_all(path).await { error!("Failed to create directory {path:?}: {e}"); return create_tuliprox_error_result!( - M3uFilterErrorKind::Notify, + TuliProxErrorKind::Notify, "Error creating STRM directory: {e}" ); } @@ -575,7 +575,7 @@ pub async fn kodi_write_strm_playlist( target_output: &StrmTargetOutput, cfg: &Config, new_playlist: &mut [PlaylistGroup], -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { if new_playlist.is_empty() { return Ok(()); } diff --git a/src/repository/m3u_playlist_iterator.rs b/src/repository/m3u_playlist_iterator.rs index 858c83108..f279e110e 100644 --- a/src/repository/m3u_playlist_iterator.rs +++ b/src/repository/m3u_playlist_iterator.rs @@ -1,5 +1,5 @@ use crate::tuliprox_error::info_err; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{ProxyType, ProxyUserCredentials}; use crate::model::{Config, ConfigTarget, ConfigTargetOptions, TargetType}; use crate::model::{M3uPlaylistItem, PlaylistItemType, XtreamCluster}; @@ -31,7 +31,7 @@ impl M3uPlaylistIterator { cfg: &Config, target: &ConfigTarget, user: &ProxyUserCredentials, - ) -> Result { + ) -> Result { let m3u_output = target.get_m3u_output().ok_or_else(|| info_err!(format!("Unexpected failure, missing m3u target output for target {}", target.name)))?; let target_path = ensure_target_storage_path(cfg, target.name.as_str())?; let (m3u_path, idx_path) = m3u_get_file_paths(&target_path); @@ -138,7 +138,7 @@ impl M3uPlaylistM3uTextIterator { cfg: &Config, target: &ConfigTarget, user: &ProxyUserCredentials, - ) -> Result { + ) -> Result { Ok(Self { inner: M3uPlaylistIterator::new(cfg, target, user).await?, started: false, diff --git a/src/repository/m3u_repository.rs b/src/repository/m3u_repository.rs index e50f661c2..08a63960c 100644 --- a/src/repository/m3u_repository.rs +++ b/src/repository/m3u_repository.rs @@ -1,5 +1,5 @@ use crate::tuliprox_error::{create_tuliprox_error,info_err}; -use crate::tuliprox_error::{str_to_io_error, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{str_to_io_error, TuliProxError, TuliProxErrorKind}; use crate::model::ProxyUserCredentials; use crate::model::{Config, ConfigTarget, M3uTargetOutput}; use crate::model::{M3uPlaylistItem, PlaylistGroup, PlaylistItem, PlaylistItemType}; @@ -18,7 +18,7 @@ use crate::repository::storage_const; macro_rules! cant_write_result { ($path:expr, $err:expr) => { - create_tuliprox_error!(M3uFilterErrorKind::Notify, "failed to write m3u playlist: {} - {}", $path.to_str().unwrap() ,$err) + create_tuliprox_error!(TuliProxErrorKind::Notify, "failed to write m3u playlist: {} - {}", $path.to_str().unwrap() ,$err) } } @@ -53,7 +53,7 @@ fn persist_m3u_playlist_as_text(cfg: &Config, target: &ConfigTarget, target_outp } } -pub async fn m3u_write_playlist( cfg: &Config, target: &ConfigTarget, target_output: &M3uTargetOutput, target_path: &Path, new_playlist: &[PlaylistGroup]) -> Result<(), M3uFilterError> { +pub async fn m3u_write_playlist( cfg: &Config, target: &ConfigTarget, target_output: &M3uTargetOutput, target_path: &Path, new_playlist: &[PlaylistGroup]) -> Result<(), TuliProxError> { if !new_playlist.is_empty() { let (m3u_path, idx_path) = m3u_get_file_paths(target_path); let m3u_playlist = new_playlist.iter() @@ -85,7 +85,7 @@ pub async fn m3u_load_rewrite_playlist( cfg: &Config, target: &ConfigTarget, user: &ProxyUserCredentials, -) -> Result { +) -> Result { M3uPlaylistM3uTextIterator::new(cfg, target, user).await } diff --git a/src/repository/playlist_repository.rs b/src/repository/playlist_repository.rs index 94c38750f..9b976b007 100644 --- a/src/repository/playlist_repository.rs +++ b/src/repository/playlist_repository.rs @@ -1,5 +1,5 @@ use crate::tuliprox_error::info_err; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{Config, ConfigTarget, TargetOutput}; use crate::model::{PlaylistGroup, PlaylistItemType}; use crate::model::Epg; @@ -14,7 +14,7 @@ use crate::utils::request::{is_dash_url, is_hls_url}; use std::path::Path; pub async fn persist_playlist(playlist: &mut [PlaylistGroup], epg: Option<&Epg>, - target: &ConfigTarget, cfg: &Config) -> Result<(), Vec> { + target: &ConfigTarget, cfg: &Config) -> Result<(), Vec> { let mut errors = vec![]; let target_path = match ensure_target_storage_path(cfg, &target.name) { Ok(path) => path, diff --git a/src/repository/storage.rs b/src/repository/storage.rs index ab6561894..3b0355d3f 100644 --- a/src/repository/storage.rs +++ b/src/repository/storage.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; use std::fmt::Write; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{Config}; use crate::model::UUIDType; use crate::tuliprox_error::{notify_err}; @@ -54,7 +54,7 @@ pub(in crate::repository) fn get_target_id_mapping_file(target_path: &Path) -> P target_path.join(PathBuf::from(storage_const::FILE_ID_MAPPING)) } -pub fn ensure_target_storage_path(cfg: &Config, target_name: &str) -> Result { +pub fn ensure_target_storage_path(cfg: &Config, target_name: &str) -> Result { if let Some(path) = get_target_storage_path(cfg, target_name) { if std::fs::create_dir_all(&path).is_err() { let msg = format!("Failed to save target data, can't create directory {path:?}"); diff --git a/src/repository/xtream_playlist_iterator.rs b/src/repository/xtream_playlist_iterator.rs index a0a8a91d7..0c30db301 100644 --- a/src/repository/xtream_playlist_iterator.rs +++ b/src/repository/xtream_playlist_iterator.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use log::error; use crate::tuliprox_error::info_err; -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::{ProxyUserCredentials}; use crate::model::{Config, ConfigTarget, TargetType}; use crate::model::{XtreamCluster, XtreamPlaylistItem}; @@ -27,7 +27,7 @@ impl XtreamPlaylistIterator { target: &ConfigTarget, category_id: Option, user: &ProxyUserCredentials, - ) -> Result { + ) -> Result { let xtream_output = target.get_xtream_output().ok_or_else(|| info_err!(format!("Unexpected: xtream output required for target {}", target.name)))?; if let Some(storage_path) = xtream_get_storage_path(config, target.name.as_str()) { let (xtream_path, idx_path) = xtream_get_file_paths(&storage_path, cluster); @@ -90,7 +90,7 @@ pub async fn new( target: &ConfigTarget, category_id: Option, user: &ProxyUserCredentials, - ) -> Result { + ) -> Result { Ok(Self { inner: XtreamPlaylistIterator::new(cluster, config, target, category_id, user).await? }) diff --git a/src/repository/xtream_repository.rs b/src/repository/xtream_repository.rs index 8861bcbf7..d418a52a9 100644 --- a/src/repository/xtream_repository.rs +++ b/src/repository/xtream_repository.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{create_tuliprox_error, create_tuliprox_error_result, info_err, notify_err, str_to_io_error, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error, create_tuliprox_error_result, info_err, notify_err, str_to_io_error, TuliProxError, TuliProxErrorKind}; use crate::model::{ProxyUserCredentials}; use crate::model::{Config, ConfigInput, ConfigTarget, XtreamTargetOutput}; use crate::model::{PlaylistEntry, PlaylistGroup, PlaylistItem, PlaylistItemType, XtreamCluster, XtreamPlaylistItem}; @@ -32,7 +32,7 @@ use std::sync::Arc; macro_rules! cant_write_result { ($path:expr, $err:expr) => { create_tuliprox_error!( - M3uFilterErrorKind::Notify, + TuliProxErrorKind::Notify, "failed to write xtream playlist: {} - {}", $path.to_str().unwrap(), $err @@ -60,7 +60,7 @@ fn get_collection_path(path: &Path, collection: &str) -> PathBuf { path.join(format!("{collection}.json")) } -fn ensure_xtream_storage_path(cfg: &Config, target_name: &str) -> Result { +fn ensure_xtream_storage_path(cfg: &Config, target_name: &str) -> Result { if let Some(path) = xtream_get_storage_path(cfg, target_name) { if std::fs::create_dir_all(&path).is_err() { let msg = format!( @@ -104,7 +104,7 @@ fn write_playlists_to_file( cfg: &Config, storage_path: &Path, collections: Vec<(XtreamCluster, &[&mut PlaylistItem])>, -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { for (cluster, playlist) in collections { let (xtream_path, idx_path) = xtream_get_file_paths(storage_path, cluster); { @@ -200,7 +200,7 @@ pub async fn xtream_write_playlist( target: &ConfigTarget, cfg: &Config, playlist: &mut [PlaylistGroup], -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { let path = ensure_xtream_storage_path(cfg, target.name.as_str())?; let mut errors = Vec::new(); let mut cat_live_col = Vec::with_capacity(1_000); @@ -281,7 +281,7 @@ pub async fn xtream_write_playlist( if !errors.is_empty() { return create_tuliprox_error_result!( - M3uFilterErrorKind::Notify, + TuliProxErrorKind::Notify, "{}", errors.join("\n") ); @@ -385,7 +385,7 @@ pub async fn xtream_load_rewrite_playlist( target: &ConfigTarget, category_id: Option, user: &ProxyUserCredentials, -) -> Result { +) -> Result { XtreamPlaylistJsonIterator::new(cluster, config, target, category_id, user).await } @@ -728,7 +728,7 @@ pub async fn xtream_update_input_info_file( input: &ConfigInput, wal_path: &Path, cluster: XtreamCluster, -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { match get_input_storage_path(&input.name, &cfg.working_dir).map(|storage_path| xtream_get_info_file_paths(&storage_path, cluster)) { Ok(Some((info_path, idx_path))) => { { @@ -771,7 +771,7 @@ pub async fn xtream_update_input_vod_record_from_wal_file( cfg: &Config, input: &ConfigInput, wal_path: &Path, -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { let record_path = get_input_storage_path(&input.name, &cfg.working_dir).map(|storage_path| xtream_get_record_file_path(&storage_path, PlaylistItemType::Video)) .map_err(|err| notify_err!(format!("Error accessing storage path: {err}"))) .and_then(|opt| opt.ok_or_else(|| notify_err!(format!("Error accessing storage path for input: {}", &input.name))))?; @@ -811,7 +811,7 @@ pub async fn xtream_update_input_series_record_from_wal_file( cfg: &Config, input: &ConfigInput, wal_path: &Path, -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { let record_path = get_input_storage_path(&input.name, &cfg.working_dir).map(|storage_path| xtream_get_record_file_path(&storage_path, PlaylistItemType::SeriesInfo)) .map_err(|err| notify_err!(format!("Error accessing storage path: {err}"))) .and_then(|opt| opt.ok_or_else(|| notify_err!(format!("Error accessing storage path for input: {}", &input.name))))?; @@ -845,7 +845,7 @@ pub async fn xtream_update_input_series_episodes_record_from_wal_file( cfg: &Config, input: &ConfigInput, wal_path: &Path, -) -> Result<(), M3uFilterError> { +) -> Result<(), TuliProxError> { let record_path = get_input_storage_path(&input.name, &cfg.working_dir).map(|storage_path| xtream_get_record_file_path(&storage_path, PlaylistItemType::Series)) .map_err(|err| notify_err!(format!("Error accessing storage path: {err}"))) .and_then(|opt| opt.ok_or_else(|| notify_err!(format!("Error accessing storage path for input: {}", &input.name))))?; diff --git a/src/utils/crypto_utils.rs b/src/utils/crypto_utils.rs index 6e4b99824..59801ed01 100644 --- a/src/utils/crypto_utils.rs +++ b/src/utils/crypto_utils.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use base64::{engine::general_purpose, Engine as _}; use openssl::symm::{Cipher, Crypter, Mode}; use rand::Rng; @@ -32,13 +32,13 @@ pub fn deobfuscate_text(secret: &[u8], text: &str) -> Result { } } -pub fn encrypt_text(secret: &[u8; 16], text: &str) -> Result { +pub fn encrypt_text(secret: &[u8; 16], text: &str) -> Result { let iv: [u8; 16] = rand::rng().random(); // Random IV (AES-CBC 16 Bytes) let cipher = Cipher::aes_128_cbc(); - let mut crypter = Crypter::new(cipher, Mode::Encrypt, secret, Some(&iv)).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; + let mut crypter = Crypter::new(cipher, Mode::Encrypt, secret, Some(&iv)).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; let mut ciphertext = vec![0; text.len() + cipher.block_size()]; - let mut count = crypter.update(text.as_bytes(), &mut ciphertext).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; - count += crypter.finalize(&mut ciphertext[count..]).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; + let mut count = crypter.update(text.as_bytes(), &mut ciphertext).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; + count += crypter.finalize(&mut ciphertext[count..]).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; ciphertext.truncate(count); // IV + Ciphertext @@ -47,17 +47,17 @@ pub fn encrypt_text(secret: &[u8; 16], text: &str) -> Result Result { - let data = general_purpose::URL_SAFE_NO_PAD.decode(encrypted_text).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; +pub fn decrypt_text(secret: &[u8; 16], encrypted_text: &str) -> Result { + let data = general_purpose::URL_SAFE_NO_PAD.decode(encrypted_text).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; let (iv, ciphertext) = data.split_at(16); // first 16 bytes IV let cipher = Cipher::aes_128_cbc(); - let mut crypter = Crypter::new(cipher, Mode::Decrypt, secret, Some(iv)).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; + let mut crypter = Crypter::new(cipher, Mode::Decrypt, secret, Some(iv)).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; let mut decrypted = vec![0; ciphertext.len() + cipher.block_size()]; - let mut count = crypter.update(ciphertext, &mut decrypted).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; - count += crypter.finalize(&mut decrypted[count..]).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()))?; + let mut count = crypter.update(ciphertext, &mut decrypted).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; + count += crypter.finalize(&mut decrypted[count..]).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string()))?; decrypted.truncate(count); - String::from_utf8(decrypted).map_err(|err| M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string())) + String::from_utf8(decrypted).map_err(|err| TuliProxError::new(TuliProxErrorKind::Info, err.to_string())) } #[cfg(test)] diff --git a/src/utils/file/config_reader.rs b/src/utils/file/config_reader.rs index 7b5383f14..3a4109315 100644 --- a/src/utils/file/config_reader.rs +++ b/src/utils/file/config_reader.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::{create_tuliprox_error, create_tuliprox_error_result, handle_tuliprox_error_result, info_err, str_to_io_error, to_io_error, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{create_tuliprox_error, create_tuliprox_error_result, handle_tuliprox_error_result, info_err, str_to_io_error, to_io_error, TuliProxError, TuliProxErrorKind}; use crate::model::ApiProxyConfig; use crate::model::{Config, ConfigDto, ConfigInput, ConfigInputAlias, InputType}; use crate::model::Mappings; @@ -41,7 +41,7 @@ pub fn config_file_reader(file: File, resolve_env: bool) -> impl Read } } -pub fn read_mappings(args_mapping: Option, cfg: &mut Config, resolve_env: bool) -> Result, M3uFilterError> { +pub fn read_mappings(args_mapping: Option, cfg: &mut Config, resolve_env: bool) -> Result, TuliProxError> { let mappings_file: String = args_mapping.unwrap_or_else(|| file_utils::get_default_mappings_path(cfg.t_config_path.as_str())); match read_mapping(mappings_file.as_str(), resolve_env) { @@ -61,7 +61,7 @@ pub fn read_mappings(args_mapping: Option, cfg: &mut Config, resolve_env } } -pub async fn read_api_proxy_config(args_api_proxy_config: Option, cfg: &mut Config) -> Result, M3uFilterError> { +pub async fn read_api_proxy_config(args_api_proxy_config: Option, cfg: &mut Config) -> Result, TuliProxError> { let api_proxy_config_file: String = args_api_proxy_config.unwrap_or_else(|| file_utils::get_default_api_proxy_config_path(cfg.t_config_path.as_str())); api_proxy_config_file.clone_into(&mut cfg.t_api_proxy_file_path); let api_proxy_config = read_api_proxy(cfg, api_proxy_config_file.as_str(), true); @@ -77,7 +77,7 @@ pub async fn read_api_proxy_config(args_api_proxy_config: Option, cfg: & } } -pub fn read_config(config_path: &str, config_file: &str, sources_file: &str, include_computed: bool) -> Result { +pub fn read_config(config_path: &str, config_file: &str, sources_file: &str, include_computed: bool) -> Result { let files = vec![std::path::PathBuf::from(config_file), std::path::PathBuf::from(sources_file)]; match multi_file_reader::MultiFileReader::new(&files) { Ok(reader) => { @@ -92,21 +92,21 @@ pub fn read_config(config_path: &str, config_file: &str, sources_file: &str, inc } } Err(e) => { - create_tuliprox_error_result!(M3uFilterErrorKind::Info, "cant read config file: {}", e) + create_tuliprox_error_result!(TuliProxErrorKind::Info, "cant read config file: {}", e) } } } - Err(err) => create_tuliprox_error_result!(M3uFilterErrorKind::Info, "{}", err) + Err(err) => create_tuliprox_error_result!(TuliProxErrorKind::Info, "{}", err) } } -pub fn read_mapping(mapping_file: &str, resolve_var: bool) -> Result, M3uFilterError> { +pub fn read_mapping(mapping_file: &str, resolve_var: bool) -> Result, TuliProxError> { let mapping_file = std::path::PathBuf::from(mapping_file); if let Ok(file) = file_utils::open_file(&mapping_file) { let mapping: Result = serde_yaml::from_reader(config_file_reader(file, resolve_var)); return match mapping { Ok(mut result) => { - handle_tuliprox_error_result!(M3uFilterErrorKind::Info, result.prepare()); + handle_tuliprox_error_result!(TuliProxErrorKind::Info, result.prepare()); Ok(Some(result)) } Err(err) => { @@ -140,7 +140,7 @@ pub fn read_api_proxy(config: &Config, api_proxy_file: &str, resolve_env: bool) }) } -fn write_config_file(file_path: &str, backup_dir: &str, config: &T, default_name: &str) -> Result<(), M3uFilterError> +fn write_config_file(file_path: &str, backup_dir: &str, config: &T, default_name: &str) -> Result<(), TuliProxError> where T: ?Sized + Serialize, { @@ -157,14 +157,14 @@ where File::create(&path) .and_then(|f| serde_yaml::to_writer(f, &config).map_err(to_io_error)) - .map_err(|err| create_tuliprox_error!(M3uFilterErrorKind::Info, "Could not write file {}: {}", &path.to_str().unwrap_or("?"), err)) + .map_err(|err| create_tuliprox_error!(TuliProxErrorKind::Info, "Could not write file {}: {}", &path.to_str().unwrap_or("?"), err)) } -pub fn save_api_proxy(file_path: &str, backup_dir: &str, config: &ApiProxyConfig) -> Result<(), M3uFilterError> { +pub fn save_api_proxy(file_path: &str, backup_dir: &str, config: &ApiProxyConfig) -> Result<(), TuliProxError> { write_config_file(file_path, backup_dir, config, "api-proxy.yml") } -pub fn save_main_config(file_path: &str, backup_dir: &str, config: &ConfigDto) -> Result<(), M3uFilterError> { +pub fn save_main_config(file_path: &str, backup_dir: &str, config: &ConfigDto) -> Result<(), TuliProxError> { write_config_file(file_path, backup_dir, config, "config.yml") } diff --git a/src/utils/network/epg.rs b/src/utils/network/epg.rs index b3d53b7e7..7ebe026d5 100644 --- a/src/utils/network/epg.rs +++ b/src/utils/network/epg.rs @@ -1,4 +1,4 @@ -use crate::tuliprox_error::M3uFilterError; +use crate::tuliprox_error::TuliProxError; use crate::model::{Config, ConfigInput}; use crate::model::TVGuide; use crate::repository::storage::short_hash; @@ -10,7 +10,7 @@ use std::path::PathBuf; use std::sync::Arc; -async fn download_epg_file(url: &str, client: &Arc, input: &ConfigInput, working_dir: &str) -> Result { +async fn download_epg_file(url: &str, client: &Arc, input: &ConfigInput, working_dir: &str) -> Result { debug!("Getting epg file path for url: {url}"); let file_prefix = short_hash(url); let persist_file_path = prepare_file_path(input.persist.as_deref(), working_dir, "") @@ -19,7 +19,7 @@ async fn download_epg_file(url: &str, client: &Arc, input: &Con request::get_input_text_content_as_file(Arc::clone(client), input, working_dir, url, persist_file_path).await } -pub async fn get_xmltv(client: Arc, _cfg: &Config, input: &ConfigInput, working_dir: &str) -> (Option, Vec) { +pub async fn get_xmltv(client: Arc, _cfg: &Config, input: &ConfigInput, working_dir: &str) -> (Option, Vec) { match &input.epg { None => (None, vec![]), Some(epg_config) => { diff --git a/src/utils/network/ip_checker.rs b/src/utils/network/ip_checker.rs index 9424f8fee..cbd17e02e 100644 --- a/src/utils/network/ip_checker.rs +++ b/src/utils/network/ip_checker.rs @@ -1,25 +1,25 @@ -use crate::tuliprox_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{TuliProxError, TuliProxErrorKind}; use crate::model::IpCheckConfig; use regex::Regex; use reqwest::Client; use std::sync::Arc; -async fn fetch_ip(client: &Arc, url: &str, regex: Option<&Regex>) -> Result { +async fn fetch_ip(client: &Arc, url: &str, regex: Option<&Regex>) -> Result { let response = client.get(url).send().await - .map_err(|e| M3uFilterError::new(M3uFilterErrorKind::Info, format!("Failed to request {url}: {e}")))?; + .map_err(|e| TuliProxError::new(TuliProxErrorKind::Info, format!("Failed to request {url}: {e}")))?; let text = response.text().await - .map_err(|e| M3uFilterError::new(M3uFilterErrorKind::Info, format!("Failed to read response: {e}")))?; + .map_err(|e| TuliProxError::new(TuliProxErrorKind::Info, format!("Failed to read response: {e}")))?; if let Some(re) = regex { return if let Some(caps) = re.captures(&text) { if let Some(m) = caps.get(1) { Ok(m.as_str().to_string()) } else { - Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Regex matched but no group found".to_string())) + Err(TuliProxError::new(TuliProxErrorKind::Info, "Regex matched but no group found".to_string())) } } else { - Err(M3uFilterError::new(M3uFilterErrorKind::Info, "Regex did not match".to_string())) + Err(TuliProxError::new(TuliProxErrorKind::Info, "Regex did not match".to_string())) }; } @@ -54,7 +54,7 @@ async fn fetch_combined_ips(client: &Arc, config: &IpCheckConfig, url: & } /// Fetch both IPv4 and IPv6 addresses, using separate or combined URL(s) -pub async fn get_ips(client: &Arc, config: &IpCheckConfig) -> Result<(Option, Option), M3uFilterError> { +pub async fn get_ips(client: &Arc, config: &IpCheckConfig) -> Result<(Option, Option), TuliProxError> { match (&config.url_ipv4, &config.url_ipv6, &config.url) { // Both dedicated URLs provided (Some(url_v4), Some(url_v6), _) => { @@ -82,6 +82,6 @@ pub async fn get_ips(client: &Arc, config: &IpCheckConfig) -> Result<(Op } // No URLs given - _ => Err(M3uFilterError::new(M3uFilterErrorKind::Info, "No valid IP-check URLs provided".to_owned())), + _ => Err(TuliProxError::new(TuliProxErrorKind::Info, "No valid IP-check URLs provided".to_owned())), } } \ No newline at end of file diff --git a/src/utils/network/m3u.rs b/src/utils/network/m3u.rs index 1d1592d0f..ad8a7e3ba 100644 --- a/src/utils/network/m3u.rs +++ b/src/utils/network/m3u.rs @@ -1,12 +1,12 @@ use std::sync::Arc; -use crate::tuliprox_error::M3uFilterError; +use crate::tuliprox_error::TuliProxError; use crate::model::{Config, ConfigInput}; use crate::model::PlaylistGroup; use crate::processing::parser::m3u; use crate::utils::file_utils::prepare_file_path; use crate::utils::request; -pub async fn get_m3u_playlist(client: Arc, cfg: &Config, input: &ConfigInput, working_dir: &str) -> (Vec, Vec) { +pub async fn get_m3u_playlist(client: Arc, cfg: &Config, input: &ConfigInput, working_dir: &str) -> (Vec, Vec) { let url = input.url.clone(); let persist_file_path = prepare_file_path(input.persist.as_deref(), working_dir, ""); match request::get_input_text_content(client, input, working_dir, &url, persist_file_path).await { diff --git a/src/utils/network/request.rs b/src/utils/network/request.rs index 3014395ca..42c15d36a 100644 --- a/src/utils/network/request.rs +++ b/src/utils/network/request.rs @@ -15,7 +15,7 @@ use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; use url::Url; use crate::tuliprox_error::create_tuliprox_error_result; -use crate::tuliprox_error::{str_to_io_error, M3uFilterError, M3uFilterErrorKind}; +use crate::tuliprox_error::{str_to_io_error, TuliProxError, TuliProxErrorKind}; use crate::model::format_elapsed_time; use crate::model::{ConfigInput, ProxyConfig, InputFetchMethod}; use crate::repository::storage::{get_input_storage_path, short_hash}; @@ -29,14 +29,14 @@ pub const fn bytes_to_megabytes(bytes: u64) -> u64 { bytes / 1_048_576 } -pub async fn get_input_text_content_as_file(client: Arc, input: &ConfigInput, working_dir: &str, url_str: &str, persist_filepath: Option) -> Result { +pub async fn get_input_text_content_as_file(client: Arc, input: &ConfigInput, working_dir: &str, url_str: &str, persist_filepath: Option) -> Result { debug_if_enabled!("getting input text content working_dir: {}, url: {}", working_dir, sanitize_sensitive_info(url_str)); if url_str.parse::().is_ok() { match download_text_content_as_file(client, input, url_str, working_dir, persist_filepath).await { Ok(content) => Ok(content), Err(e) => { error!("cant download input url: {} => {}", sanitize_sensitive_info(url_str), sanitize_sensitive_info(e.to_string().as_str())); - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to download") + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to download") } } } else { @@ -49,7 +49,7 @@ pub async fn get_input_text_content_as_file(client: Arc, input: Ok(_) => {} Err(e) => { error!("cant persist to: {} => {}", to_file.to_str().unwrap_or("?"), e); - return create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to persist: {} => {}", to_file.to_str().unwrap_or("?"), e); + return create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to persist: {} => {}", to_file.to_str().unwrap_or("?"), e); } } } @@ -57,7 +57,7 @@ pub async fn get_input_text_content_as_file(client: Arc, input: if filepath.exists() { Some(filepath) } else { - return create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed: file does not exists {filepath:?}"); + return create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed: file does not exists {filepath:?}"); } } else { None @@ -69,13 +69,13 @@ pub async fn get_input_text_content_as_file(client: Arc, input: result.map_or_else(|| { let msg = format!("cant read input url: {}", sanitize_sensitive_info(url_str)); error!("{msg}"); - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "{msg}") + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "{msg}") }, Ok) } } -pub async fn get_input_text_content(client: Arc, input: &ConfigInput, working_dir: &str, url_str: &str, persist_filepath: Option) -> Result { +pub async fn get_input_text_content(client: Arc, input: &ConfigInput, working_dir: &str, url_str: &str, persist_filepath: Option) -> Result { debug_if_enabled!("getting input text content working_dir: {}, url: {}", working_dir, sanitize_sensitive_info(url_str)); if url_str.parse::().is_ok() { @@ -83,7 +83,7 @@ pub async fn get_input_text_content(client: Arc, input: &Config Ok((content, _response_url)) => Ok(content), Err(e) => { error!("cant download input url: {} => {}", sanitize_sensitive_info(url_str), sanitize_sensitive_info(e.to_string().as_str())); - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to download") + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to download") } } } else { @@ -96,7 +96,7 @@ pub async fn get_input_text_content(client: Arc, input: &Config Ok(_) => {} Err(e) => { error!("cant persist to: {} => {}", to_file.to_str().unwrap_or("?"), e); - return create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed to persist: {} => {}", to_file.to_str().unwrap_or("?"), e); + return create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed to persist: {} => {}", to_file.to_str().unwrap_or("?"), e); } } } @@ -104,7 +104,7 @@ pub async fn get_input_text_content(client: Arc, input: &Config match get_local_file_content(&filepath) { Ok(content) => Some(content), Err(err) => { - return create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "Failed : {}", err); + return create_tuliprox_error_result!(TuliProxErrorKind::Notify, "Failed : {}", err); } } } else { @@ -116,7 +116,7 @@ pub async fn get_input_text_content(client: Arc, input: &Config result.map_or_else(|| { let msg = format!("cant read input url: {}", sanitize_sensitive_info(url_str)); error!("{msg}"); - create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "{msg}") + create_tuliprox_error_result!(TuliProxErrorKind::Notify, "{msg}") }, Ok) } } @@ -360,10 +360,10 @@ async fn download_json_content(client: Arc, input: &ConfigInput } } -pub async fn get_input_json_content(client: Arc, input: &ConfigInput, url: &str, persist_filepath: Option) -> Result { +pub async fn get_input_json_content(client: Arc, input: &ConfigInput, url: &str, persist_filepath: Option) -> Result { match download_json_content(client, input, url, persist_filepath).await { Ok(content) => Ok(content), - Err(e) => create_tuliprox_error_result!(M3uFilterErrorKind::Notify, "cant download input url: {} => {}", sanitize_sensitive_info(url), sanitize_sensitive_info(e.to_string().as_str())) + Err(e) => create_tuliprox_error_result!(TuliProxErrorKind::Notify, "cant download input url: {} => {}", sanitize_sensitive_info(url), sanitize_sensitive_info(e.to_string().as_str())) } } diff --git a/src/utils/network/xtream.rs b/src/utils/network/xtream.rs index 579eee47a..7c3b51ef5 100644 --- a/src/utils/network/xtream.rs +++ b/src/utils/network/xtream.rs @@ -1,5 +1,5 @@ use std::sync::Arc; -use crate::tuliprox_error::{str_to_io_error, M3uFilterError}; +use crate::tuliprox_error::{str_to_io_error, TuliProxError}; use crate::model::{Config, ConfigInput, ConfigTarget}; use crate::model::{PlaylistEntry, PlaylistGroup, XtreamCluster, XtreamPlaylistItem}; use crate::processing::parser::xtream; @@ -129,7 +129,7 @@ const ACTIONS: [(XtreamCluster, &str, &str); 3] = [ (XtreamCluster::Video, crate::model::XC_ACTION_GET_VOD_CATEGORIES, crate::model::XC_ACTION_GET_VOD_STREAMS), (XtreamCluster::Series, crate::model::XC_ACTION_GET_SERIES_CATEGORIES, crate::model::XC_ACTION_GET_SERIES)]; -pub async fn get_xtream_playlist(client: Arc, input: &ConfigInput, working_dir: &str) -> (Vec, Vec) { +pub async fn get_xtream_playlist(client: Arc, input: &ConfigInput, working_dir: &str) -> (Vec, Vec) { let username = input.username.as_ref().map_or("", |v| v); let password = input.password.as_ref().map_or("", |v| v);