about summary refs log tree commit diff stats
path: root/src/download/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/download/mod.rs')
-rw-r--r--src/download/mod.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/download/mod.rs b/src/download/mod.rs
index c3d79b7..707f281 100644
--- a/src/download/mod.rs
+++ b/src/download/mod.rs
@@ -12,7 +12,6 @@ use std::{collections::HashMap, sync::Arc, time::Duration};
 
 use crate::{
     app::App,
-    constants::download_dir,
     download::download_options::download_opts,
     storage::video_database::{
         downloader::{get_next_uncached_video, set_video_cache_path},
@@ -72,8 +71,8 @@ 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().await?
-                + self.get_approx_video_size(&next_video).await?
+            if Self::get_current_cache_allocation(&app).await?
+                + self.get_approx_video_size(&app, &next_video).await?
                 >= max_cache_size
             {
                 warn!(
@@ -134,7 +133,7 @@ impl Downloader {
         Ok(())
     }
 
-    async fn get_current_cache_allocation() -> Result<u64> {
+    async fn get_current_cache_allocation(app: &App) -> Result<u64> {
         fn dir_size(mut dir: fs::ReadDir) -> BoxFuture<'static, Result<u64>> {
             async move {
                 let mut acc = 0;
@@ -155,14 +154,14 @@ impl Downloader {
             .boxed()
         }
 
-        let val = dir_size(fs::read_dir(download_dir(true)?).await?).await;
+        let val = dir_size(fs::read_dir(&app.config.paths.download_dir).await?).await;
         if let Ok(val) = val.as_ref() {
             info!("Cache dir has a size of '{}'", val);
         }
         val
     }
 
-    async fn get_approx_video_size(&mut self, video: &Video) -> Result<u64> {
+    async fn get_approx_video_size(&mut self, app: &App, video: &Video) -> Result<u64> {
         if let Some(value) = self.video_size_cache.get(&video.extractor_hash) {
             Ok(*value)
         } else {
@@ -170,7 +169,7 @@ impl Downloader {
             let add_opts = YtDlpOptions {
                 subtitle_langs: "".to_owned(),
             };
-            let opts = &download_opts(add_opts);
+            let opts = &download_opts(&app, add_opts);
 
             let result = yt_dlp::extract_info(&opts, &video.url, false, true)
                 .await
@@ -201,7 +200,7 @@ impl Downloader {
 
         let addional_opts = get_video_yt_dlp_opts(&app, &video.extractor_hash).await?;
 
-        let result = yt_dlp::download(&[video.url.clone()], &download_opts(addional_opts))
+        let result = yt_dlp::download(&[video.url.clone()], &download_opts(&app, addional_opts))
             .await
             .with_context(|| format!("Failed to download video: '{}'", video.title))?;