fix: remove unwraps and add some error handling.
This commit is contained in:
parent
92833c21ce
commit
25e63c2aae
1 changed files with 29 additions and 4 deletions
33
src/main.rs
33
src/main.rs
|
@ -27,7 +27,13 @@ fn main() {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
info!("Found {} file(s) to be processed.", input_files.len());
|
info!("Found {} file(s) to be processed.", input_files.len());
|
||||||
|
|
||||||
|
let mut success_count = 0;
|
||||||
|
|
||||||
for file in input_files {
|
for file in input_files {
|
||||||
|
let mut fail = |job: &TranscodeJob, remarks: &str| {
|
||||||
|
error!("Failed to process file {}: {}", job.input, remarks);
|
||||||
|
};
|
||||||
|
|
||||||
let mut output_path = file.clone();
|
let mut output_path = file.clone();
|
||||||
output_path.set_extension(&config.ffmpeg.output.format);
|
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 output_path = PathBuf::from(&config.files.output_path).join(output_path.file_name().unwrap()); // TODO: This is a bit of a mess.
|
||||||
|
@ -43,15 +49,34 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Processing file {}.", job.input);
|
info!("Processing file {}.", job.input);
|
||||||
let mut child = job.run(&config.ffmpeg).unwrap();
|
let mut child = match job.run(&config.ffmpeg) {
|
||||||
|
Ok(child) => child,
|
||||||
|
Err(e) => {
|
||||||
|
fail(&job, &format!("Failed to start ffmpeg process: {}", e));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
if (config.ffmpeg.process.niceness.unwrap_or(0)) > 0 {
|
if (config.ffmpeg.process.niceness.unwrap_or(0)) > 0 {
|
||||||
renice(child.id(), config.ffmpeg.process.niceness.unwrap_or(0))
|
match renice(child.id(), config.ffmpeg.process.niceness.unwrap()) {
|
||||||
.expect("Failed to renice process.");
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Failed to renice ffmpeg process: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = child.wait() {
|
||||||
|
fail(&job, &format!("Failed to wait for ffmpeg process: {}", e));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
child.wait().expect("Failed to wait for process.");
|
|
||||||
|
|
||||||
// TODO: Cleanup
|
// TODO: Cleanup
|
||||||
|
|
||||||
|
info!("Finished processing file {}.", job.input);
|
||||||
|
success_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info!("Finished processing {} file(s).", success_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_logger(config: &configuration::Config) {
|
fn setup_logger(config: &configuration::Config) {
|
||||||
|
|
Loading…
Reference in a new issue