async def rclone_command_f(client, message): """/rclone command""" LOGGER.info( f"rclone command from chatid:{message.chat.id}, userid:{message.from_user.id}" ) if message.from_user.id == OWNER_ID and message.chat.type == "private": config.read("rclone_bak.conf") sections = list(config.sections()) inline_keyboard = [] for section in sections: ikeyboard = [ pyrogram.InlineKeyboardButton( section, callback_data=(f"rclone_{section}").encode("UTF-8") ) ] inline_keyboard.append(ikeyboard) config.read("rclone.conf") section = config.sections()[0] msg_text = f"""Default section of rclone config is: **{section}**\n\n There are {len(sections)} sections in your rclone.conf file, please choose which section you want to use:""" ikeyboard = [ pyrogram.InlineKeyboardButton( "‼️ Cancel ‼️", callback_data=(f"rcloneCancel").encode("UTF-8") ) ] inline_keyboard.append(ikeyboard) reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard) await message.reply_text(text=msg_text, reply_markup=reply_markup) else: await message.reply_text("You have no permission!") LOGGER.warning( f"uid={message.from_user.id} have no permission to edit rclone config!" )
async def upload_single_file( message, local_file_name, caption_str, from_user, client, edit_media, yt_thumb ): await asyncio.sleep(EDIT_SLEEP_TIME_OUT) local_file_name = str(Path(local_file_name).resolve()) sent_message = None start_time = time.time() # thumbnail_location = os.path.join( DOWNLOAD_LOCATION, "thumbnails", str(from_user) + ".jpg" ) # LOGGER.info(thumbnail_location) if UPLOAD_AS_DOC.upper() == "TRUE": # todo: this code will be removed in future thumb = None thumb_image_path = None if os.path.exists(thumbnail_location): thumb_image_path = await copy_file( thumbnail_location, os.path.dirname( os.path.abspath(local_file_name)) ) thumb = thumb_image_path message_for_progress_display = message if not edit_media: message_for_progress_display = await message.reply_text( "starting upload of {}".format( os.path.basename(local_file_name)) ) prog = Progress(from_user, client, message_for_progress_display) sent_message = await message.reply_document( document=local_file_name, thumb=thumb, caption=caption_str, parse_mode="html", disable_notification=True, progress=prog.progress_for_pyrogram, progress_args=( f"{os.path.basename(local_file_name)}", start_time, ), ) if edit_media: await message_for_progress_display.delete() if message.message_id != message_for_progress_display.message_id: try: await message_for_progress_display.delete() except FloodWait as gf: time.sleep(gf.x) except Exception as rr: LOGGER.warning(str(rr)) os.remove(local_file_name) if thumb is not None: os.remove(thumb) else: try: message_for_progress_display = message if not edit_media: message_for_progress_display = await message.reply_text( "starting upload of {}".format( os.path.basename(local_file_name)) ) prog = Progress(from_user, client, message_for_progress_display) if local_file_name.upper().endswith(("MKV", "MP4", "WEBM", "M4V", "3GP")): duration = 0 try: metadata = extractMetadata(createParser(local_file_name)) if metadata.has("duration"): duration = metadata.get("duration").seconds except Exception as g_e: LOGGER.info(g_e) width = 0 height = 0 thumb_image_path = None if os.path.exists(thumbnail_location): thumb_image_path = await copy_file( thumbnail_location, os.path.dirname(os.path.abspath(local_file_name)), ) else: if not yt_thumb: thumb_image_path = await take_screen_shot( local_file_name, os.path.dirname(os.path.abspath(local_file_name)), (duration / 2), ) else: req = requests.get(yt_thumb) thumb_image_path = os.path.join( os.path.dirname(os.path.abspath(local_file_name)), str(time.time()) + ".jpg", ) with open(thumb_image_path, "wb") as thum: thum.write(req.content) img = Image.open(thumb_image_path).convert("RGB") img.save(thumb_image_path, format="jpeg") # get the correct width, height, and duration for videos greater than 10MB if os.path.exists(thumb_image_path): metadata = extractMetadata( createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path ) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails # thumb = None if thumb_image_path is not None and os.path.isfile(thumb_image_path): thumb = thumb_image_path # send video if edit_media and message.photo: await asyncio.sleep(EDIT_SLEEP_TIME_OUT) sent_message = await message.edit_media( media=InputMediaVideo( media=local_file_name, thumb=thumb, caption=caption_str, parse_mode="html", width=width, height=height, duration=duration, supports_streaming=True, ) # quote=True, ) else: sent_message = await message.reply_video( video=local_file_name, caption=caption_str, parse_mode="html", duration=duration, width=width, height=height, thumb=thumb, supports_streaming=True, disable_notification=True, progress=prog.progress_for_pyrogram, progress_args=( f"{os.path.basename(local_file_name)}", start_time, ), ) if thumb is not None: os.remove(thumb) elif local_file_name.upper().endswith(("MP3", "M4A", "M4B", "FLAC", "WAV")): metadata = extractMetadata(createParser(local_file_name)) duration = 0 title = "" artist = "" if metadata.has("duration"): duration = metadata.get("duration").seconds if metadata.has("title"): title = metadata.get("title") if metadata.has("artist"): artist = metadata.get("artist") thumb_image_path = None if os.path.isfile(thumbnail_location): thumb_image_path = await copy_file( thumbnail_location, os.path.dirname(os.path.abspath(local_file_name)), ) thumb = None if thumb_image_path is not None and os.path.isfile(thumb_image_path): thumb = thumb_image_path # send audio if edit_media and message.photo: await asyncio.sleep(EDIT_SLEEP_TIME_OUT) sent_message = await message.edit_media( media=InputMediaAudio( media=local_file_name, thumb=thumb, caption=caption_str, parse_mode="html", duration=duration, performer=artist, title=title, ) ) else: sent_message = await message.reply_audio( audio=local_file_name, caption=caption_str, parse_mode="html", duration=duration, performer=artist, title=title, thumb=thumb, disable_notification=True, progress=prog.progress_for_pyrogram, progress_args=( f"{os.path.basename(local_file_name)}", start_time, ), ) if thumb is not None: os.remove(thumb) else: thumb_image_path = None if os.path.isfile(thumbnail_location): thumb_image_path = await copy_file( thumbnail_location, os.path.dirname(os.path.abspath(local_file_name)), ) # if a file, don't upload "thumb" # this "diff" is a major derp -_- 😔😭😭 thumb = None if thumb_image_path is not None and os.path.isfile(thumb_image_path): thumb = thumb_image_path # # send document if edit_media and message.photo: sent_message = await message.edit_media( media=InputMediaDocument( media=local_file_name, thumb=thumb, caption=caption_str, parse_mode="html", ) ) else: sent_message = await message.reply_document( document=local_file_name, thumb=thumb, caption=caption_str, parse_mode="html", disable_notification=True, progress=prog.progress_for_pyrogram, progress_args=( f"{os.path.basename(local_file_name)}", start_time, ), ) if thumb is not None: os.remove(thumb) except MessageNotModified as oY: LOGGER.info(oY) except FloodWait as g: LOGGER.info(g) time.sleep(g.x) except Exception as e: LOGGER.info(e) await message_for_progress_display.edit_text("**FAILED**\n" + str(e)) else: if message.message_id != message_for_progress_display.message_id: try: if sent_message is not None: await message_for_progress_display.delete() except FloodWait as gf: time.sleep(gf.x) except Exception as rr: LOGGER.warning(str(rr)) await asyncio.sleep(5) os.remove(local_file_name) return sent_message
async def check_progress_for_dl(aria2, gid, event, previous_message): # g_id = event.reply_to_message.from_user.id try: file = aria2.get_download(gid) complete = file.is_complete is_file = file.seeder if not complete: if not file.error_message: msg = "" # sometimes, this weird https://t.me/c/1220993104/392975 # error creeps up # TODO: temporary workaround downloading_dir_name = "N/A" try: # another derp -_- # https://t.me/c/1220993104/423318 downloading_dir_name = str(file.name) except: pass # if is_file is None: msgg = f"Conn: {file.connections} <b>|</b> GID: <code>{gid}</code>" else: msgg = f"P: {file.connections} | S: {file.num_seeders} <b>|</b> GID: <code>{gid}</code>" msg = f"\n`{downloading_dir_name}`" msg += f"\n<b>Speed</b>: {file.download_speed_string()}" msg += f"\n<b>Status</b>: {file.progress_string()} <b>of</b> {file.total_length_string()} <b>|</b> {file.eta_string()} <b>|</b> {msgg}" # msg += f"\nSize: {file.total_length_string()}" # if is_file is None : # msg += f"\n<b>Conn:</b> {file.connections}, GID: <code>{gid}</code>" # else : # msg += f"\n<b>Info:</b>[ P : {file.connections} | S : {file.num_seeders} ], GID: <code>{gid}</code>" # msg += f"\nStatus: {file.status}" # msg += f"\nETA: {file.eta_string()}" # msg += f"\nGID: <code>{gid}</code>" inline_keyboard = [] ikeyboard = [] ikeyboard.append( InlineKeyboardButton( "Cancel 🚫", callback_data=(f"cancel {gid}").encode("UTF-8"))) inline_keyboard.append(ikeyboard) reply_markup = InlineKeyboardMarkup(inline_keyboard) if msg != previous_message: if not file.has_failed: try: await event.edit(msg, reply_markup=reply_markup) except FloodWait as e_e: LOGGER.warning(f"Trying to sleep for {e_e}") time.sleep(e_e.x) except MessageNotModified as e_p: LOGGER.info(e_p) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) previous_message = msg else: LOGGER.info( f"Cancelling downloading of {file.name} may be due to slow torrent" ) await event.edit( f"Download cancelled :\n<code>{file.name}</code>\n\n #MetaDataError" ) file.remove(force=True, files=True) return False else: msg = file.error_message LOGGER.info(msg) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit(f"`{msg}`") return False await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) else: LOGGER.info( f"Downloaded Successfully: `{file.name} ({file.total_length_string()})` 🤒" ) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit( f"Downloaded Successfully: `{file.name} ({file.total_length_string()})` 🤒" ) return True except aria2p.client.ClientException: await event.edit( f"Download cancelled :\n<code>{file.name} ({file.total_length_string()})</code>" ) except MessageNotModified as ep: LOGGER.info(ep) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) except FloodWait as e: LOGGER.info(e) time.sleep(e.x) except RecursionError: file.remove(force=True, files=True) await event.edit("Download Auto Canceled :\n\n" "Your Torrent/Link is Dead.".format(file.name)) return False except Exception as e: LOGGER.info(str(e)) if "not found" in str(e) or "'file'" in str(e): await event.edit( f"Download cancelled :\n<code>{file.name} ({file.total_length_string()})</code>" ) return False else: LOGGER.info(str(e)) await event.edit( "<u>error</u> :\n<code>{}</code> \n\n#error".format(str(e))) return False
async def check_progress_for_dl(aria2, gid, event, previous_message): # g_id = event.reply_to_message.from_user.id try: file = aria2.get_download(gid) complete = file.is_complete is_file = file.seeder if not complete: if not file.error_message: msg = "" # sometimes, this weird https://t.me/c/1220993104/392975 # error creeps up # TODO: temporary workaround downloading_dir_name = "N/A" try: # another derp -_- # https://t.me/c/1220993104/423318 downloading_dir_name = str(file.name) except: pass # if is_file is None: msgg = f"<b>╠═ ⚙ 𝗖𝗢𝗡𝗡𝗘𝗖𝗧𝗜𝗢𝗡𝗦 : {file.connections}</b>" else: msgg = f"<b>╠═ 🔍 𝗜𝗡𝗙𝗢 :𝗣𝗘𝗘𝗥: {file.connections} || 𝗦𝗘𝗘𝗗: {file.num_seeders} </b>\n\n<b>╠═ 🗑️ 𝗚𝗜𝗗 :</b> <code>{gid}</code>" msg = f"\n<b> ╔═══════════════ ⌊ 📥 𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗𝗜𝗡𝗚.. ⌉ \n║" msg += f"\n<b>╠═ 📀 𝗡𝗔𝗠𝗘 :</b> `{downloading_dir_name}`\n║\n<b>╠═ 🧭 𝗦𝗣𝗘𝗘𝗗 :</b> `{file.download_speed_string()}`\n║" msg += f"\n<b>╠═ 💾 𝗧𝗢𝗧𝗔𝗟 𝗦𝗜𝗭𝗘 :</b> `{file.total_length_string()}`\n<b>║" msg += f"\n<b>╠═ ⏳ 𝗗𝗼𝘄𝗻𝗹𝗼𝗮𝗱𝗲𝗱</b> : `{file.progress_string()}`\n║\n<b>╠═ ⏰ 𝗘𝗧𝗔 :</b> `{file.eta_string()}`\n║\n{msgg}\n║" msg += f"\n<b>╚════ ⌊⚡️ 𝗧𝗘𝗔𝗠 𝗗𝗘𝗩 ⌉" inline_keyboard = [] ikeyboard = [] ikeyboard.append( InlineKeyboardButton( "❌ Cancel ❌", callback_data=(f"cancel {gid}").encode("UTF-8"))) inline_keyboard.append(ikeyboard) reply_markup = InlineKeyboardMarkup(inline_keyboard) if msg != previous_message: if not file.has_failed: try: await event.edit(msg, reply_markup=reply_markup) except FloodWait as e_e: LOGGER.warning(f"Trying to sleep for {e_e}") time.sleep(e_e.x) except MessageNotModified as e_p: LOGGER.info(e_p) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) previous_message = msg else: LOGGER.info( f" 𝗖𝗔𝗡𝗖𝗘𝗟𝗟𝗜𝗡𝗚 𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗𝗜𝗡𝗚 𝗢𝗙 {file.name} 𝗠𝗔𝗬 𝗕𝗘 𝗗𝗨𝗘 𝗧𝗢 𝗦𝗟𝗢𝗪 𝗧𝗢𝗥𝗥𝗘𝗡𝗧\n\n#Cancelled" ) await event.edit( f"𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗 𝗖𝗔𝗡𝗖𝗘𝗟𝗟𝗘𝗗 ❌\n\n𝗙𝗶𝗹𝗲 𝗡𝗮𝗺𝗲 🗂 :<code>{file.name}</code>\n\n#Cancelled" ) file.remove(force=True, files=True) return False else: msg = file.error_message LOGGER.info(msg) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit(f"`{msg}`") return False await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) else: LOGGER.info( f"<b>𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗 𝗖𝗢𝗠𝗣𝗟𝗘𝗧𝗘𝗗 💯</b>\n\n <b>𝗙𝗶𝗹𝗲 𝗡𝗮𝗺𝗲</b> 🗂:`{file.name}`\n\n<b>𝗧𝗼𝘁𝗮𝗹 𝗦𝗶𝘇𝗲 ⚙</b>: `〘{file.total_length_string()}〙`\n\n#Completed" ) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit( f"<b>𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗 𝗖𝗢𝗠𝗣𝗟𝗘𝗧𝗘𝗗 💯</b>\n\n <b>𝗙𝗶𝗹𝗲 𝗡𝗮𝗺𝗲</b> 🗂:`{file.name}`\n\n<b>𝗧𝗼𝘁𝗮𝗹 𝗦𝗶𝘇𝗲 ⚙</b>: `〘{file.total_length_string()}〙`\n\n#Completed" ) return True except aria2p.client.ClientException: await event.edit( f"<b>𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗 𝗖𝗔𝗡𝗖𝗘𝗟𝗟𝗘𝗗 ❌</b>\n\n<b>𝗙𝗶𝗹𝗲 𝗡𝗮𝗺𝗲</b>🗂:<code>{file.name}\n\n<b>𝗧𝗼𝘁𝗮𝗹 𝗦𝗶𝘇𝗲 ⚙</b>: ({file.total_length_string()})</code>\n\n#Cancelled" ) except MessageNotModified as ep: LOGGER.info(ep) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) except FloodWait as e: LOGGER.info(e) time.sleep(e.x) except RecursionError: file.remove(force=True, files=True) await event.edit("*𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗 𝗔𝗨𝗧𝗢 𝗖𝗔𝗡𝗖𝗘𝗟𝗟𝗘𝗗 :**\n\n" "`𝗬𝗢𝗨𝗥 𝗧𝗢𝗥𝗥𝗘𝗡𝗧/𝗠𝗔𝗚𝗡𝗘𝗧 𝗟𝗜𝗡𝗞 𝗜𝗦 𝗗𝗘𝗔𝗗.`".format( file.name)) return False except Exception as e: LOGGER.info(str(e)) if "not found" in str(e) or "'file'" in str(e): await event.edit( f"𝗗𝗢𝗪𝗡𝗟𝗢𝗔𝗗 𝗖𝗔𝗡𝗖𝗘𝗟𝗟𝗘𝗗 ❌\n\n𝗙𝗶𝗹𝗲 𝗡𝗮𝗺𝗲 🗂 :<code>{file.name}\n\n𝗧𝗼𝘁𝗮𝗹 𝗦𝗶𝘇𝗲 ⚙:({file.total_length_string()})</code>\n\n#Cancelled" ) return False else: LOGGER.info(str(e)) await event.edit( "<u>❌ 𝗘𝗥𝗥𝗢𝗥 ❌</u> :\n<code>{}</code> \n\n#error".format(str(e)) ) return False
async def check_progress_for_dl(aria2, gid, event, previous_message): # g_id = event.reply_to_message.from_user.id try: file = aria2.get_download(gid) complete = file.is_complete is_file = file.seeder if not complete: if not file.error_message: msg = "" # sometimes, this weird https://t.me/c/1220993104/392975 # error creeps up # TODO: temporary workaround downloading_dir_name = "N/A" try: # another derp -_- # https://t.me/c/1220993104/423318 downloading_dir_name = str(file.name) except: pass # prog = pyprog.ProgressBar(" ", " ", total=100, bar_length=15, complete_symbol="●", not_complete_symbol="○", wrap_bar_prefix=" 〖", wrap_bar_suffix="〗 ", progress_explain="", progress_loc=pyprog.ProgressBar.PROGRESS_LOC_END) old_stdout = sys.stdout new_stdout = io.StringIO() sys.stdout = new_stdout p = file.progress_string() l = len(p) p=p[0:l-1] a = float(p) prog.set_stat(a) prog.update() output = new_stdout.getvalue() sys.stdout = old_stdout prg = output[3:len(output)] i = 0 i = int(i) STR = int(os.environ.get("STR", 30)) msg = f"╭──────── ⌊ 📥 <b>Downloading</b> ⌉ \n" msg += "│"+"\n├"+f"{prg}\n" +"│" msg += f"\n├<b>FileName</b> 📚: " while(len(downloading_dir_name)>0): st = downloading_dir_name[0:STR] if(i==0): msg += f"{downloading_dir_name[0:STR-15]}" downloading_dir_name = downloading_dir_name[STR-15:len(downloading_dir_name)] i = 1 else: msg += f"\n│{st}" downloading_dir_name = downloading_dir_name[STR:len(downloading_dir_name)] msg += f"\n├<b>Speed</b> 🚀 : <code>{file.download_speed_string()} </code>" msg += f"\n├<b>Total Size</b> 🗂 : <code>{file.total_length_string()}</code>" if is_file is None : msg += f"\n├<b>Connections</b> 📬 : <code>{file.connections}</code>" else : msg += f"\n├<b>Info</b> 📄 : <code>[ P : {file.connections} || S : {file.num_seeders} ]</code>" # msg += f"\n<b>Status</b> : <code>{file.status}</code>" msg += f"\n├<b>ETA</b> ⏳ : <code>{file.eta_string()}</code>" +"\n│" msg += "\n╰─── ⌊ ⚡️ using engine aria2 ⌉" inline_keyboard = [] ikeyboard = [] ikeyboard.append( InlineKeyboardButton( "Cancel 🚫", callback_data=(f"cancel {gid}").encode("UTF-8") ) ) inline_keyboard.append(ikeyboard) reply_markup = InlineKeyboardMarkup(inline_keyboard) if msg != previous_message: if not file.has_failed: try: await event.edit(msg, reply_markup=reply_markup) except FloodWait as e_e: LOGGER.warning(f"Trying to sleep for {e_e}") time.sleep(e_e.x) except MessageNotModified as e_p: LOGGER.info(e_p) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) previous_message = msg else: LOGGER.info( f"Cancelling downloading of {file.name} may be due to slow torrent" ) await event.edit( f"Download cancelled :\n<code>{file.name}</code>\n\n #MetaDataError" ) file.remove(force=True, files=True) return False else: msg = file.error_message LOGGER.info(msg) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit(f"`{msg}`") return False await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) else: LOGGER.info( f"Downloaded Successfully: `{file.name} ({file.total_length_string()})` 🤒" ) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit( f"Downloaded Successfully: `{file.name} ({file.total_length_string()})` 🤒" ) return True except aria2p.client.ClientException: await event.edit( f"Download cancelled :\n<code>{file.name} ({file.total_length_string()})</code>" ) except MessageNotModified as ep: LOGGER.info(ep) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) except FloodWait as e: LOGGER.info(e) time.sleep(e.x) except RecursionError: file.remove(force=True, files=True) await event.edit( "Download Auto Canceled :\n\n" "Your Torrent/Link is Dead.".format(file.name) ) return False except Exception as e: LOGGER.info(str(e)) if "not found" in str(e) or "'file'" in str(e): await event.edit( f"Download cancelled :\n<code>{file.name} ({file.total_length_string()})</code>" ) return False else: LOGGER.info(str(e)) await event.edit( "<u>error</u> :\n<code>{}</code> \n\n#error".format(str(e)) ) return False
async def check_progress_for_dl(aria2, gid, event, previous_message): # g_id = event.reply_to_message.from_user.id try: file = aria2.get_download(gid) complete = file.is_complete is_file = file.seeder if not complete: if not file.error_message: msg = "" # sometimes, this weird https://t.me/c/1220993104/392975 # error creeps up # TODO: temporary workaround downloading_dir_name = "N/A" try: # another derp -_- # https://t.me/c/1220993104/423318 downloading_dir_name = str(file.name) except: pass # if is_file is None: msgg = f"<b>╠═ ⚙ 𝗖𝗼𝗻𝗻𝗲𝗰𝘁𝗶𝗼𝗻𝘀 : {file.connections}</b>" else: msgg = f"<b>➩ Info :- P: {file.connections} || S: {file.num_seeders} </b>\n\n<b>🗑️ GID :</b> <code>{gid}</code>" msg = f"\n<b> ╔═══════════════ ⌊ 📥 𝗗𝗼𝘄𝗻𝗹𝗼𝗮𝗱𝗶𝗻𝗴.. ⌉ \n║" msg += f"\n<b>╠═ 📀 𝗙𝗶𝗹𝗲 𝗡𝗮𝗺𝗲 :</b> `{downloading_dir_name}`\n║\n<b>╠═ 🧭 𝗦𝗽𝗲𝗲𝗱 :</b> `{file.download_speed_string()}`\n║" msg += f"\n<b>╠═ 💾 𝗧𝗼𝘁𝗮𝗹 𝗦𝗶𝘇𝗲 :</b> `{file.total_length_string()}`\n<b>║" msg += f"\n<b>╠═ ⏳ 𝗗𝗼𝘄𝗻𝗹𝗼𝗮𝗱𝗲𝗱</b> : `{file.progress_string()}`\n║\n<b>╠═ ⏰ 𝗘𝗧𝗔 :</b> `{file.eta_string()}`\n║\n{msgg}\n║" msg += f"\n<b>╚════ ⌊⚡️ 𝗗𝗘𝗩 𝗖𝗟𝗢𝗨𝗗 ⌉" inline_keyboard = [] ikeyboard = [] ikeyboard.append( InlineKeyboardButton( "❌ Cancel ❌", callback_data=(f"cancel {gid}").encode("UTF-8") ) ) inline_keyboard.append(ikeyboard) reply_markup = InlineKeyboardMarkup(inline_keyboard) if msg != previous_message: if not file.has_failed: try: await event.edit(msg, reply_markup=reply_markup) except FloodWait as e_e: LOGGER.warning(f"Trying to sleep for {e_e}") time.sleep(e_e.x) except MessageNotModified as e_p: LOGGER.info(e_p) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) previous_message = msg else: LOGGER.info( f"Cancelling downloading of {file.name} may be due to slow torrent" ) await event.edit( f"**Download cancelled :**\n<code>{file.name}</code>\n\n #MetaDataError" ) file.remove(force=True, files=True) return False else: msg = file.error_message LOGGER.info(msg) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit(f"`{msg}`") return False await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) else: LOGGER.info( f"<b> Downloaded Successfully 💯</b>: `{file.name} ({file.total_length_string()})` 🤒" ) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await event.edit( f"<b>Downloaded Successfully 💯</b>:\n\n <b>File Name</b> 🗂: \n`{file.name}`\n\n📀 <b>Total Size ⚙</b>: `〘{file.total_length_string()}〙`" ) return True except aria2p.client.ClientException: await event.edit( f"Download cancelled :\n<code>{file.name} ({file.total_length_string()})</code>" ) except MessageNotModified as ep: LOGGER.info(ep) await asyncio.sleep(EDIT_SLEEP_TIME_OUT) await check_progress_for_dl(aria2, gid, event, previous_message) except FloodWait as e: LOGGER.info(e) time.sleep(e.x) except RecursionError: file.remove(force=True, files=True) await event.edit( "*Download Auto Canceled :**\n\n" "`Your Torrent/Link is Dead.`👺".format(file.name) ) return False except Exception as e: LOGGER.info(str(e)) if "not found" in str(e) or "'file'" in str(e): await event.edit( f"Download cancelled :\n<code>{file.name} ({file.total_length_string()})</code>" ) return False else: LOGGER.info(str(e)) await event.edit( "<u>error</u> :\n<code>{}</code> \n\n#error".format(str(e)) ) return False