override config by arguments
This commit is contained in:
parent
532a95960b
commit
2434764c9e
@ -1,35 +1,36 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[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 {
|
pub struct Args {
|
||||||
#[clap(short, long, help = "file path to ffplayout.conf")]
|
#[clap(short, long, help = "file path to ffplayout.conf")]
|
||||||
pub config: Option<String>,
|
pub config: Option<String>,
|
||||||
|
|
||||||
|
#[clap(long, help = "playing mode: folder, playlist, custom...")]
|
||||||
|
pub play_mode: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long, help = "play folder content")]
|
#[clap(short, long, help = "play folder content")]
|
||||||
pub folder: Option<String>,
|
pub folder: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long, help = "file path for logfile")]
|
|
||||||
pub log: Option<String>,
|
|
||||||
|
|
||||||
#[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<String>,
|
|
||||||
|
|
||||||
#[clap(short, long, help = "path from playlist")]
|
#[clap(short, long, help = "path from playlist")]
|
||||||
pub playlist: Option<String>,
|
pub playlist: Option<String>,
|
||||||
|
|
||||||
#[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<String>,
|
pub start: Option<String>,
|
||||||
|
|
||||||
#[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<String>,
|
pub length: Option<String>,
|
||||||
|
|
||||||
#[clap(long, help = "playing mode: folder, playlist, custom...")]
|
#[clap(short, long, help = "loop playlist infinitely")]
|
||||||
pub play_mode: Option<String>,
|
pub infinit: bool,
|
||||||
|
|
||||||
|
#[clap(short, long,
|
||||||
|
help = "set output mode: desktop, hls, stream")]
|
||||||
|
pub output: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long, help = "set audio volume")]
|
#[clap(short, long, help = "set audio volume")]
|
||||||
pub volume: Option<String>,
|
pub volume: Option<String>,
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::{self};
|
use serde_yaml::{self};
|
||||||
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
// use regex::Regex;
|
// use regex::Regex;
|
||||||
|
|
||||||
|
use crate::arg_parse;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub general: General,
|
pub general: General,
|
||||||
@ -58,6 +61,7 @@ pub struct Processing {
|
|||||||
pub loud_tp: f32,
|
pub loud_tp: f32,
|
||||||
pub loud_lra: f32,
|
pub loud_lra: f32,
|
||||||
pub output_count: u32,
|
pub output_count: u32,
|
||||||
|
pub volume: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -71,7 +75,7 @@ pub struct Playlist {
|
|||||||
pub path: String,
|
pub path: String,
|
||||||
pub day_start: String,
|
pub day_start: String,
|
||||||
pub length: String,
|
pub length: String,
|
||||||
pub r#loop: bool,
|
pub infinit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -100,15 +104,51 @@ pub struct Out {
|
|||||||
pub stream_param: Vec<String>,
|
pub stream_param: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
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();
|
config_path = "/etc/ffplayout/ffplayout.yml".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
let f = std::fs::File::open(config_path).expect("Could not open file.");
|
let f = File::open(config_path).expect("Could not open config file.");
|
||||||
let config: Config = serde_yaml::from_reader(f).expect("Could not read 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
|
config
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user