Implement cancellation of downloads by gid
This commit is contained in:
parent
6b60ca4491
commit
a44d0da9f6
|
|
@ -54,6 +54,14 @@ def get_readable_file_size(size_in_bytes) -> str:
|
|||
except IndexError:
|
||||
return 'File too large'
|
||||
|
||||
def getDownloadByGid(gid):
|
||||
with download_dict_lock:
|
||||
for dl in download_dict.values():
|
||||
if dl.status() == MirrorStatus.STATUS_DOWNLOADING:
|
||||
if dl.download().gid == gid:
|
||||
return dl
|
||||
return None
|
||||
|
||||
|
||||
def get_progress_bar_string(status):
|
||||
completed = status.processed_bytes() / 8
|
||||
|
|
@ -95,6 +103,7 @@ def get_readable_message():
|
|||
if hasattr(download, 'is_torrent'):
|
||||
msg += f"| P: {download.download().connections} " \
|
||||
f"| S: {download.download().num_seeders}"
|
||||
msg += f"\nGID: <code>{download.download().gid}</code>"
|
||||
msg += "\n\n"
|
||||
return msg
|
||||
|
||||
|
|
|
|||
|
|
@ -5,18 +5,34 @@ from bot.helper.telegram_helper.filters import CustomFilters
|
|||
from bot.helper.ext_utils.fs_utils import clean_download
|
||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||
from time import sleep
|
||||
from bot.helper.ext_utils.bot_utils import getDownloadByGid
|
||||
|
||||
@run_async
|
||||
def cancel_mirror(bot,update):
|
||||
args = update.message.text.split(" ",maxsplit=1)
|
||||
mirror_message = None
|
||||
if len(args) > 1:
|
||||
gid = args[1]
|
||||
dl = getDownloadByGid(gid)
|
||||
if not dl:
|
||||
sendMessage(f"GID: <code>{gid}</code> not found.",bot,update)
|
||||
return
|
||||
with download_dict_lock:
|
||||
keys = list(download_dict.keys())
|
||||
mirror_message = dl._listener.message
|
||||
elif update.message.reply_to_message:
|
||||
mirror_message = update.message.reply_to_message
|
||||
with download_dict_lock:
|
||||
keys = download_dict.keys()
|
||||
keys = list(download_dict.keys())
|
||||
dl = download_dict[mirror_message.message_id]
|
||||
if len(args) == 1:
|
||||
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'
|
||||
if BotCommands.MirrorCommand in mirror_message.text or BotCommands.TarMirrorCommand in mirror_message.text:
|
||||
msg = "Mirror already have been cancelled"
|
||||
sendMessage(msg,bot,update)
|
||||
return
|
||||
else:
|
||||
msg = 'Please reply to the /mirror message which was used to start the download to cancel it!'
|
||||
msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!"
|
||||
sendMessage(msg,bot,update)
|
||||
return
|
||||
if dl.status() == "Uploading":
|
||||
|
|
@ -31,10 +47,6 @@ def cancel_mirror(bot,update):
|
|||
downloads = aria2.get_downloads(download.followed_by_ids)
|
||||
aria2.pause(downloads)
|
||||
aria2.pause([download])
|
||||
|
||||
elif dl.status() == "Uploading":
|
||||
sendMessage("Upload in Progress, Dont Cancel it.",bot,update)
|
||||
return
|
||||
else:
|
||||
dl._listener.onDownloadError("Download stopped by user!")
|
||||
sleep(1) # Wait a Second For Aria2 To free Resources.
|
||||
|
|
|
|||
Loading…
Reference in New Issue