Fixed Handling of Cancellation of uploads/archivals

This commit is contained in:
jaskaranSM 2019-12-29 19:13:10 +05:30
parent 7c4779cfc6
commit 38fa1ec2a6
2 changed files with 13 additions and 9 deletions

View File

@ -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()

View File

@ -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.