From ebcf828536ce6050ce18862ba602e6608b427fb4 Mon Sep 17 00:00:00 2001 From: pybt Date: Mon, 30 May 2022 19:42:32 +0700 Subject: [PATCH 1/3] accept remote source --- src/input/playlist.rs | 7 ++----- src/utils/json_validate.rs | 5 ++--- src/utils/mod.rs | 2 ++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/input/playlist.rs b/src/input/playlist.rs index d4efd1a3..f665bdd5 100644 --- a/src/input/playlist.rs +++ b/src/input/playlist.rs @@ -10,10 +10,7 @@ use std::{ use serde_json::json; use simplelog::*; -use crate::utils::{ - check_sync, gen_dummy, get_delta, get_sec, is_close, json_serializer::read_json, modified_time, - seek_and_length, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, -}; +use crate::utils::{check_sync, gen_dummy, get_delta, get_sec, is_close, json_serializer::read_json, modified_time, seek_and_length, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, validate_source}; /// Struct for current playlist. /// @@ -430,7 +427,7 @@ fn timed_source( /// Generate the source CMD, or when clip not exist, get a dummy. fn gen_source(config: &GlobalConfig, mut node: Media) -> Media { - if Path::new(&node.source).is_file() { + if validate_source(&node.source) { node.add_probe(); node.cmd = Some(seek_and_length( node.source.clone(), diff --git a/src/utils/json_validate.rs b/src/utils/json_validate.rs index f2dddf33..a8deac76 100644 --- a/src/utils/json_validate.rs +++ b/src/utils/json_validate.rs @@ -1,5 +1,4 @@ use std::{ - path::Path, sync::{ atomic::{AtomicBool, Ordering}, Arc, @@ -8,7 +7,7 @@ use std::{ use simplelog::*; -use crate::utils::{sec_to_time, GlobalConfig, MediaProbe, Playlist}; +use crate::utils::{sec_to_time, GlobalConfig, MediaProbe, Playlist, validate_source}; /// Validate a given playlist, to check if: /// @@ -31,7 +30,7 @@ pub fn validate_playlist(playlist: Playlist, is_terminated: Arc, con return; } - if Path::new(&item.source).is_file() { + if validate_source(&item.source) { let probe = MediaProbe::new(item.source.clone()); if probe.format.is_none() { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 6664fae6..0b32173f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -20,6 +20,7 @@ mod generator; pub mod json_serializer; mod json_validate; mod logging; +mod source; pub use arg_parse::get_args; pub use config::GlobalConfig; @@ -28,6 +29,7 @@ pub use generator::generate_playlist; pub use json_serializer::{read_json, Playlist, DUMMY_LEN}; pub use json_validate::validate_playlist; pub use logging::{init_logging, send_mail}; +pub use source::{validate_source}; use crate::filter::filter_chains; From d2a89c66ab9f33357fd62841eaf35bacd14c90d3 Mon Sep 17 00:00:00 2001 From: pybt Date: Mon, 30 May 2022 20:18:04 +0700 Subject: [PATCH 2/3] add source.rs --- src/utils/source.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/utils/source.rs diff --git a/src/utils/source.rs b/src/utils/source.rs new file mode 100644 index 00000000..73e7297a --- /dev/null +++ b/src/utils/source.rs @@ -0,0 +1,9 @@ +use std::path::Path; + +use regex::Regex; + +pub fn validate_source(source: &str) -> bool +{ + let re = Regex::new(r"^https?://.*").unwrap(); + return Path::new(&source).is_file() || re.is_match(&source); +} \ No newline at end of file From 398ec1e4494c0771ae585f830dc7ee3cf4c7e9ae Mon Sep 17 00:00:00 2001 From: pybt Date: Mon, 30 May 2022 23:46:24 +0700 Subject: [PATCH 3/3] check remote source video really exists --- src/input/playlist.rs | 7 +++++-- src/utils/json_validate.rs | 10 ++++------ src/utils/mod.rs | 19 +++++++++++++++++-- src/utils/source.rs | 9 --------- 4 files changed, 26 insertions(+), 19 deletions(-) delete mode 100644 src/utils/source.rs diff --git a/src/input/playlist.rs b/src/input/playlist.rs index f665bdd5..6606b329 100644 --- a/src/input/playlist.rs +++ b/src/input/playlist.rs @@ -10,7 +10,10 @@ use std::{ use serde_json::json; use simplelog::*; -use crate::utils::{check_sync, gen_dummy, get_delta, get_sec, is_close, json_serializer::read_json, modified_time, seek_and_length, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, validate_source}; +use crate::utils::{ + check_sync, gen_dummy, get_delta, get_sec, is_close, json_serializer::read_json, modified_time, + seek_and_length, validate_source, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, +}; /// Struct for current playlist. /// @@ -427,7 +430,7 @@ fn timed_source( /// Generate the source CMD, or when clip not exist, get a dummy. fn gen_source(config: &GlobalConfig, mut node: Media) -> Media { - if validate_source(&node.source) { + if validate_source(&node.source) { node.add_probe(); node.cmd = Some(seek_and_length( node.source.clone(), diff --git a/src/utils/json_validate.rs b/src/utils/json_validate.rs index a8deac76..ebbaf85b 100644 --- a/src/utils/json_validate.rs +++ b/src/utils/json_validate.rs @@ -1,13 +1,11 @@ -use std::{ - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }, +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, }; use simplelog::*; -use crate::utils::{sec_to_time, GlobalConfig, MediaProbe, Playlist, validate_source}; +use crate::utils::{sec_to_time, validate_source, GlobalConfig, MediaProbe, Playlist}; /// Validate a given playlist, to check if: /// diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 0b32173f..01552b95 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -20,7 +20,6 @@ mod generator; pub mod json_serializer; mod json_validate; mod logging; -mod source; pub use arg_parse::get_args; pub use config::GlobalConfig; @@ -29,7 +28,6 @@ pub use generator::generate_playlist; pub use json_serializer::{read_json, Playlist, DUMMY_LEN}; pub use json_validate::validate_playlist; pub use logging::{init_logging, send_mail}; -pub use source::{validate_source}; use crate::filter::filter_chains; @@ -491,6 +489,23 @@ pub fn validate_ffmpeg(config: &GlobalConfig) { } } +pub fn validate_source(source: &String) -> bool { + let re: Regex = Regex::new(r"^https?://.*").unwrap(); + + if re.is_match(source) { + let probe = MediaProbe::new(source.clone()); + match probe.video_streams { + Some(_video_streams) => true, + None => { + error!("Remote file not exist: {source}"); + false + } + } + } else { + return Path::new(&source).is_file(); + } +} + /// Get system time, in non test case. #[cfg(not(test))] pub fn time_now() -> DateTime { diff --git a/src/utils/source.rs b/src/utils/source.rs deleted file mode 100644 index 73e7297a..00000000 --- a/src/utils/source.rs +++ /dev/null @@ -1,9 +0,0 @@ -use std::path::Path; - -use regex::Regex; - -pub fn validate_source(source: &str) -> bool -{ - let re = Regex::new(r"^https?://.*").unwrap(); - return Path::new(&source).is_file() || re.is_match(&source); -} \ No newline at end of file