Merge pull request #130 from pybt/features/remote-source
accept remote source start with http or https
This commit is contained in:
commit
dd575cb159
@ -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(),
|
||||
|
@ -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<AtomicBool>, 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() {
|
||||
|
@ -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<Local> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user