about summary refs log tree commit diff stats
path: root/crates/yt_dlp/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crates/yt_dlp/src/lib.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs
index 4e35cb0..9d1a0c5 100644
--- a/crates/yt_dlp/src/lib.rs
+++ b/crates/yt_dlp/src/lib.rs
@@ -20,7 +20,7 @@ use std::{path::PathBuf, sync::Once};
 use crate::{duration::Duration, logging::setup_logging, wrapper::info_json::InfoJson};
 
 use bytes::Bytes;
-use log::{info, log_enabled, warn, Level};
+use log::{info, log_enabled, Level};
 use pyo3::types::{PyString, PyTuple, PyTupleMethods};
 use pyo3::{
     pyfunction,
@@ -102,6 +102,7 @@ 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(());
     }
@@ -219,21 +220,19 @@ pub fn progress_hook(py: Python<'_>, input: &Bound<'_, PyDict>) -> PyResult<()>
             let total_bytes = {
                 let total_bytes = default_get!(as_u64, 0, "total_bytes");
                 if total_bytes == 0 {
-                    let estimate = default_get!(as_u64, 0, "total_bytes_estimate");
-                    warn!(
-                        "The video does not have a total_byte count, using an estimate of '{}'",
-                        estimate
-                    );
-                    estimate
+                    let maybe_estimate = default_get!(as_u64, 0, "total_bytes_estimate");
+
+                    if maybe_estimate == 0 {
+                        // The download speed should be in bytes per second and the eta in seconds.
+                        // 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
+                    } else {
+                        maybe_estimate
+                    }
                 } else {
                     total_bytes
-                    // FIXME: The solution below _would_ work, if we had a info_json with the
-                    // values. <2024-08-24>
-                    //
-                    // let duration = default_get! {as_f64, 0.0, "duration"}.ceil() as u64;
-                    // // TODO: yt_dlp gets this from the format
-                    // let tbr = default_get! {as_f64, 0.0, "tbr"}.ceil() as u64;
-                    // duration * tbr * (1000 / 8)
                 }
             };
             let percent: f64 = {