check remote source video really exists

This commit is contained in:
pybt 2022-05-30 23:46:24 +07:00
parent d2a89c66ab
commit 398ec1e449
4 changed files with 26 additions and 19 deletions

View File

@ -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(),

View File

@ -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:
///

View File

@ -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<Local> {

View File

@ -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);
}