From 9d976b49ab1b562b19f167c95f959882ec8ea31d Mon Sep 17 00:00:00 2001 From: Daniel M Date: Fri, 1 Apr 2022 01:22:13 +0200 Subject: [PATCH] Actually fix the parallel download --- src/main.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8de4319..fcdf586 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,24 +110,26 @@ async fn download_multiple(args: CLIArgs, raw_urls: Vec) -> Result<()> { async fn download_job(urls: SyncQueue, reporter: UnboundedSender, cli_args: CLIArgs) { // The mutex access must be in its own scope to ensure that the lock is dropped - while let Some(dlreq) = { urls.lock().await.pop_front() } { + while let Some(dlreq) = { + let mut urls = urls.lock().await; + urls.pop_front().take() + } { + println!("Downloading {}", dlreq.url); let reporter = DlReporter::new(dlreq.id as u32, reporter.clone()); // Resolve the zippy url to the direct download url if necessary let url = match is_integrated_url(&dlreq.url) { - Some(service) => { - match resolve_integrated_url(&dlreq.url, service).await { - Ok(url) => url, - Err(_e) => { - report_msg!( - reporter, - "Zippyshare link could not be resolved, skipping: {}", - dlreq.url - ); - continue; - } + Some(service) => match resolve_integrated_url(&dlreq.url, service).await { + Ok(url) => url, + Err(_e) => { + report_msg!( + reporter, + "Zippyshare link could not be resolved, skipping: {}", + dlreq.url + ); + continue; } - } + }, None => dlreq.url, };