aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-30 15:13:49 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-30 15:13:49 +0100
commit52955b88a26b0dcd344e7619bdb5bef1082f1806 (patch)
treeb63c09258faba170e93e20c069cdd335f37806b8
parentfix(yt/commands/status): Show active subscriptions number (diff)
downloadyt-52955b88a26b0dcd344e7619bdb5bef1082f1806.zip
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.
-rw-r--r--crates/yt/src/commands/download/implm/download/progress_hook.rs41
1 files 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 <https://www.gnu.org/licenses/gpl-3.0.txt>.
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<Option<HashSet<String>>> = 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