From 72acfb93627918f6fc9c68a5bf5b4ecf34d07a23 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 22 Aug 2024 14:19:42 +0200 Subject: test(benches/update): Init --- src/download/mod.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/download/mod.rs') diff --git a/src/download/mod.rs b/src/download/mod.rs index 4431d3e..3785876 100644 --- a/src/download/mod.rs +++ b/src/download/mod.rs @@ -8,7 +8,7 @@ // You should have received a copy of the License along with this program. // If not, see . -use std::time::Duration; +use std::{sync::Arc, time::Duration}; use crate::{ app::App, @@ -34,14 +34,11 @@ pub struct CurrentDownload { } impl CurrentDownload { - fn new_from_video(video: Video) -> Self { + fn new_from_video(app: Arc, video: Video) -> Self { let extractor_hash = video.extractor_hash.clone(); let task_handle = tokio::spawn(async move { - // FIXME: Remove this app reconstruction <2024-07-29> - let new_app = App::new().await?; - - Downloader::actually_cache_video(&new_app, &video) + Downloader::actually_cache_video(&app, &video) .await .with_context(|| format!("Failed to cache video: '{}'", video.title))?; Ok(()) @@ -69,7 +66,7 @@ impl Downloader { /// This Downloader will periodically check if the database has changed, and then also /// change which videos it downloads. /// This will run, until the database doesn't contain any watchable videos - pub async fn consume(&mut self, app: &App) -> Result<()> { + pub async fn consume(&mut self, app: Arc, max_cache_size: u64) -> Result<()> { while let Some(next_video) = get_next_uncached_video(app).await? { if let Some(_) = &self.current_download { let current_download = self.current_download.take().expect("Is Some"); @@ -82,19 +79,23 @@ impl Downloader { if next_video.extractor_hash != current_download.extractor_hash { info!( "Noticed, that the next video is not the video being downloaded, replacing it ('{}' vs. '{}')!", - next_video.extractor_hash.into_short_hash(app).await?, current_download.extractor_hash.into_short_hash(app).await? + next_video.extractor_hash.into_short_hash(&app).await?, current_download.extractor_hash.into_short_hash(&app).await? ); // Replace the currently downloading video current_download.task_handle.abort(); - let new_current_download = CurrentDownload::new_from_video(next_video); + let new_current_download = + CurrentDownload::new_from_video(Arc::clone(&app), next_video); self.current_download = Some(new_current_download); } else { debug!( "Currently downloading '{}'", - current_download.extractor_hash.into_short_hash(app).await? + current_download + .extractor_hash + .into_short_hash(&app) + .await? ); // Reset the taken value self.current_download = Some(current_download); @@ -105,7 +106,8 @@ impl Downloader { "No video is being downloaded right now, setting it to '{}'", next_video.title ); - let new_current_download = CurrentDownload::new_from_video(next_video); + let new_current_download = + CurrentDownload::new_from_video(Arc::clone(&app), next_video); self.current_download = Some(new_current_download); } -- cgit 1.4.1