check for playlist update, add media probe node
This commit is contained in:
parent
0b82779292
commit
0bcbadbdd0
@ -1,9 +1,12 @@
|
||||
use crate::utils::{
|
||||
get_config,
|
||||
json_reader::{read_json, Program},
|
||||
modified_time, MediaProbe,
|
||||
};
|
||||
|
||||
pub struct CurrentProgram {
|
||||
json_mod: String,
|
||||
json_path: String,
|
||||
nodes: Vec<Program>,
|
||||
idx: usize,
|
||||
}
|
||||
@ -12,12 +15,31 @@ impl CurrentProgram {
|
||||
fn new() -> Self {
|
||||
let config = get_config();
|
||||
let json = read_json(&config, true);
|
||||
let program: Vec<Program> = json.program;
|
||||
|
||||
Self {
|
||||
nodes: program,
|
||||
json_mod: json.modified.unwrap(),
|
||||
json_path: json.current_file.unwrap(),
|
||||
nodes: json.program.into(),
|
||||
idx: json.start_index.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_update(&mut self) {
|
||||
let config = get_config();
|
||||
let mod_time = modified_time(self.json_path.clone());
|
||||
|
||||
if !mod_time.unwrap().to_string().eq(&self.json_mod) {
|
||||
// when playlist has changed, reload it
|
||||
let json = read_json(&config, true);
|
||||
|
||||
self.json_mod = json.modified.unwrap();
|
||||
self.nodes = json.program.into();
|
||||
}
|
||||
}
|
||||
|
||||
fn append_probe(&mut self, node: &mut Program) {
|
||||
node.probe = Some(MediaProbe::new(node.source.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for CurrentProgram {
|
||||
@ -25,18 +47,24 @@ impl Iterator for CurrentProgram {
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.idx < self.nodes.len() {
|
||||
let current = self.nodes[self.idx].clone();
|
||||
self.check_update();
|
||||
let mut current = self.nodes[self.idx].clone();
|
||||
self.idx += 1;
|
||||
|
||||
self.append_probe(&mut current);
|
||||
|
||||
Some(current)
|
||||
} else {
|
||||
// play first item from next playlist
|
||||
let config = get_config();
|
||||
let program: Vec<Program> = read_json(&config, false).program;
|
||||
self.nodes = program;
|
||||
let json = read_json(&config, false);
|
||||
self.json_mod = json.modified.unwrap();
|
||||
self.json_path = json.current_file.unwrap();
|
||||
self.nodes = json.program.into();
|
||||
self.idx = 1;
|
||||
|
||||
let current = self.nodes[0].clone();
|
||||
let mut current = self.nodes[0].clone();
|
||||
|
||||
self.append_probe(&mut current);
|
||||
|
||||
Some(current)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user