about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-04 20:29:29 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-04 20:29:29 +0100
commit887be12527ca8eba92b89226c6251089d30e3be5 (patch)
treef011976fa3832eca078cb9e8f05611b0dd739a53 /crates
parentfix(yt/download): Only print changed bytes sizes, on changed string (diff)
downloadyt-887be12527ca8eba92b89226c6251089d30e3be5.tar.gz
yt-887be12527ca8eba92b89226c6251089d30e3be5.zip
fix(yt_dlp/progress_hook): Mark estimates as such
Currently, the wildly changing estimate numbers are not differentiated
from the valid numbers.
Diffstat (limited to '')
-rw-r--r--crates/yt_dlp/src/lib.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs
index 9fd0200..980d807 100644
--- a/crates/yt_dlp/src/lib.rs
+++ b/crates/yt_dlp/src/lib.rs
@@ -103,7 +103,6 @@ signal.signal(signal.SIGINT, signal.SIG_DFL)",
 pub fn progress_hook(py: Python<'_>, input: &Bound<'_, PyDict>) -> PyResult<()> {
     // Only add the handler, if the log-level is higher than Debug (this avoids covering debug
     // messages).
-    // FIXME: We should actually just find a way to not cover printed messages. <2024-10-19>
     if log_enabled!(Level::Debug) {
         return Ok(());
     }
@@ -229,7 +228,7 @@ pub fn progress_hook(py: Python<'_>, input: &Bound<'_, PyDict>) -> PyResult<()>
             let speed = default_get! {as_f64, 0.0, "speed"};
 
             let downloaded_bytes = get! {is_u64, as_u64, "downloaded_bytes"};
-            let total_bytes = {
+            let (total_bytes, bytes_is_estimate): (u64, &'static str) = {
                 let total_bytes = default_get!(as_u64, 0, "total_bytes");
                 if total_bytes == 0 {
                     let maybe_estimate = default_get!(as_u64, 0, "total_bytes_estimate");
@@ -239,12 +238,12 @@ pub fn progress_hook(py: Python<'_>, input: &Bound<'_, PyDict>) -> PyResult<()>
                         // Thus multiplying them gets us the raw bytes (which were estimated by `yt_dlp`, from their `info.json`)
                         let bytes_still_needed = (speed * eta).ceil() as u64;
 
-                        downloaded_bytes + bytes_still_needed
+                        (downloaded_bytes + bytes_still_needed, "~")
                     } else {
-                        maybe_estimate
+                        (maybe_estimate, "~")
                     }
                 } else {
-                    total_bytes
+                    (total_bytes, "")
                 }
             };
             let percent: f64 = {
@@ -259,19 +258,20 @@ pub fn progress_hook(py: Python<'_>, input: &Bound<'_, PyDict>) -> PyResult<()>
             move_to_col(1);
 
             print!(
-                "'{}' [{}/{} at {}] -> [{}/{} {}] ",
+                "'{}' [{}/{} at {}] -> [{} of {}{} {}] ",
                 c!("34;1", get_title(true)),
                 c!("33;1", Duration::from(Some(elapsed))),
                 c!("33;1", Duration::from(Some(eta))),
                 c!("32;1", format_speed(speed)),
                 c!("31;1", format_bytes(downloaded_bytes)),
+                c!("31;1", bytes_is_estimate),
                 c!("31;1", format_bytes(total_bytes)),
                 c!("36;1", format!("{:.02}%", percent))
             );
             stdout().flush()?;
         }
         "finished" => {
-            println!("-> Finished downloading: '{}'", c!("34;1", get_title(true)));
+            println!("-> Finished downloading.");
         }
         "error" => {
             panic!("-> Error while downloading: {}", get_title(true))