about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-23 18:28:51 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-24 11:45:15 +0200
commit5ae4ea69a25abda96a4114298216a8602c2d7d5d (patch)
tree1d890138933527b62a7f22ddc75be036a91df011
parentfeat(watch/handlers): Add status messages to the script handlers (diff)
downloadyt-5ae4ea69a25abda96a4114298216a8602c2d7d5d.tar.gz
yt-5ae4ea69a25abda96a4114298216a8602c2d7d5d.zip
feat(downloader): Display the sizes, when waiting for a cache size reduction
-rw-r--r--src/download/mod.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/download/mod.rs b/src/download/mod.rs
index 707f281..4aee136 100644
--- a/src/download/mod.rs
+++ b/src/download/mod.rs
@@ -22,6 +22,7 @@ use crate::{
 };
 
 use anyhow::{bail, Context, Result};
+use bytes::Bytes;
 use futures::{future::BoxFuture, FutureExt};
 use log::{debug, info, warn};
 use tokio::{fs, task::JoinHandle, time};
@@ -71,14 +72,14 @@ impl Downloader {
     /// This will run, until the database doesn't contain any watchable videos
     pub async fn consume(&mut self, app: Arc<App>, max_cache_size: u64) -> Result<()> {
         while let Some(next_video) = get_next_uncached_video(&app).await? {
-            if Self::get_current_cache_allocation(&app).await?
-                + self.get_approx_video_size(&app, &next_video).await?
-                >= max_cache_size
-            {
+            let cache_allocation = Self::get_current_cache_allocation(&app).await?;
+            let video_size = self.get_approx_video_size(&app, &next_video).await?;
+            if cache_allocation + video_size >= max_cache_size {
                 warn!(
-                    "Can't download video: '{}' as it's too large for the cache.",
-                    next_video.title
+                    "Can't download video: '{}' ({}) as it's too large for the cache ({} of {} allocated).",
+                    next_video.title, Bytes::new(video_size), Bytes::new(cache_allocation), Bytes::new(max_cache_size)
                 );
+
                 // Wait and hope, that a large video is deleted from the cache.
                 time::sleep(Duration::from_secs(10)).await;
                 continue;