diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-22 14:19:42 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-22 14:19:42 +0200 |
commit | 72acfb93627918f6fc9c68a5bf5b4ecf34d07a23 (patch) | |
tree | e59a493e573b05a4fc5a09f3c6d2702635410bec /src/download/mod.rs | |
parent | perf(raw_update.py)!: Don't fetch entries that are already in the database (diff) | |
download | yt-72acfb93627918f6fc9c68a5bf5b4ecf34d07a23.tar.gz yt-72acfb93627918f6fc9c68a5bf5b4ecf34d07a23.zip |
test(benches/update): Init
Diffstat (limited to 'src/download/mod.rs')
-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); } |