Skip to content

Commit 82215a3

Browse files
authored
fix: not counting up progress if target exists and logging error if overwrite is false (#29)
1 parent 5a099a4 commit 82215a3

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/main.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ fn main() {
168168
.to_str()
169169
.unwrap_or(""),
170170
);
171+
172+
if Path::new(&final_file_name).exists() && !cmd_args.overwrite {
173+
logger.log_error(
174+
format!("File {final_file_name} already exists and --overwrite is set to false. Continuing with next task if there is more to do..."),
175+
thread,
176+
verbose
177+
);
178+
failed_paths.lock().unwrap().push(final_file_name);
179+
break;
180+
}
181+
171182
let final_path_parent = Path::new(&final_file_name).parent().unwrap();
172183

173184
if !final_path_parent.exists() {
@@ -187,20 +198,18 @@ fn main() {
187198
}
188199
}
189200

190-
let overwrite = match cmd_args.overwrite {
191-
true => "-y",
192-
false => "-n",
193-
};
201+
let mut command = Command::new("ffmpeg");
202+
command.arg("-i").arg(path.to_str().unwrap());
203+
command.args(split_options);
204+
command.arg(&final_file_name);
205+
command.stdout(Stdio::null());
206+
command.stderr(Stdio::piped());
207+
208+
if cmd_args.overwrite {
209+
command.arg("-y");
210+
}
194211

195-
if let Ok(output) = Command::new("ffmpeg")
196-
.args(["-i", path.to_str().unwrap()])
197-
.args(split_options)
198-
.arg(&final_file_name)
199-
.arg(overwrite)
200-
.stdout(Stdio::null())
201-
.stderr(Stdio::piped())
202-
.output()
203-
{
212+
if let Ok(output) = command.output() {
204213
if output.status.success() {
205214
logger.log_info(
206215
format!("Success, saving to {final_file_name}"),

src/progress.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ impl Progress {
1010
pub(crate) fn new(length: usize, eta: bool) -> Self {
1111
let multi = MultiProgress::new();
1212
let progress = multi.add(ProgressBar::new(length as u64));
13-
let progress_bar_template = if eta { "{spinner:.green} [{elapsed_precise} - ETA: {eta_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({percent}%)" } else { "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({percent}%)" };
13+
let progress_bar_template = if eta {
14+
"{spinner:.green} [{elapsed_precise} - ETA: {eta_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({percent}%)"
15+
} else {
16+
"{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({percent}%)"
17+
};
1418
progress.set_style(
1519
ProgressStyle::default_bar()
1620
.template(progress_bar_template)

0 commit comments

Comments
 (0)