set nodes
This commit is contained in:
parent
b6e1f0db8c
commit
e9c14b6561
@ -3,36 +3,41 @@ use std::fs::File;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::utils::Config;
|
use crate::utils::Config;
|
||||||
use crate::utils::{get_date, modified_time};
|
use crate::utils::{get_date, get_sec, modified_time};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Playlist {
|
pub struct Playlist {
|
||||||
pub date: String,
|
pub date: String,
|
||||||
|
pub start_index: Option<usize>,
|
||||||
pub modified: Option<String>,
|
pub modified: Option<String>,
|
||||||
pub program: Vec<Program>,
|
pub program: Vec<Program>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct Program {
|
pub struct Program {
|
||||||
|
pub begin: Option<f64>,
|
||||||
|
pub index: Option<usize>,
|
||||||
#[serde(rename = "in")]
|
#[serde(rename = "in")]
|
||||||
pub seek: f32,
|
pub seek: f64,
|
||||||
pub out: f32,
|
pub out: f64,
|
||||||
pub duration: f32,
|
pub duration: f64,
|
||||||
pub category: String,
|
pub category: String,
|
||||||
pub source: String,
|
pub source: String,
|
||||||
|
pub cmd: Option<Vec<String>>,
|
||||||
|
pub filter: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_json(config: &Config) -> Playlist {
|
pub fn read_json(config: &Config, seek: bool) -> Playlist {
|
||||||
let mut playlist_path = Path::new(&config.playlist.path).to_owned();
|
let mut playlist_path = Path::new(&config.playlist.path).to_owned();
|
||||||
let start = &config.playlist.day_start;
|
let start = &config.playlist.day_start;
|
||||||
|
let t: Vec<&str> = start.split(':').collect();
|
||||||
|
let h: f64 = t[0].parse().unwrap();
|
||||||
|
let m: f64 = t[1].parse().unwrap();
|
||||||
|
let s: f64 = t[2].parse().unwrap();
|
||||||
|
let mut start_sec = h * 3600.0 + m * 60.0 + s;
|
||||||
|
let mut seek_first = seek;
|
||||||
|
|
||||||
if playlist_path.is_dir() {
|
if playlist_path.is_dir() {
|
||||||
let t: Vec<&str> = start.split(':').collect();
|
|
||||||
let h: f64 = t[0].parse().unwrap();
|
|
||||||
let m: f64 = t[1].parse().unwrap();
|
|
||||||
let s: f64 = t[2].parse().unwrap();
|
|
||||||
let start_sec = h * 3600.0 + m * 60.0 + s;
|
|
||||||
|
|
||||||
let date = get_date(true, start_sec, 0.0);
|
let date = get_date(true, start_sec, 0.0);
|
||||||
let d: Vec<&str> = date.split('-').collect();
|
let d: Vec<&str> = date.split('-').collect();
|
||||||
playlist_path = playlist_path
|
playlist_path = playlist_path
|
||||||
@ -56,5 +61,36 @@ pub fn read_json(config: &Config) -> Playlist {
|
|||||||
playlist.modified = Some(modify.unwrap().to_string());
|
playlist.modified = Some(modify.unwrap().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let time_sec = get_sec();
|
||||||
|
|
||||||
|
for (i, item) in playlist.program.iter_mut().enumerate() {
|
||||||
|
item.begin = Some(start_sec);
|
||||||
|
item.index = Some(i);
|
||||||
|
|
||||||
|
if seek_first && item.begin.unwrap() + (item.out - item.seek) > time_sec {
|
||||||
|
seek_first = false;
|
||||||
|
playlist.start_index = Some(i);
|
||||||
|
item.seek = time_sec - item.begin.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.seek > 0.0 {
|
||||||
|
item.cmd = Some(vec![
|
||||||
|
"-ss".to_string(),
|
||||||
|
format!("{}", item.seek).to_string(),
|
||||||
|
"-i".to_string(),
|
||||||
|
item.source.clone(),
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
item.cmd = Some(vec![
|
||||||
|
"-i".to_string(),
|
||||||
|
item.source.clone(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
start_sec += item.out - item.seek;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{:#?}", playlist);
|
||||||
|
|
||||||
playlist
|
playlist
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,11 @@ pub struct CurrentProgram {
|
|||||||
impl CurrentProgram {
|
impl CurrentProgram {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
let program: Vec<Program> = read_json(&config).program;
|
let json = read_json(&config, true);
|
||||||
|
let program: Vec<Program> = json.program;
|
||||||
Self {
|
Self {
|
||||||
nodes: program,
|
nodes: program,
|
||||||
idx: 0,
|
idx: json.start_index.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +32,7 @@ impl Iterator for CurrentProgram {
|
|||||||
} else {
|
} else {
|
||||||
// play first item from next playlist
|
// play first item from next playlist
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
let program: Vec<Program> = read_json(&config).program;
|
let program: Vec<Program> = read_json(&config, false).program;
|
||||||
self.nodes = program;
|
self.nodes = program;
|
||||||
self.idx = 1;
|
self.idx = 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user