69 lines
2.1 KiB
Rust
69 lines
2.1 KiB
Rust
#[macro_use]
|
|
extern crate simple_log;
|
|
|
|
use std::env;
|
|
use std::path::PathBuf;
|
|
use simple_log::LogConfigBuilder;
|
|
use renice::renice;
|
|
use transcode::job::TranscodeJob;
|
|
|
|
mod configuration;
|
|
mod files;
|
|
mod ffmpeg;
|
|
mod renice;
|
|
mod transcode;
|
|
|
|
fn main() {
|
|
let config = configuration::Config::from_file(&env::var("CONFIG").unwrap_or(String::from("./config.toml")));
|
|
setup_logger(&config);
|
|
debug!("Config: {:#?}", &config);
|
|
|
|
let input_files = files::get_files(&config.files.input_path)
|
|
.into_iter()
|
|
.filter(|path| {
|
|
let path = path.to_str().unwrap();
|
|
config.files.include.iter().any(|include| path.contains(include))
|
|
})
|
|
.collect::<Vec<_>>();
|
|
info!("Found {} file(s) to be processed.", input_files.len());
|
|
|
|
for file in input_files {
|
|
let mut output_path = file.clone();
|
|
output_path.set_extension(&config.ffmpeg.output.format);
|
|
let output_path = PathBuf::from(&config.files.output_path).join(output_path.file_name().unwrap()); // TODO: This is a bit of a mess.
|
|
|
|
let job = TranscodeJob::new(
|
|
file.to_str().unwrap(),
|
|
output_path.to_str().unwrap()
|
|
);
|
|
|
|
if job.check_if_exists() {
|
|
info!("Skipping conversion for {} to {} as the output file already exists.", job.input, job.output);
|
|
continue;
|
|
}
|
|
|
|
info!("Processing file {}.", job.input);
|
|
let mut child = job.run(&config.ffmpeg).unwrap();
|
|
if (config.ffmpeg.process.niceness.unwrap_or(0)) > 0 {
|
|
renice(child.id(), config.ffmpeg.process.niceness.unwrap_or(0))
|
|
.expect("Failed to renice process.");
|
|
}
|
|
child.wait().expect("Failed to wait for process.");
|
|
|
|
// TODO: Cleanup
|
|
}
|
|
}
|
|
|
|
fn setup_logger(config: &configuration::Config) {
|
|
let log_config = LogConfigBuilder::builder()
|
|
.path("backups.log")
|
|
.size(10 * 1000)
|
|
.roll_count(10)
|
|
.time_format("%Y-%m-%d %H:%M:%S")
|
|
.level(if config.is_debug() { "debug" } else { "info" })
|
|
.output_file()
|
|
.output_console()
|
|
.build();
|
|
|
|
simple_log::new(log_config).unwrap();
|
|
}
|