diff --git a/src/arg_parse.rs b/src/arg_parse.rs index 7013495e..b3d1dfd5 100644 --- a/src/arg_parse.rs +++ b/src/arg_parse.rs @@ -1,35 +1,36 @@ use clap::Parser; #[derive(Parser, Debug)] -#[clap(version, about = "ffplayout, the rust playout solution", long_about = None)] +#[clap(version, + about = "ffplayout, the rust playout solution", + long_about = None)] pub struct Args { #[clap(short, long, help = "file path to ffplayout.conf")] pub config: Option, + #[clap(long, help = "playing mode: folder, playlist, custom...")] + pub play_mode: Option, + #[clap(short, long, help = "play folder content")] pub folder: Option, - #[clap(short, long, help = "file path for logfile")] - pub log: Option, - - #[clap(short = 'i', long, help = "loop playlist infinitely")] - pub r#loop: bool, - - #[clap(short, long, - help = "set output mode: desktop, hls, stream")] - pub output: Option, - #[clap(short, long, help = "path from playlist")] pub playlist: Option, - #[clap(short, long, help = "start time in 'hh:mm:ss', 'now' for start with first")] + #[clap(short, long, + help = "start time in 'hh:mm:ss', 'now' for start with first")] pub start: Option, - #[clap(short = 't', long, help = "set length in 'hh:mm:ss', 'none' for no length check")] + #[clap(short = 't', + long, help = "set length in 'hh:mm:ss', 'none' for no length check")] pub length: Option, - #[clap(long, help = "playing mode: folder, playlist, custom...")] - pub play_mode: Option, + #[clap(short, long, help = "loop playlist infinitely")] + pub infinit: bool, + + #[clap(short, long, + help = "set output mode: desktop, hls, stream")] + pub output: Option, #[clap(short, long, help = "set audio volume")] pub volume: Option, diff --git a/src/config_reader.rs b/src/config.rs similarity index 65% rename from src/config_reader.rs rename to src/config.rs index a16f9dec..a931f842 100644 --- a/src/config_reader.rs +++ b/src/config.rs @@ -1,8 +1,11 @@ use serde::{Deserialize, Serialize}; use serde_yaml::{self}; +use std::fs::File; use std::path::Path; // use regex::Regex; +use crate::arg_parse; + #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub general: General, @@ -58,6 +61,7 @@ pub struct Processing { pub loud_tp: f32, pub loud_lra: f32, pub output_count: u32, + pub volume: String, } #[derive(Debug, Serialize, Deserialize)] @@ -71,7 +75,7 @@ pub struct Playlist { pub path: String, pub day_start: String, pub length: String, - pub r#loop: bool, + pub infinit: bool, } #[derive(Debug, Serialize, Deserialize)] @@ -100,15 +104,51 @@ pub struct Out { pub stream_param: Vec, } -pub fn read_yaml() -> Config { +pub fn get_config() -> Config { + let args = arg_parse::get_args(); let mut config_path: String = "ffplayout.yml".to_string(); - if Path::new("/etc/ffplayout/ffplayout.yml").exists() { + if args.config.is_some() { + config_path = args.config.unwrap(); + } else if Path::new("/etc/ffplayout/ffplayout.yml").exists() { config_path = "/etc/ffplayout/ffplayout.yml".to_string(); } - let f = std::fs::File::open(config_path).expect("Could not open file."); - let config: Config = serde_yaml::from_reader(f).expect("Could not read config file."); + let f = File::open(config_path).expect("Could not open config file."); + let mut config: Config = serde_yaml::from_reader(f) + .expect("Could not read config file."); + + if args.playlist.is_some() { + config.playlist.path = args.playlist.unwrap(); + } + + if args.play_mode.is_some() { + config.processing.mode = args.play_mode.unwrap(); + } + + if args.folder.is_some() { + config.storage.path = args.folder.unwrap(); + } + + if args.start.is_some() { + config.playlist.day_start = args.start.unwrap(); + } + + if args.length.is_some() { + config.playlist.length = args.length.unwrap(); + } + + if args.infinit { + config.playlist.infinit = args.infinit; + } + + if args.output.is_some() { + config.out.mode = args.output.unwrap(); + } + + if args.volume.is_some() { + config.processing.volume = args.volume.unwrap(); + } config }