diff --git a/src/input/playlist.rs b/src/input/playlist.rs index d4efd1a3..6606b329 100644 --- a/src/input/playlist.rs +++ b/src/input/playlist.rs @@ -12,7 +12,7 @@ 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, + seek_and_length, validate_source, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, }; /// Struct for current playlist. @@ -430,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 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..ebbaf85b 100644 --- a/src/utils/json_validate.rs +++ b/src/utils/json_validate.rs @@ -1,14 +1,11 @@ -use std::{ - path::Path, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }, +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, }; use simplelog::*; -use crate::utils::{sec_to_time, GlobalConfig, MediaProbe, Playlist}; +use crate::utils::{sec_to_time, validate_source, GlobalConfig, MediaProbe, Playlist}; /// Validate a given playlist, to check if: /// @@ -31,7 +28,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..01552b95 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -489,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 {