about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--yt_dlp/Cargo.lock5
-rw-r--r--yt_dlp/Cargo.toml1
-rw-r--r--yt_dlp/src/lib.rs19
3 files changed, 11 insertions, 14 deletions
diff --git a/yt_dlp/Cargo.lock b/yt_dlp/Cargo.lock
index 4082d62..cb8d7c9 100644
--- a/yt_dlp/Cargo.lock
+++ b/yt_dlp/Cargo.lock
@@ -15,6 +15,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
 
 [[package]]
+name = "bytes"
+version = "1.0.0"
+
+[[package]]
 name = "cfg-if"
 version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -589,6 +593,7 @@ dependencies = [
 name = "yt_dlp"
 version = "0.1.0"
 dependencies = [
+ "bytes",
  "log",
  "pyo3",
  "serde",
diff --git a/yt_dlp/Cargo.toml b/yt_dlp/Cargo.toml
index 590c422..e5f2efc 100644
--- a/yt_dlp/Cargo.toml
+++ b/yt_dlp/Cargo.toml
@@ -22,3 +22,4 @@ pyo3 = { version = "0.21.2", features = ["auto-initialize", "gil-refs"] }
 serde = { version = "1.0.203", features = ["derive"] }
 serde_json = "1.0.117"
 url = { version = "2.5.0", features = ["serde"] }
+bytes = {path = "./crates/bytes"}
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 {