diff --git a/src/args.rs b/src/args.rs index d07988c..8b331d5 100644 --- a/src/args.rs +++ b/src/args.rs @@ -52,6 +52,8 @@ pub struct TranscodeCommandArgs { pub transcode_config: Option, #[clap(long)] pub ignore_extension: bool, + #[clap(long)] + pub hide_progress: bool, } #[derive(Debug, Clone, Args)] diff --git a/src/commands/transcode.rs b/src/commands/transcode.rs index 0d03bba..aba335b 100644 --- a/src/commands/transcode.rs +++ b/src/commands/transcode.rs @@ -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, mpsc::Receiver) = mpsc::channel(); - let child = thread::spawn(move || loop { - let progress = rx.recv(); + let (tx, rx) = mpsc::channel::(); + let mut child: Option> = 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");