about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-15 23:18:44 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-15 23:18:44 +0200
commit680f811adc83554cfbaff56d8b50501786a949e2 (patch)
tree1fd01cbd0639420b03d80ba89835151936184254
parentfix(yt_dlp/json_{cast,get}): Improve error reporting (diff)
downloadyt-680f811adc83554cfbaff56d8b50501786a949e2.zip
fix(yt/download/get_file_size): Correct deal with `filesize_approx` = Null
-rw-r--r--crates/yt/src/download/mod.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/yt/src/download/mod.rs b/crates/yt/src/download/mod.rs
index 110bf55..6065cf9 100644
--- a/crates/yt/src/download/mod.rs
+++ b/crates/yt/src/download/mod.rs
@@ -311,8 +311,11 @@ impl Downloader {
 
             let size = if let Some(val) = result.get("filesize") {
                 json_cast!(val, as_u64)
-            } else if let Some(val) = result.get("filesize_approx") {
-                json_cast!(val, as_u64)
+            } else if let Some(serde_json::Value::Number(num)) = result.get("filesize_approx") {
+                // NOTE(@bpeetz): yt_dlp sets this value to `Null`, instead of omitting it when it
+                // can't calculate the approximate filesize.
+                // Thus, we have to check, that it is actually non-null, before we cast it. <2025-06-15>
+                json_cast!(num, as_u64)
             } else if result.get("duration").is_some() && result.get("tbr").is_some() {
                 #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
                 let duration = json_get!(result, "duration", as_f64).ceil() as u64;
@@ -347,7 +350,7 @@ impl Downloader {
         let yt_dlp = download_opts(app, &addional_opts)?;
 
         let result = yt_dlp
-            .download(&[video.url.to_owned()])
+            .download(&[video.url.clone()])
             .with_context(|| format!("Failed to download video: '{}'", video.title))?;
 
         assert_eq!(result.len(), 1);