From 38fa1ec2a69531a1ea54bf4c4087145f234ca897 Mon Sep 17 00:00:00 2001 From: jaskaranSM Date: Sun, 29 Dec 2019 19:13:10 +0530 Subject: [PATCH] Fixed Handling of Cancellation of uploads/archivals --- .../download_utils/aria2_download.py | 3 +-- bot/modules/cancel_mirror.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bot/helper/mirror_utils/download_utils/aria2_download.py b/bot/helper/mirror_utils/download_utils/aria2_download.py index f04d012..58b1bc0 100644 --- a/bot/helper/mirror_utils/download_utils/aria2_download.py +++ b/bot/helper/mirror_utils/download_utils/aria2_download.py @@ -6,7 +6,6 @@ from bot.helper.telegram_helper.message_utils import * import threading from aria2p import API - class AriaDownloadHelper(DownloadHelper): def __init__(self, listener): @@ -25,7 +24,7 @@ class AriaDownloadHelper(DownloadHelper): def __onDownloadComplete(self, api: API, gid): with self._resource_lock: if self.gid == gid: - if api.get_download(gid).followed_by_ids: + if api.get_download(gid).followed_by: self.gid = api.get_download(gid).followed_by_ids[0] download_dict[self._listener.uid] = AriaDownloadStatus(self.gid, self._listener) update_all_messages() diff --git a/bot/modules/cancel_mirror.py b/bot/modules/cancel_mirror.py index 4cece6b..97a6429 100644 --- a/bot/modules/cancel_mirror.py +++ b/bot/modules/cancel_mirror.py @@ -13,7 +13,6 @@ def cancel_mirror(bot, update): with download_dict_lock: keys = download_dict.keys() dl = download_dict[mirror_message.message_id] - download = download_dict[mirror_message.message_id].download() if mirror_message is None or mirror_message.message_id not in keys: if '/mirror' in mirror_message.text or '/tarmirror' in mirror_message.text: msg = 'Message has already been cancelled' @@ -21,14 +20,18 @@ def cancel_mirror(bot, update): msg = 'Please reply to the /mirror message which was used to start the download to cancel it!' sendMessage(msg, bot, update) return - if dl.status() != "Queued": + if dl.status() == "Uploading": + sendMessage("Upload in Progress, Don't Cancel it.", bot, update) + return + elif dl.status() == "Archiving": + sendMessage("Archival in Progress, Don't Cancel it.", bot, update) + return + elif dl.status() != "Queued": if len(download.followed_by_ids) != 0: downloads = aria2.get_downloads(download.followed_by_ids) aria2.pause(downloads) + download = dl.download() aria2.pause([download]) - elif dl.status() == "Uploading": - sendMessage("Upload in Progress, Don't Cancel it.", bot, update) - return else: dl._listener.onDownloadError("Download stopped by user!") sleep(1) # Wait a Second For Aria2 To free Resources. @@ -39,9 +42,11 @@ def cancel_mirror(bot, update): def cancel_all(update, bot): with download_dict_lock: for dlDetails in list(download_dict.values()): - if dlDetails.download().is_waiting: + if not dlDetails.status() == "Uploading" or dlDetails.status() == "Archiving": + aria2.pause([dlDetails.download()]) + continue + if dlDetails.status() == "Queued": dlDetails._listener.onDownloadError("Download Manually Cancelled By user.") - aria2.pause([dlDetails.download()]) delete_all_messages() sendMessage('Cancelled all downloads!', update, bot) sleep(0.5) # Wait a Second For Aria2 To free Resources.