From 52955b88a26b0dcd344e7619bdb5bef1082f1806 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 30 Nov 2025 15:13:49 +0100 Subject: fix(yt/commands/download/progress_hook): Show title, if already downloaded Otherwise, if an already downloaded video (but not as downloaded registered video) is "downloaded" yt would just show `-> download finish`. This does not inform the user about what was actually downloaded. --- .../download/implm/download/progress_hook.rs | 41 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/crates/yt/src/commands/download/implm/download/progress_hook.rs b/crates/yt/src/commands/download/implm/download/progress_hook.rs index 19fe122..a414d4a 100644 --- a/crates/yt/src/commands/download/implm/download/progress_hook.rs +++ b/crates/yt/src/commands/download/implm/download/progress_hook.rs @@ -9,9 +9,10 @@ // If not, see . use std::{ + collections::HashSet, io::{Write, stderr}, process, - sync::atomic::Ordering, + sync::{Mutex, atomic::Ordering}, }; use colors::{Colorize, IntoCanvas}; @@ -37,6 +38,8 @@ macro_rules! json_get_default { }; } +static TITLES: Mutex>> = Mutex::new(None); + fn format_bytes(bytes: u64) -> String { let bytes = Bytes::new(bytes); bytes.to_string() @@ -129,9 +132,11 @@ pub(crate) fn progress_hook( let should_use_color = SHOULD_DISPLAY_COLOR.load(Ordering::Relaxed); + let title = get_title(); + eprint!( "{} [{}/{} at {}] -> [{} of {}{} {}] ", - get_title().bold().blue().render(should_use_color), + (&title).bold().blue().render(should_use_color), MaybeDuration::from_secs_f64(elapsed) .bold() .yellow() @@ -156,9 +161,39 @@ pub(crate) fn progress_hook( .render(should_use_color), ); stderr().flush()?; + + { + let mut titles = TITLES.lock().expect("The lock should work"); + + match titles.as_mut() { + Some(titles) => { + titles.insert(title); + } + None => *titles = Some(HashSet::from_iter([title])), + } + } } "finished" => { - eprintln!("-> Finished downloading."); + let should_use_color = SHOULD_DISPLAY_COLOR.load(Ordering::Relaxed); + let title = get_title(); + + let has_already_been_printed = { + let titles = TITLES.lock().expect("The lock should work"); + + match titles.as_ref() { + Some(titles) => titles.contains(&title), + None => false, + } + }; + + if has_already_been_printed { + eprintln!("-> Finished downloading."); + } else { + eprintln!( + "Download of {} already finished.", + title.bold().blue().render(should_use_color) + ); + } } "error" => { // TODO: This should probably return an Err. But I'm not so sure where the error would -- cgit 1.4.1