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>,
|
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)]
|
||||||
|
|
|
@ -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,24 +49,34 @@ 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;
|
||||||
let progress = rx.recv();
|
|
||||||
|
|
||||||
if let Ok(progress_str) = progress {
|
if !transcode_args.hide_progress {
|
||||||
println!("Transcode Progress: {}", progress_str);
|
child = Some(thread::spawn(move || loop {
|
||||||
} else {
|
let progress = rx.recv();
|
||||||
break;
|
|
||||||
}
|
if let Ok(progress_str) = progress {
|
||||||
});
|
println!("Transcode Progress: {}", progress_str);
|
||||||
|
} else {
|
||||||
|
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),
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
child.join().expect("oops! the child thread panicked");
|
|
||||||
|
if let Some(child) = child {
|
||||||
|
child.join().expect("oops! the child thread panicked");
|
||||||
|
}
|
||||||
|
|
||||||
println!("Transcode Finished");
|
println!("Transcode Finished");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue