integrate option infinit for playlist
This commit is contained in:
parent
a28abb3b4c
commit
c90fc62a38
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1055,7 +1055,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ffplayout-lib"
|
||||
version = "0.10.0"
|
||||
version = "0.10.1"
|
||||
dependencies = [
|
||||
"chrono 0.4.19 (git+https://github.com/chronotope/chrono.git)",
|
||||
"crossbeam-channel 0.5.5",
|
||||
|
@ -348,7 +348,8 @@ impl Iterator for CurrentProgram {
|
||||
let (_, total_delta) =
|
||||
get_delta(&self.config, &self.config.playlist.start_sec.unwrap());
|
||||
|
||||
if last_playlist == self.json_path
|
||||
if !self.config.playlist.infinit
|
||||
&& last_playlist == self.json_path
|
||||
&& total_delta.abs() > self.config.general.stop_threshold
|
||||
{
|
||||
// Test if playlist is to early finish,
|
||||
|
@ -4,7 +4,7 @@ description = "Library for ffplayout"
|
||||
license = "GPL-3.0"
|
||||
authors = ["Jonathan Baecker jonbae77@gmail.com"]
|
||||
readme = "README.md"
|
||||
version = "0.10.0"
|
||||
version = "0.10.1"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
@ -17,6 +17,7 @@ pub const DUMMY_LEN: f64 = 60.0;
|
||||
/// This is our main playlist object, it holds all necessary information for the current day.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct JsonPlaylist {
|
||||
#[serde(default = "default_channel")]
|
||||
pub channel: String,
|
||||
pub date: String,
|
||||
|
||||
@ -57,6 +58,10 @@ impl PartialEq for JsonPlaylist {
|
||||
|
||||
impl Eq for JsonPlaylist {}
|
||||
|
||||
fn default_channel() -> String {
|
||||
"Channel 1".to_string()
|
||||
}
|
||||
|
||||
fn set_defaults(
|
||||
mut playlist: JsonPlaylist,
|
||||
current_file: String,
|
||||
@ -80,6 +85,54 @@ fn set_defaults(
|
||||
playlist
|
||||
}
|
||||
|
||||
fn loop_playlist(
|
||||
config: &PlayoutConfig,
|
||||
current_file: String,
|
||||
mut playlist: JsonPlaylist,
|
||||
) -> JsonPlaylist {
|
||||
let start_sec = config.playlist.start_sec.unwrap();
|
||||
let mut begin = start_sec;
|
||||
let length = config.playlist.length_sec.unwrap();
|
||||
let mut program_list = vec![];
|
||||
let mut index = 0;
|
||||
|
||||
playlist.current_file = Some(current_file);
|
||||
playlist.start_sec = Some(start_sec);
|
||||
|
||||
'program_looper: loop {
|
||||
for item in playlist.program.iter() {
|
||||
let media = Media {
|
||||
index: Some(index),
|
||||
begin: Some(begin),
|
||||
seek: item.seek,
|
||||
out: item.out,
|
||||
duration: item.duration,
|
||||
category: item.category.clone(),
|
||||
source: item.source.clone(),
|
||||
cmd: item.cmd.clone(),
|
||||
probe: item.probe.clone(),
|
||||
process: Some(true),
|
||||
last_ad: Some(false),
|
||||
next_ad: Some(false),
|
||||
filter: Some(vec![]),
|
||||
};
|
||||
|
||||
if begin < start_sec + length {
|
||||
program_list.push(media);
|
||||
} else {
|
||||
break 'program_looper;
|
||||
}
|
||||
|
||||
begin += item.out - item.seek;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
playlist.program = program_list;
|
||||
|
||||
playlist
|
||||
}
|
||||
|
||||
/// Read json playlist file, fills JsonPlaylist struct and set some extra values,
|
||||
/// which we need to process.
|
||||
pub fn read_json(
|
||||
@ -131,7 +184,11 @@ pub fn read_json(
|
||||
validate_playlist(list_clone, is_terminated, config_clone)
|
||||
});
|
||||
|
||||
return set_defaults(playlist, current_file, start_sec);
|
||||
if config.playlist.infinit {
|
||||
return loop_playlist(config, current_file, playlist);
|
||||
} else {
|
||||
return set_defaults(playlist, current_file, start_sec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,7 +206,11 @@ pub fn read_json(
|
||||
|
||||
thread::spawn(move || validate_playlist(list_clone, is_terminated, config_clone));
|
||||
|
||||
return set_defaults(playlist, current_file, start_sec);
|
||||
if config.playlist.infinit {
|
||||
return loop_playlist(config, current_file, playlist);
|
||||
} else {
|
||||
return set_defaults(playlist, current_file, start_sec);
|
||||
}
|
||||
}
|
||||
|
||||
error!("Playlist <b><magenta>{current_file}</></b> not exist!");
|
||||
|
@ -53,7 +53,7 @@ pub fn validate_playlist(
|
||||
begin += item.out - item.seek;
|
||||
}
|
||||
|
||||
if length > begin + 1.0 {
|
||||
if !config.playlist.infinit && length > begin + 1.0 {
|
||||
error!(
|
||||
"Playlist from <yellow>{date}</> not long enough, <yellow>{}</> needed!",
|
||||
sec_to_time(length - begin),
|
||||
|
Loading…
Reference in New Issue
Block a user