def __onDownloadComplete(api, gid): LOGGER.info(f"onDownloadComplete: {gid}") dl = getDownloadByGid(gid) download = api.get_download(gid) if download.followed_by_ids: new_gid = download.followed_by_ids[0] new_download = api.get_download(new_gid) if dl is None: dl = getDownloadByGid(new_gid) with download_dict_lock: download_dict[dl.uid()] = AriaDownloadStatus( new_gid, dl.getListener()) LOGGER.info(f'Changed gid from {gid} to {new_gid}') elif dl: Thread(target=dl.getListener().onDownloadComplete).start()
def __onDownloadPause(self, api, gid): LOGGER.info(f"onDownloadPause: {gid}") dl = getDownloadByGid(gid) try: dl.getListener().onDownloadError('Download stopped by user!') except AttributeError: pass
def __onDownloadStarted(api, gid): try: if any([ STOP_DUPLICATE, TORRENT_DIRECT_LIMIT, ZIP_UNZIP_LIMIT, STORAGE_THRESHOLD ]): sleep(1.5) dl = getDownloadByGid(gid) if dl is None: return download = api.get_download(gid) if STOP_DUPLICATE and not dl.getListener().isLeech: LOGGER.info('Checking File/Folder if already in Drive...') sname = download.name if dl.getListener().isZip: sname = sname + ".zip" elif dl.getListener().extract: try: sname = get_base_name(sname) except: sname = None if sname is not None: smsg, button = GoogleDriveHelper().drive_list(sname, True) if smsg: dl.getListener().onDownloadError( 'File/Folder already available in Drive.\n\n') api.remove([download], force=True, files=True) return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button) if any([ZIP_UNZIP_LIMIT, TORRENT_DIRECT_LIMIT, STORAGE_THRESHOLD]): sleep(1) limit = None size = api.get_download(gid).total_length arch = any([dl.getListener().isZip, dl.getListener().extract]) if STORAGE_THRESHOLD is not None: acpt = check_storage_threshold(size, arch, True) # True if files allocated, if allocation disabled remove True arg if not acpt: msg = f'You must leave {STORAGE_THRESHOLD}GB free storage.' msg += f'\nYour File/Folder size is {get_readable_file_size(size)}' dl.getListener().onDownloadError(msg) return api.remove([download], force=True, files=True) if ZIP_UNZIP_LIMIT is not None and arch: mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB' limit = ZIP_UNZIP_LIMIT elif TORRENT_DIRECT_LIMIT is not None: mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB' limit = TORRENT_DIRECT_LIMIT if limit is not None: LOGGER.info('Checking File/Folder Size...') if size > limit * 1024**3: dl.getListener().onDownloadError( f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}' ) return api.remove([download], force=True, files=True) except: LOGGER.error( f"onDownloadStart: {gid} stop duplicate and size check didn't pass" )
def cancel_mirror(update, context): 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.", context.bot, update) return mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: keys = list(download_dict.keys()) try: dl = download_dict[mirror_message.message_id] except: pass if len(args) == 1 and (not mirror_message or mirror_message.message_id not in keys): msg = f"Reply to active <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or send <code>/{BotCommands.CancelMirror} GID</code> to cancel it!" sendMessage(msg, context.bot, update) return if dl.status() == MirrorStatus.STATUS_ARCHIVING: sendMessage("Archival in Progress, You Can't Cancel It.", context.bot, update) elif dl.status() == MirrorStatus.STATUS_EXTRACTING: sendMessage("Extract in Progress, You Can't Cancel It.", context.bot, update) elif dl.status() == MirrorStatus.STATUS_SPLITTING: sendMessage("Split in Progress, You Can't Cancel It.", context.bot, update) else: dl.download().cancel_download()
def cancel_mirror(update,context): 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.",context.bot,update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "Mirror already have been cancelled" sendMessage(msg,context.bot,update) return else: msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!" sendMessage(msg,context.bot,update) return if dl.status() == "Uploading": dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/') return
def xdcc_download(update, context): bot = context.bot message_args = update.message.text.split(' ', 2) try: server_channel = message_args[1] except IndexError: server_channel = '' server_channel = server_channel.strip() if not server_channel: sendMessage('You need to provide a channel to join.', bot, update) return try: command = message_args[2] except IndexError: command = message_args[2] if not command: sendMessage('You need to provide download command.', bot, update) return server_channel = server_channel.split(",") server_info = {} args = {} for each_info in server_channel: info = each_info.split("=") if info[0].lower() == "channel": args.update({info[0]: info[1]}) else: server_info.update({info[0]: info[1]}) tag = None pattern = r".* (.*?) xdcc (send|batch) (.*)" commands = re.match(pattern, command) args.update({ "bot": commands.group(1), "action": commands.group(2), "packs": commands.group(3) }) gid = format(binascii.crc32((args['bot'] + args['packs']).encode('utf8')), '08x') if getDownloadByGid(gid): sendMessage('Mirror already in queue.', bot, update) return root = f"/{args['bot']} {args['packs']}/" listener = MirrorListener(bot, update, False, tag, root=root) xdcc_dl = XDCCDownload(listener) xdcc_dl.add_download(args, f'{DOWNLOAD_DIR}{listener.uid}/{root}') sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def __onDownloadComplete(self, api: API, gid): LOGGER.info(f"onDownloadComplete: {gid}") dl = getDownloadByGid(gid) download = api.get_download(gid) if download.followed_by_ids: new_gid = download.followed_by_ids[0] new_download = api.get_download(new_gid) if dl is None: dl = getDownloadByGid(new_gid) with download_dict_lock: download_dict[dl.uid()] = AriaDownloadStatus( new_gid, dl.getListener()) if new_download.is_torrent: download_dict[dl.uid()].is_torrent = True update_all_messages() LOGGER.info(f"Changed gid from {gid} to {new_gid}") elif dl: threading.Thread( target=dl.getListener().onDownloadComplete).start()
def __onDownloadError(self, api, gid): sleep( 0.5 ) # sleep for split second to ensure proper dl gid update from onDownloadComplete LOGGER.info(f"onDownloadError: {gid}") dl = getDownloadByGid(gid) download = api.get_download(gid) error = download.error_message LOGGER.info(f"Download Error: {error}") if dl: dl.getListener().onDownloadError(error)
def __onDownloadError(api, gid): LOGGER.info(f"onDownloadError: {gid}") sleep(0.5) dl = getDownloadByGid(gid) try: download = api.get_download(gid) error = download.error_message LOGGER.info(f"Download Error: {error}") except: pass if dl: dl.getListener().onDownloadError(error)
def cancel_mirror(update, context): 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.", context.bot, update) return mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: keys = list(download_dict.keys()) try: dl = download_dict[mirror_message.message_id] except: pass if len(args) == 1: msg = f"Please reply to the <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or send <code>/{BotCommands.CancelMirror} GID</code> to cancel it!" if mirror_message and mirror_message.message_id not in keys: if BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text or \ BotCommands.UnzipMirrorCommand in mirror_message.text: msg1 = "Mirror Already Have Been Cancelled" sendMessage(msg1, context.bot, update) return else: sendMessage(msg, context.bot, update) return elif not mirror_message: sendMessage(msg, context.bot, update) return if dl.status() == "Uploading...📤": sendMessage("Upload in Progress, You Can't Cancel It.", context.bot, update) return elif dl.status() == "Archiving...🔐": sendMessage("Archival in Progress, You Can't Cancel It.", context.bot, update) return elif dl.status() == "Extracting...📂": sendMessage("Extract in Progress, You Can't Cancel It.", context.bot, update) return else: dl.download().cancel_download() sleep( 3 ) # incase of any error with ondownloaderror listener, clean_download will delete the folder but the download will stuck in status msg. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def cancel_mirror(update, context): 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.", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message else: if update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: try: keys = list(download_dict.keys()) dl = download_dict[mirror_message.message_id] except: sendMessage( "It's not your msg, reply to your mirror msg which was used to start the download to cancel.", context.bot, update) return if not update.message.reply_to_message: pass try: if dl.status() == "Uploading...📤": sendMessage("Upload in progress, can't cancel.", context.bot, update) return elif dl.status() == "Archiving...🔐": sendMessage("Archival in progress, can't cancel.", context.bot, update) return elif dl.status() == "Extracting...📂": sendMessage("Extract in progress, can't cancel.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/') except: psn = f"Please reply to your mirror msg which was used to start the download or <code>/{BotCommands.CancelMirror} GID</code> to cancel." sendMessage(psn, context.bot, update) return
def __onDownloadStarted(api, gid): if STOP_DUPLICATE or TORRENT_DIRECT_LIMIT is not None or ZIP_UNZIP_LIMIT is not None: sleep(1.5) dl = getDownloadByGid(gid) download = api.get_download(gid) try: if STOP_DUPLICATE and dl is not None and not dl.getListener( ).isLeech: LOGGER.info('Checking File/Folder if already in Drive...') sname = download.name if dl.getListener().isZip: sname = sname + ".zip" if not dl.getListener().extract: smsg, button = GoogleDriveHelper().drive_list(sname, True) if smsg: dl.getListener().onDownloadError( 'File/Folder already available in Drive.\n\n') api.remove([download], force=True, files=True) sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button) return if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None): sleep(1) limit = None if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract): mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB' limit = ZIP_UNZIP_LIMIT elif TORRENT_DIRECT_LIMIT is not None: mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB' limit = TORRENT_DIRECT_LIMIT if limit is not None: LOGGER.info('Checking File/Folder Size...') size = api.get_download(gid).total_length if size > limit * 1024**3: dl.getListener().onDownloadError( f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}' ) api.remove([download], force=True, files=True) return except: LOGGER.error( f"onDownloadStart: {gid} stop duplicate and size check didn't pass" )
def get_confirm(update, context): query = update.callback_query user_id = query.from_user.id data = query.data data = data.split(" ") qbdl = getDownloadByGid(data[1]) if qbdl is None: query.answer(text="This task has been cancelled!", show_alert=True) query.message.delete() elif user_id != qbdl.listener().message.from_user.id: query.answer(text="Don't waste your time!", show_alert=True) elif data[0] == "pin": query.answer(text=data[2], show_alert=True) elif data[0] == "done": query.answer() qbdl.client().torrents_resume(torrent_hashes=data[2]) sendStatusMessage(qbdl.listener().update, qbdl.listener().bot) query.message.delete()
def cancel_mirror(update, context): 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.", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "⛽𝐌𝐢𝐫𝐫𝐨𝐫 𝐎𝐟 𝐘𝐨𝐮𝐫 𝐅𝐢𝐥𝐞 𝐀𝐥𝐫𝐞𝐚𝐝𝐲 𝐇𝐚𝐯𝐞 𝐁𝐞𝐞𝐧 𝐂𝐚𝐧𝐜𝐞𝐥𝐥𝐞𝐝" sendMessage(msg, context.bot, update) return else: msg = "⛽𝐏𝐥𝐞𝐚𝐬𝐞 𝐑𝐞𝐩𝐥𝐲 𝐓𝐨 𝐓𝐡𝐞 /mirror 𝐌𝐞𝐬𝐬𝐚𝐠𝐞 𝐖𝐡𝐢𝐜𝐡 𝐖𝐚𝐬 𝐔𝐬𝐞𝐝 𝐓𝐨 𝐒𝐭𝐚𝐫𝐭 𝐓𝐡𝐞 𝐃𝐨𝐰𝐧𝐥𝐨𝐚𝐝 𝐨𝐫 /cancel 𝐆𝐢𝐝 𝐓𝐨 𝐂𝐚𝐧𝐜𝐞𝐥 𝐈𝐭!" sendMessage(msg, context.bot, update) return if dl.status() == "𝐔𝐩𝐥𝐨𝐚𝐝𝐢𝐧𝐠 📤...": sendMessage( "⛽𝐔𝐩𝐥𝐨𝐚𝐝𝐢𝐧𝐠 𝐎𝐟 𝐘𝐨𝐮𝐫 𝐅𝐢𝐥𝐞 𝐈𝐬 𝐀𝐥𝐫𝐞𝐚𝐝𝐲 𝐈𝐧 𝐏𝐫𝐨𝐠𝐫𝐞𝐬𝐬, 𝐃𝐨𝐧'𝐭 𝐂𝐚𝐧𝐜𝐞𝐥 𝐈𝐭.", context.bot, update) return elif dl.status() == "𝐀𝐫𝐜𝐡𝐢𝐯𝐢𝐧𝐠 🗃️🔐...": sendMessage( "⛽𝐀𝐫𝐜𝐡𝐢𝐯𝐚𝐥 𝐎𝐟 𝐘𝐨𝐮𝐫 𝐅𝐢𝐥𝐞 𝐈𝐬 𝐈𝐧 𝐀𝐥𝐫𝐞𝐚𝐝𝐲 𝐏𝐫𝐨𝐠𝐫𝐞𝐬𝐬, 𝐃𝐨𝐧'𝐭 𝐂𝐚𝐧𝐜𝐞𝐥 𝐈𝐭.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def cancel_mirror(update, context): 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"<b>Gɪᴅ:</b> <code>{gid}</code> <b>Nᴏᴛ Fᴏᴜɴᴅ🚫.</b>", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "<b>☘️Mɪʀʀᴏʀ Aʟʀᴇᴀᴅʏ Hᴀᴠᴇ Bᴇᴇɴ Cᴀɴᴄᴇʟʟᴇᴅ</b>" sendMessage(msg, context.bot, update) return else: msg = "<b>⛽Pʟᴇᴀsᴇ Rᴇᴘʟʏ Tᴏ Tʜᴇ</b> /{BotCommands.MirrorCommand} <b>Mᴇssᴀɢᴇ Wʜɪᴄʜ Wᴀs Usᴇᴅ Tᴏ Sᴛᴀʀᴛ Tʜᴇ Dᴏᴡɴʟᴏᴀᴅ Oʀ</b> /{BotCommands.CancelMirror} <b>Gɪᴅ Tᴏ Cᴀɴᴄᴇʟ Mɪʀʀᴏʀ Yᴏᴜʀ Pʀᴏᴄᴇss!</b>" sendMessage(msg, context.bot, update) return if dl.status() == "Uploading": sendMessage( "<b>📤Uᴘʟᴏᴀᴅ Oꜰ Yᴏᴜʀ Fɪʟᴇ Is Aʟʀᴇᴀᴅʏ Iɴ Pʀᴏɢʀᴇss, Pʟᴇᴀsᴇ 🚫Dᴏɴ'ᴛ Cᴀɴᴄᴇʟ Iᴛ!</b>", context.bot, update) return elif dl.status() == "Archiving": sendMessage( "<b>🔐Aʀᴄʜɪᴠᴀʟ Oꜰ Yᴏᴜʀ Fɪʟᴇ Is Aʟʀᴇᴀᴅʏ Iɴ Pʀᴏɢʀᴇss, Pʟᴇᴀsᴇ 🚫Dᴏɴ'ᴛ Cᴀɴᴄᴇʟ Iᴛ!</b>", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def cancel_mirror(update, context): 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.", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in update.message.text or \ BotCommands.TarMirrorCommand in update.message.text or \ BotCommands.UnzipMirrorCommand in update.message.text: msg = "Mirror Already Have Been Cancelled" sendMessage(msg, context.bot, update) return else: msg = f"Please reply to the <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or <code>/{BotCommands.CancelMirror} GID</code> to cancel it!" sendMessage(msg, context.bot, update) return if dl.status() == "Uploading...📤": sendMessage("Upload in Progress, You Can't Cancel It.", context.bot, update) return elif dl.status() == "Archiving...🔐": sendMessage("Archival in Progress, You Can't Cancel It.", context.bot, update) return elif dl.status() == "Extracting...📂": sendMessage("Extract in Progress, You Can't Cancel It.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def cancel_mirror(update, context): 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"𝗚𝗜𝗗: <code>{gid}</code> not found.", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "𝗧𝗼𝗿𝗿𝗲𝗻𝘁 𝗮𝗹𝗿𝗲𝗮𝗱𝘆 𝗵𝗮𝘃𝗲 𝗯𝗲𝗲𝗻 𝗖𝗮𝗻𝗰𝗲𝗹𝗹𝗲𝗱" sendMessage(msg, context.bot, update) return else: msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!" sendMessage(msg, context.bot, update) return if dl.status() == "Uploading": sendMessage("Upload in Progress, Don't Cancel it.", context.bot, update) return elif dl.status() == "Archiving": sendMessage("Archival in Progress, Don't Cancel it.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def cancel_mirror(update, context): 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"ID yang kamu mirror: <code>{gid}</code> Gak ditemukan.", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "Mirror nya udah aku berhentiin ya" sendMessage(msg, context.bot, update) return else: msg = "Kalo pengen nge mirror pake /kaca sama kalo pengen batalin pake /gagal" sendMessage(msg, context.bot, update) return if dl.status() == "Lagi upload": sendMessage("Lagi Proses upload jangan digagalin.", context.bot, update) return elif dl.status() == "Lagi Nge Arsip": sendMessage("Lagi Nge arsip jangan dibatalin.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def cancel_mirror(client: Client, message: Message): args = 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.", client, message) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif message.reply_to_message: mirror_message = message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "Mirror already have been cancelled" sendMessage(msg, client, message) return else: msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!" sendMessage(msg, client, message) return if dl.status() == "Uploading": sendMessage("Upload in Progress, Don't Cancel it.", client, message) return elif dl.status() == "Archiving": sendMessage("Archival in Progress, Don't Cancel it.", client, message) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download( os.path.join(DOWNLOAD_DIR, str(mirror_message.message_id)) + os.path.sep)
def cancel_mirror(update, context): 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> không tìm thấy.", context.bot, update) return with download_dict_lock: keys = list(download_dict.keys()) mirror_message = dl.message elif update.message.reply_to_message: mirror_message = update.message.reply_to_message with download_dict_lock: 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 BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "Mirror already have been cancelled" sendMessage(msg, context.bot, update) return else: msg = "Vui lòng trả lời tin nhắn /mirror được sử dụng để bắt đầu tải xuống hoặc /cancel gid để hủy nó!" sendMessage(msg, context.bot, update) return if dl.status() == "Uploading": sendMessage("Đang tải lên, vui lòng không hủy.", context.bot, update) return elif dl.status() == "Archiving": sendMessage("Đang tiến hành lưu trữ, vui lòng không hủy bỏ.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/')
def __onDownloadComplete(self, api: API, gid): LOGGER.info(f"onDownloadComplete: {gid}") dl = getDownloadByGid(gid) download = api.get_download(gid) if download.followed_by_ids: new_gid = download.followed_by_ids[0] new_download = api.get_download(new_gid) with download_dict_lock: download_dict[dl.uid()] = AriaDownloadStatus( new_gid, dl.getListener(), self) if new_download.is_torrent: download_dict[dl.uid()].is_torrent = True update_all_messages() LOGGER.info(f'Changed gid from {gid} to {new_gid}') return if dl: queue = self.queue_dict[dl.uid()] if queue.current_download != queue.queue_length: self.__startNextDownload(dl.uid()) return threading.Thread( target=dl.getListener().onDownloadComplete).start()
def __onDownloadStopped(self, api, gid): LOGGER.info(f"onDownloadStop: {gid}") dl = getDownloadByGid(gid) if dl: dl.getListener().onDownloadError("Download stopped by user!")
def __onDownloadStarted(self, api, gid): LOGGER.info(f"onDownloadStart: {gid}") dl = getDownloadByGid(gid) if dl: self.queue_dict[dl.uid()].name = api.get_download(gid).name update_all_messages()
def __onDownloadStopped(api, gid): sleep(4) dl = getDownloadByGid(gid) if dl: dl.getListener().onDownloadError('Dead torrent!')