get start seconds from config, fix case when playlist not exists at start time
This commit is contained in:
parent
82a9def158
commit
0d6590d719
@ -4,10 +4,7 @@ use std::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
process,
|
process,
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
sync::{
|
sync::{mpsc::channel, Arc, Mutex},
|
||||||
mpsc::channel,
|
|
||||||
Arc, Mutex,
|
|
||||||
},
|
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@ -46,10 +43,7 @@ pub fn play(config: Config) {
|
|||||||
|
|
||||||
debug!("Monitor folder: <b><magenta>{}</></b>", path);
|
debug!("Monitor folder: <b><magenta>{}</></b>", path);
|
||||||
|
|
||||||
runtime.spawn(watch_folder(
|
runtime.spawn(watch_folder(receiver, Arc::clone(&folder_source.nodes)));
|
||||||
receiver,
|
|
||||||
Arc::clone(&folder_source.nodes),
|
|
||||||
));
|
|
||||||
|
|
||||||
Box::new(folder_source) as Box<dyn Iterator<Item = Media>>
|
Box::new(folder_source) as Box<dyn Iterator<Item = Media>>
|
||||||
}
|
}
|
||||||
@ -107,11 +101,11 @@ pub fn play(config: Config) {
|
|||||||
for node in get_source {
|
for node in get_source {
|
||||||
let cmd = match node.cmd {
|
let cmd = match node.cmd {
|
||||||
Some(cmd) => cmd,
|
Some(cmd) => cmd,
|
||||||
None => break
|
None => break,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !node.process.unwrap() {
|
if !node.process.unwrap() {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
|
@ -3,7 +3,7 @@ use std::{fs::File, path::Path};
|
|||||||
|
|
||||||
use simplelog::*;
|
use simplelog::*;
|
||||||
|
|
||||||
use crate::utils::{get_date, get_sec, modified_time, seek_and_length, time_to_sec, Config, Media};
|
use crate::utils::{get_date, modified_time, seek_and_length, time_to_sec, Config, Media};
|
||||||
|
|
||||||
pub const DUMMY_LEN: f64 = 20.0;
|
pub const DUMMY_LEN: f64 = 20.0;
|
||||||
|
|
||||||
@ -51,7 +51,8 @@ pub fn read_json(config: &Config, seek: bool, next_start: f64) -> Playlist {
|
|||||||
|
|
||||||
if !playlist_path.is_file() {
|
if !playlist_path.is_file() {
|
||||||
error!("Playlist <b><magenta>{}</></b> not exists!", current_file);
|
error!("Playlist <b><magenta>{}</></b> not exists!", current_file);
|
||||||
return Playlist::new(date, get_sec());
|
// let dummy_playlist = Playlist::new(date, get_sec());
|
||||||
|
return Playlist::new(date, start_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Read Playlist: <b><magenta>{}</></b>", ¤t_file);
|
info!("Read Playlist: <b><magenta>{}</></b>", ¤t_file);
|
||||||
|
@ -11,7 +11,7 @@ use crate::utils::{
|
|||||||
pub struct CurrentProgram {
|
pub struct CurrentProgram {
|
||||||
config: Config,
|
config: Config,
|
||||||
start_sec: f64,
|
start_sec: f64,
|
||||||
json_mod: String,
|
json_mod: Option<String>,
|
||||||
json_path: Option<String>,
|
json_path: Option<String>,
|
||||||
nodes: Vec<Media>,
|
nodes: Vec<Media>,
|
||||||
current_node: Media,
|
current_node: Media,
|
||||||
@ -26,8 +26,8 @@ impl CurrentProgram {
|
|||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
start_sec: json.start_sec.unwrap(),
|
start_sec: json.start_sec.unwrap(),
|
||||||
json_mod: json.modified.unwrap(),
|
json_mod: json.modified,
|
||||||
json_path: Some(json.current_file.unwrap()),
|
json_path: json.current_file,
|
||||||
nodes: json.program,
|
nodes: json.program,
|
||||||
current_node: Media::new(0, "".to_string()),
|
current_node: Media::new(0, "".to_string()),
|
||||||
init: true,
|
init: true,
|
||||||
@ -41,12 +41,16 @@ impl CurrentProgram {
|
|||||||
if Path::new(&path).is_file() {
|
if Path::new(&path).is_file() {
|
||||||
let mod_time = modified_time(path);
|
let mod_time = modified_time(path);
|
||||||
|
|
||||||
if !mod_time.unwrap().to_string().eq(&self.json_mod) {
|
if !mod_time
|
||||||
|
.unwrap()
|
||||||
|
.to_string()
|
||||||
|
.eq(&self.json_mod.clone().unwrap())
|
||||||
|
{
|
||||||
// when playlist has changed, reload it
|
// when playlist has changed, reload it
|
||||||
let json = read_json(&self.config, false, 0.0);
|
let json = read_json(&self.config, false, 0.0);
|
||||||
|
|
||||||
self.json_mod = json.modified.unwrap();
|
self.json_mod = json.modified;
|
||||||
self.nodes = json.program.into();
|
self.nodes = json.program;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error!("Playlist <b><magenta>{}</></b> not exists!", path);
|
error!("Playlist <b><magenta>{}</></b> not exists!", path);
|
||||||
@ -61,7 +65,6 @@ impl CurrentProgram {
|
|||||||
self.init = true;
|
self.init = true;
|
||||||
self.index = 0;
|
self.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
@ -94,8 +97,8 @@ impl CurrentProgram {
|
|||||||
if next_start >= playlist_length {
|
if next_start >= playlist_length {
|
||||||
let json = read_json(&self.config, false, next_start);
|
let json = read_json(&self.config, false, next_start);
|
||||||
|
|
||||||
self.json_mod = json.modified.unwrap();
|
self.json_mod = json.modified;
|
||||||
self.nodes = json.program.into();
|
self.nodes = json.program;
|
||||||
self.index = 0;
|
self.index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +164,7 @@ impl CurrentProgram {
|
|||||||
item.duration,
|
item.duration,
|
||||||
));
|
));
|
||||||
self.current_node = handle_list_init(item.clone(), &self.config);
|
self.current_node = handle_list_init(item.clone(), &self.config);
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
start_sec += item.out - item.seek;
|
start_sec += item.out - item.seek;
|
||||||
}
|
}
|
||||||
@ -183,8 +186,8 @@ impl Iterator for CurrentProgram {
|
|||||||
let json = read_json(&self.config, false, get_sec() + DUMMY_LEN);
|
let json = read_json(&self.config, false, get_sec() + DUMMY_LEN);
|
||||||
|
|
||||||
if json.current_file.is_some() {
|
if json.current_file.is_some() {
|
||||||
self.json_mod = json.modified.unwrap();
|
self.json_mod = json.modified;
|
||||||
self.json_path = Some(json.current_file.unwrap());
|
self.json_path = json.current_file;
|
||||||
self.nodes = json.program;
|
self.nodes = json.program;
|
||||||
self.get_init_clip();
|
self.get_init_clip();
|
||||||
} else {
|
} else {
|
||||||
@ -252,8 +255,8 @@ impl Iterator for CurrentProgram {
|
|||||||
self.json_path = None;
|
self.json_path = None;
|
||||||
self.nodes = json.program;
|
self.nodes = json.program;
|
||||||
} else {
|
} else {
|
||||||
self.json_mod = json.modified.unwrap();
|
self.json_mod = json.modified;
|
||||||
self.json_path = Some(json.current_file.unwrap());
|
self.json_path = json.current_file;
|
||||||
self.nodes = json.program;
|
self.nodes = json.program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user