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>, pub transcode_config: Option<String>,
#[clap(long)] #[clap(long)]
pub ignore_extension: bool, pub ignore_extension: bool,
#[clap(long)]
pub hide_progress: bool,
} }
#[derive(Debug, Clone, Args)] #[derive(Debug, Clone, Args)]

View file

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