about summary refs log tree commit diff stats
path: root/yt_dlp/src
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-23 13:01:28 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-23 13:01:28 +0200
commit2e168d07314c38adbe25a046a06c8f62e5e33c6e (patch)
treeb80b69cdbc2fea215c66d8d150c30ebb1a96e44b /yt_dlp/src
parentfeat(crates/bytes): Init (diff)
downloadyt-2e168d07314c38adbe25a046a06c8f62e5e33c6e.tar.gz
yt-2e168d07314c38adbe25a046a06c8f62e5e33c6e.zip
fix(yt_dlp/lib): Standardize the formatting of bytes with the new `bytes` crate
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 {