From 6b7e2cd95a113958eb3c70d20c71685a88888912 Mon Sep 17 00:00:00 2001 From: euzu Date: Mon, 6 Oct 2025 21:00:13 +0200 Subject: [PATCH] Handling edge cases for series info parsing --- backend/src/processing/parser/xmltv.rs | 33 +++++++++++++--------- backend/src/processing/parser/xtream.rs | 9 ++++-- backend/src/utils/file/csv_input_reader.rs | 4 +-- shared/src/utils/json_utils.rs | 2 ++ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/backend/src/processing/parser/xmltv.rs b/backend/src/processing/parser/xmltv.rs index 3ca8097a9..dc0a26be7 100644 --- a/backend/src/processing/parser/xmltv.rs +++ b/backend/src/processing/parser/xmltv.rs @@ -554,26 +554,31 @@ mod tests { #[test] fn parse_test() -> io::Result<()> { - //let file_path = PathBuf::from("/tmp/epg.xml.gz"); - let file_path = PathBuf::from("/tmp/invalid_epg.xml"); + let run_test = async move || { + //let file_path = PathBuf::from("/tmp/epg.xml.gz"); + let file_path = PathBuf::from("/tmp/invalid_epg.xml"); - if file_path.exists() { - let tv_guide = TVGuide::new(vec![PersistedEpgSource { file_path, priority: 0, logo_override: false }]); + if file_path.exists() { + let tv_guide = TVGuide::new(vec![PersistedEpgSource { file_path, priority: 0, logo_override: false }]); - let mut id_cache = EpgIdCache::new(None); - id_cache.channel_epg_id.insert(Cow::Owned("342".to_string())); - //id_cache.collect_epg_id(fp); + let mut id_cache = EpgIdCache::new(None); + id_cache.channel_epg_id.insert(Cow::Owned("342".to_string())); + //id_cache.collect_epg_id(fp); - let channel_ids = HashSet::from(["342".to_string()]); - match tv_guide.filter(&mut id_cache) { - None => assert!(false, "No epg filtered"), - Some(epgs) => { - for epg in epgs { - assert_eq!(epg.children.len(), channel_ids.len() * 2, "Epg size does not match") + let channel_ids = HashSet::from(["342".to_string()]); + match tv_guide.filter(&mut id_cache).await { + None => assert!(false, "No epg filtered"), + Some(epgs) => { + for epg in epgs { + assert_eq!(epg.children.len(), channel_ids.len() * 2, "Epg size does not match") + } } } } - } + }; + let _result = tokio::runtime::Runtime::new() + .unwrap() + .block_on(run_test()); Ok(()) } diff --git a/backend/src/processing/parser/xtream.rs b/backend/src/processing/parser/xtream.rs index cc5c27fb4..b2902e87f 100644 --- a/backend/src/processing/parser/xtream.rs +++ b/backend/src/processing/parser/xtream.rs @@ -208,8 +208,13 @@ mod tests { #[test] fn test_read_json_file_into_struct() { - let file_content = fs::read_to_string("series-info.json").expect("Unable to read file"); - let _info: XtreamSeriesInfo = serde_json::from_str(&file_content).expect("JSON was not well-formatted"); + let file_content = fs::read_to_string("/tmp/series-info.json").expect("Unable to read file"); + match serde_json::from_str::(&file_content) { + Ok(series_info) => {}, + Err(err) => { + assert!(false, "Failed to parse json file: {err}"); + } + } } diff --git a/backend/src/utils/file/csv_input_reader.rs b/backend/src/utils/file/csv_input_reader.rs index e50b49979..622440654 100644 --- a/backend/src/utils/file/csv_input_reader.rs +++ b/backend/src/utils/file/csv_input_reader.rs @@ -194,8 +194,8 @@ http://hd.providerline.com/get.php?username=user4&password=user4&type=m3u_plus;i const XTREAM_BATCH: &str = r" #name;username;password;url;max_connections -input_1;desanocra;eyCG8SN523KQ;http://provider_1.tv:80;1 -input_2;desanocra;eyCG8SN523KQ;http://provider_2.tv:8080;1 +input_1;de566567;de2345f43g5;http://provider_1.tv:80;1 +input_2;de566567;de2345f43g5;http://provider_2.tv:8080;1 "; #[test] diff --git a/shared/src/utils/json_utils.rs b/shared/src/utils/json_utils.rs index dd641940f..1ca312863 100644 --- a/shared/src/utils/json_utils.rs +++ b/shared/src/utils/json_utils.rs @@ -67,6 +67,7 @@ where let value: Value = serde::Deserialize::deserialize(deserializer)?; match value { + Value::Null => Ok(0u32), Value::Number(num) => { if let Some(v) = num.as_u64() { u32::try_from(v) @@ -114,6 +115,7 @@ where let value: Value = serde::Deserialize::deserialize(deserializer)?; match value { + Value::Null => Ok(0f64), Value::Number(num) => num .as_f64() .ok_or_else(|| serde::de::Error::custom("Invalid number")),