diff --git a/bot/helper/ext_utils/bot_utils.py b/bot/helper/ext_utils/bot_utils.py index ab36f0b..bc5f370 100644 --- a/bot/helper/ext_utils/bot_utils.py +++ b/bot/helper/ext_utils/bot_utils.py @@ -93,17 +93,23 @@ def get_readable_message(): with download_dict_lock: msg = "" for download in list(download_dict.values()): - msg += f"{download.name()} - " - msg += download.status() + msg += f"Filename : {download.name()}" + msg += f"\nStatus : {download.status()}" if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING: - msg += f"\n{get_progress_bar_string(download)} {download.progress()} of " \ - f"{download.size()}" \ - f" at {download.speed()}, ETA: {download.eta()} " + msg += f"\n{get_progress_bar_string(download)} {download.progress()}" + if download.status() == MirrorStatus.STATUS_DOWNLOADING: + msg += f"\nDownloaded : {get_readable_file_size(download.processed_bytes())} of {download.size()}" + else: + msg += f"\nUploaded : {get_readable_file_size(download.processed_bytes())} of {download.size()}" + msg += f"\nSpeed : {download.speed()}, \nETA: {download.eta()} " + # if hasattr(download, 'is_torrent'): + try: + msg += f"\nInfo :- Seeders: {download.aria_download().num_seeders}" \ + f" & Peers : {download.aria_download().connections}" + except: + pass if download.status() == MirrorStatus.STATUS_DOWNLOADING: - if hasattr(download, 'is_torrent'): - msg += f"| P: {download.aria_download().connections} " \ - f"| S: {download.aria_download().num_seeders}" - msg += f"\nGID: {download.gid()}" + msg += f"\nGID: {download.gid()}" msg += "\n\n" return msg diff --git a/bot/helper/telegram_helper/message_utils.py b/bot/helper/telegram_helper/message_utils.py index b5cafca..dd70d62 100644 --- a/bot/helper/telegram_helper/message_utils.py +++ b/bot/helper/telegram_helper/message_utils.py @@ -1,12 +1,12 @@ from telegram import InlineKeyboardMarkup from telegram.message import Message from telegram.update import Update +import psutil import time from bot import AUTO_DELETE_MESSAGE_DURATION, LOGGER, bot, \ - status_reply_dict, status_reply_dict_lock -from bot.helper.ext_utils.bot_utils import get_readable_message + status_reply_dict, status_reply_dict_lock, download_dict, download_dict_lock +from bot.helper.ext_utils.bot_utils import get_readable_message, get_readable_file_size, MirrorStatus from telegram.error import TimedOut, BadRequest -from bot import bot def sendMessage(text: str, bot, update: Update): @@ -68,6 +68,27 @@ def delete_all_messages(): def update_all_messages(): msg = get_readable_message() + msg += f"CPU: {psutil.cpu_percent()}%" \ + f" DISK: {psutil.disk_usage('/').percent}%" \ + f" RAM: {psutil.virtual_memory().percent}%" + with download_dict_lock: + dlspeed_bytes = 0 + uldl_bytes = 0 + for download in list(download_dict.values()): + speedy = download.speed() + if download.status() == MirrorStatus.STATUS_DOWNLOADING: + if 'KiB/s' in speedy: + dlspeed_bytes += float(speedy.split('K')[0]) * 1024 + elif 'MiB/s' in speedy: + dlspeed_bytes += float(speedy.split('M')[0]) * 1048576 + if download.status() == MirrorStatus.STATUS_UPLOADING: + if 'KB/s' in speedy: + uldl_bytes += float(speedy.split('K')[0]) * 1024 + elif 'MB/s' in speedy: + uldl_bytes += float(speedy.split('M')[0]) * 1048576 + dlspeed = get_readable_file_size(dlspeed_bytes) + ulspeed = get_readable_file_size(uldl_bytes) + msg += f"\nDL:{dlspeed}ps 🔻| UL:{ulspeed}ps 🔺\n" with status_reply_dict_lock: for chat_id in list(status_reply_dict.keys()): if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text: @@ -83,6 +104,27 @@ def update_all_messages(): def sendStatusMessage(msg, bot): progress = get_readable_message() + progress += f"CPU: {psutil.cpu_percent()}%" \ + f" DISK: {psutil.disk_usage('/').percent}%" \ + f" RAM: {psutil.virtual_memory().percent}%" + with download_dict_lock: + dlspeed_bytes = 0 + uldl_bytes = 0 + for download in list(download_dict.values()): + speedy = download.speed() + if download.status() == MirrorStatus.STATUS_DOWNLOADING: + if 'KiB/s' in speedy: + dlspeed_bytes += float(speedy.split('K')[0]) * 1024 + elif 'MiB/s' in speedy: + dlspeed_bytes += float(speedy.split('M')[0]) * 1048576 + if download.status() == MirrorStatus.STATUS_UPLOADING: + if 'KB/s' in speedy: + uldl_bytes += float(speedy.split('K')[0]) * 1024 + elif 'MB/s' in speedy: + uldl_bytes += float(speedy.split('M')[0]) * 1048576 + dlspeed = get_readable_file_size(dlspeed_bytes) + ulspeed = get_readable_file_size(uldl_bytes) + progress += f"\nDL:{dlspeed}ps 🔻| UL:{ulspeed}ps 🔺\n" with status_reply_dict_lock: if msg.message.chat.id in list(status_reply_dict.keys()): try: