about summary refs log tree commit diff stats
path: root/yt_dlp/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--yt_dlp/src/lib.rs19
1 files changed, 5 insertions, 14 deletions
diff --git a/yt_dlp/src/lib.rs b/yt_dlp/src/lib.rs
index e0cb590..37d0945 100644
--- a/yt_dlp/src/lib.rs
+++ b/yt_dlp/src/lib.rs
@@ -14,6 +14,7 @@ use std::{path::PathBuf, sync::Once};
 
 use crate::{duration::Duration, logging::setup_logging, wrapper::info_json::InfoJson};
 
+use bytes::Bytes;
 use log::{info, warn};
 use pyo3::types::{PyString, PyTuple, PyTupleMethods};
 use pyo3::{
@@ -151,23 +152,13 @@ pub fn progress_hook<'a>(py: Python, input: Bound<'_, PyDict>) -> PyResult<()> {
     }
 
     fn format_bytes(bytes: u64) -> String {
-        if bytes >= 1_000_000 {
-            format!("{} MB", bytes / 1_000_000)
-        } else if bytes >= 1_000 {
-            format!("{} KB", bytes / 1_000)
-        } else {
-            format!("{} B", bytes)
-        }
+        let bytes = Bytes::new(bytes);
+        bytes.to_string()
     }
 
     fn format_speed(speed: f64) -> String {
-        if speed > 1_000_000.0 {
-            format!("{:.02} MB/s", speed / 1_000_000.0)
-        } else if speed > 1_000.0 {
-            format!("{:.02} KB/s", speed / 1_000.0)
-        } else {
-            format!("{:.02} B/s", speed)
-        }
+        let bytes = Bytes::new(speed.floor() as u64);
+        format!("{}/s", bytes)
     }
 
     let get_title = |add_extension: bool| -> String {