add ability to hide progress on transcode command
This commit is contained in:
parent
bb4f776538
commit
3eaa4b0f33
|
@ -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)]
|
||||
|
|
|
@ -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,8 +49,11 @@ pub fn transcode_command(
|
|||
}
|
||||
}
|
||||
|
||||
let (tx, rx): (mpsc::Sender<String>, mpsc::Receiver<String>) = mpsc::channel();
|
||||
let child = thread::spawn(move || loop {
|
||||
let (tx, rx) = mpsc::channel::<String>();
|
||||
let mut child: Option<JoinHandle<()>> = None;
|
||||
|
||||
if !transcode_args.hide_progress {
|
||||
child = Some(thread::spawn(move || loop {
|
||||
let progress = rx.recv();
|
||||
|
||||
if let Ok(progress_str) = progress {
|
||||
|
@ -57,15 +61,22 @@ pub fn transcode_command(
|
|||
} else {
|
||||
break;
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
transcode(
|
||||
input_file,
|
||||
transcode_args.dest.clone(),
|
||||
&transcode_config,
|
||||
Some(tx),
|
||||
match transcode_args.hide_progress {
|
||||
true => None,
|
||||
false => Some(tx),
|
||||
},
|
||||
)?;
|
||||
|
||||
if let Some(child) = child {
|
||||
child.join().expect("oops! the child thread panicked");
|
||||
}
|
||||
|
||||
println!("Transcode Finished");
|
||||
|
||||
|
|
Loading…
Reference in a new issue