aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--yt/src/download/progress_hook.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/yt/src/download/progress_hook.rs b/yt/src/download/progress_hook.rs
index db58225..b75ec00 100644
--- a/yt/src/download/progress_hook.rs
+++ b/yt/src/download/progress_hook.rs
@@ -12,14 +12,9 @@ use crate::{
select::selection_file::duration::MaybeDuration,
};
-// #[allow(clippy::too_many_lines)]
-// #[allow(clippy::missing_panics_doc)]
-// #[allow(clippy::items_after_statements)]
-// #[allow(
-// clippy::cast_possible_truncation,
-// clippy::cast_sign_loss,
-// clippy::cast_precision_loss
-// )]
+/// # Panics
+/// If expectations fail.
+#[allow(clippy::too_many_lines, clippy::needless_pass_by_value)]
pub fn progress_hook(
input: serde_json::Map<String, serde_json::Value>,
) -> Result<(), std::io::Error> {
@@ -89,11 +84,13 @@ pub fn progress_hook(
};
}
+ #[allow(clippy::items_after_statements)]
fn format_bytes(bytes: u64) -> String {
let bytes = Bytes::new(bytes);
bytes.to_string()
}
+ #[allow(clippy::items_after_statements)]
fn format_speed(speed: f64) -> String {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let bytes = Bytes::new(speed.floor() as u64);
@@ -127,6 +124,7 @@ pub fn progress_hook(
if total_bytes == 0 {
let maybe_estimate = default_get!(as_u64, 0, "total_bytes_estimate");
+ #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
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`)
@@ -140,11 +138,19 @@ pub fn progress_hook(
(total_bytes, "")
}
};
+
let percent: f64 = {
if total_bytes == 0 {
100.0
} else {
- (downloaded_bytes as f64 / total_bytes as f64) * 100.0
+ #[allow(
+ clippy::cast_possible_truncation,
+ clippy::cast_sign_loss,
+ clippy::cast_precision_loss
+ )]
+ {
+ (downloaded_bytes as f64 / total_bytes as f64) * 100.0
+ }
}
};
@@ -174,7 +180,7 @@ pub fn progress_hook(
process::exit(1);
}
other => unreachable!("'{other}' should not be a valid state!"),
- };
+ }
Ok(())
}