From 1b76e8ee28e30ebf3f5dcffca25a7d6b2e60dda6 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sat, 17 Feb 2024 23:27:38 +0000 Subject: [PATCH] Aria2c: Fix shutdown condition edge condition when URLs > 1000 `stopped_downloads` is capped to just 1000 objects even though I asked for 999999 downloads, so if aria2c is downloading more than 1000 URLs the count of stopped downloads will never match the count of download URLs and never stop. --- devine/core/downloaders/aria2c.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/devine/core/downloaders/aria2c.py b/devine/core/downloaders/aria2c.py index b930018..0cea146 100644 --- a/devine/core/downloaders/aria2c.py +++ b/devine/core/downloaders/aria2c.py @@ -201,13 +201,15 @@ def download( caller=partial(rpc_session.post, url=rpc_uri), secret=rpc_secret, method="aria2.getGlobalStat" - ) - number_stopped = int(global_stats["numStoppedTotal"]) - if global_stats: - yield dict( - completed=number_stopped, - downloaded=f"{filesize.decimal(int(global_stats['downloadSpeed']))}/s" - ) + ) or {} + + number_stopped = int(global_stats.get("numStoppedTotal", 0)) + download_speed = int(global_stats.get("downloadSpeed", -1)) + + if number_stopped: + yield dict(completed=number_stopped) + if download_speed != -1: + yield dict(downloaded=f"{filesize.decimal(download_speed)}/s") stopped_downloads: list[dict[str, Any]] = rpc( caller=partial(rpc_session.post, url=rpc_uri), @@ -215,6 +217,7 @@ def download( method="aria2.tellStopped", params=[0, 999999] ) or [] + for dl in stopped_downloads: if dl["status"] == "error": used_uri = next( @@ -233,7 +236,7 @@ def download( console.log(Text.from_ansi("\n[Aria2c]: " + error_pretty)) raise ValueError(error) - if len(stopped_downloads) == len(urls): + if number_stopped == len(urls): rpc( caller=partial(rpc_session.post, url=rpc_uri), secret=rpc_secret,