about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to '')
-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