140 lines
3.9 KiB
Rust
140 lines
3.9 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
mod ffmpeg;
|
|
|
|
#[allow(non_camel_case_types)] // this is allowed cuz we want to use snake case in the config file
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub enum ConfigFilesCleanupOriginalBehavior {
|
|
delete,
|
|
archive,
|
|
keep,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFilesCleanupArchive {
|
|
pub path: String,
|
|
pub keep_file_structure: bool,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFilesCleanupDelete {
|
|
pub remove_empty_directories: bool,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFilesCleanup {
|
|
pub enabled: bool,
|
|
pub original_cleanup_behavior: ConfigFilesCleanupOriginalBehavior,
|
|
pub archive: ConfigFilesCleanupArchive,
|
|
pub delete: ConfigFilesCleanupDelete,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFiles {
|
|
pub keep_file_structure: bool,
|
|
pub input_path: String,
|
|
pub output_path: String,
|
|
pub include: Vec<String>,
|
|
pub cleanup: ConfigFilesCleanup,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFFmpegProcess {
|
|
pub threads: Option<u8>,
|
|
pub niceness: Option<u8>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFFmpegOutputVideo {
|
|
pub codec: String,
|
|
pub bitrate: u32,
|
|
pub crf: u8,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFFmpegOutputAudio {
|
|
pub codec: String,
|
|
pub bitrate: u32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFFmpegOutput {
|
|
pub format: String,
|
|
pub video: ConfigFFmpegOutputVideo,
|
|
pub audio: ConfigFFmpegOutputAudio,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct ConfigFFmpeg {
|
|
pub path: String,
|
|
pub process: ConfigFFmpegProcess,
|
|
pub output: ConfigFFmpegOutput,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct Config {
|
|
pub debug: Option<bool>,
|
|
pub files: ConfigFiles,
|
|
pub ffmpeg: ConfigFFmpeg,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn new() -> Config {
|
|
Config {
|
|
debug: None,
|
|
files: ConfigFiles {
|
|
keep_file_structure: false,
|
|
input_path: String::from("/data/input"),
|
|
output_path: String::from("/data/output"),
|
|
include: Vec::new(),
|
|
cleanup: ConfigFilesCleanup {
|
|
enabled: false,
|
|
original_cleanup_behavior: ConfigFilesCleanupOriginalBehavior::delete,
|
|
archive: ConfigFilesCleanupArchive {
|
|
path: String::from("/data/archive"),
|
|
keep_file_structure: false,
|
|
},
|
|
delete: ConfigFilesCleanupDelete {
|
|
remove_empty_directories: false
|
|
},
|
|
},
|
|
},
|
|
ffmpeg: ConfigFFmpeg {
|
|
path: String::from("/usr/bin/ffmpeg"),
|
|
process: ConfigFFmpegProcess {
|
|
threads: Some(0),
|
|
niceness: Some(0),
|
|
},
|
|
output: ConfigFFmpegOutput {
|
|
format: String::from("webm"),
|
|
video: ConfigFFmpegOutputVideo {
|
|
codec: String::from("libsvtav1"),
|
|
bitrate: 0,
|
|
crf: 0,
|
|
},
|
|
audio: ConfigFFmpegOutputAudio {
|
|
codec: String::from("libopus"),
|
|
bitrate: 0,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn from_file(path: &str) -> Config {
|
|
let config_file = std::fs::read_to_string(path).expect("Failed to read config file");
|
|
match toml::from_str(&config_file) {
|
|
Ok(config) => config,
|
|
Err(e) => {
|
|
panic!("Failed to parse config file: {}", e.message());
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn is_debug(&self) -> bool {
|
|
match self.debug {
|
|
Some(debug) => debug,
|
|
None => false,
|
|
}
|
|
}
|
|
} |