add ability to hide progress on transcode command

This commit is contained in:
chaos 2023-10-18 14:53:45 +01:00
parent bb4f776538
commit 3eaa4b0f33
No known key found for this signature in database
2 changed files with 24 additions and 11 deletions

View file

@ -52,6 +52,8 @@ pub struct TranscodeCommandArgs {
pub transcode_config: Option<String>,
#[clap(long)]
pub ignore_extension: bool,
#[clap(long)]
pub hide_progress: bool,
}
#[derive(Debug, Clone, Args)]

View file

@ -2,6 +2,7 @@ use std::path::PathBuf;
use std::process::exit;
use std::sync::mpsc;
use std::thread;
use std::thread::JoinHandle;
use crate::args::CLIArgs;
use crate::args::TranscodeCommandArgs;
@ -48,24 +49,34 @@ pub fn transcode_command(
}
}
let (tx, rx): (mpsc::Sender<String>, mpsc::Receiver<String>) = mpsc::channel();
let child = thread::spawn(move || loop {
let progress = rx.recv();
let (tx, rx) = mpsc::channel::<String>();
let mut child: Option<JoinHandle<()>> = None;
if let Ok(progress_str) = progress {
println!("Transcode Progress: {}", progress_str);
} else {
break;
}
});
if !transcode_args.hide_progress {
child = Some(thread::spawn(move || loop {
let progress = rx.recv();
if let Ok(progress_str) = progress {
println!("Transcode Progress: {}", progress_str);
} else {
break;
}
}));
}
transcode(
input_file,
transcode_args.dest.clone(),
&transcode_config,
Some(tx),
match transcode_args.hide_progress {
true => None,
false => Some(tx),
},
)?;
child.join().expect("oops! the child thread panicked");
if let Some(child) = child {
child.join().expect("oops! the child thread panicked");
}
println!("Transcode Finished");