96 lines
		
	
	
		
			No EOL
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			96 lines
		
	
	
		
			No EOL
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use serde::{Deserialize, Serialize};
 | |
| 
 | |
| pub 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,
 | |
| }
 | |
| 
 | |
| #[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 input_path: String,
 | |
|     pub output_path: String,
 | |
|     pub include: Vec<String>,
 | |
|     pub cleanup: Option<ConfigFilesCleanup>,
 | |
| }
 | |
| 
 | |
| #[derive(Serialize, Deserialize, Debug)]
 | |
| pub struct Config {
 | |
|     pub debug: Option<bool>,
 | |
|     pub files: ConfigFiles,
 | |
|     pub ffmpeg: ffmpeg::ConfigFFmpeg,
 | |
| }
 | |
| 
 | |
| impl Config {
 | |
|     pub fn new() -> Config {
 | |
|         Config {
 | |
|             debug: None,
 | |
|             files: ConfigFiles {
 | |
|                 input_path: String::from("/data/input"),
 | |
|                 output_path: String::from("/data/output"),
 | |
|                 include: Vec::new(),
 | |
|                 cleanup: None,
 | |
|             },
 | |
|             ffmpeg: ffmpeg::ConfigFFmpeg {
 | |
|                 path: String::from("/usr/bin/ffmpeg"),
 | |
|                 extra_args: None,
 | |
|                 overwrite: None,
 | |
|                 process: Some(ffmpeg::ConfigFFmpegProcess {
 | |
|                     threads: Some(0),
 | |
|                     niceness: Some(0),
 | |
|                 }),
 | |
|                 output: ffmpeg::ConfigFFmpegOutput {
 | |
|                     format: String::from("webm"),
 | |
|                     video: ffmpeg::ConfigFFmpegOutputVideo {
 | |
|                         codec: String::from("libsvtav1"),
 | |
|                         bitrate: 0,
 | |
|                         crf: 0,
 | |
|                     },
 | |
|                     audio: ffmpeg::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,
 | |
|         }
 | |
|     }
 | |
| } |