diff options
Diffstat (limited to '')
-rw-r--r-- | src/download/mod.rs | 24 |
1 files changed, 13 insertions, 11 deletions
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 <https://www.gnu.org/licenses/gpl-3.0.txt>. -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<App>, 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<App>, 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); } |