Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 0fd9969

Browse files
authored
v3.8 (#15)
- Added overall DL, UL speed in /status - Added CPU, DISK, RAM usage in /status - Show peers and seeders
1 parent f783585 commit 0fd9969

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

bot/helper/ext_utils/bot_utils.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,23 @@ def get_readable_message():
9393
with download_dict_lock:
9494
msg = ""
9595
for download in list(download_dict.values()):
96-
msg += f"<i>{download.name()}</i> - "
97-
msg += download.status()
96+
msg += f"<b>Filename :</b> <code>{download.name()}</code>"
97+
msg += f"\n<b>Status :</b> <i>{download.status()}</i>"
9898
if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
99-
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code> of " \
100-
f"{download.size()}" \
101-
f" at {download.speed()}, ETA: {download.eta()} "
99+
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
100+
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
101+
msg += f"\n<b>Downloaded :</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
102+
else:
103+
msg += f"\n<b>Uploaded :</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
104+
msg += f"\n<b>Speed :</b> {download.speed()}, \n<b>ETA:</b> {download.eta()} "
105+
# if hasattr(download, 'is_torrent'):
106+
try:
107+
msg += f"\n<b>Info :- Seeders:</b> {download.aria_download().num_seeders}" \
108+
f" & <b>Peers :</b> {download.aria_download().connections}"
109+
except:
110+
pass
102111
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
103-
if hasattr(download, 'is_torrent'):
104-
msg += f"| P: {download.aria_download().connections} " \
105-
f"| S: {download.aria_download().num_seeders}"
106-
msg += f"\nGID: <code>{download.gid()}</code>"
112+
msg += f"\n<b>GID</b>: <code>{download.gid()}</code>"
107113
msg += "\n\n"
108114
return msg
109115

bot/helper/telegram_helper/message_utils.py

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from telegram import InlineKeyboardMarkup
22
from telegram.message import Message
33
from telegram.update import Update
4+
import psutil
45
import time
56
from bot import AUTO_DELETE_MESSAGE_DURATION, LOGGER, bot, \
6-
status_reply_dict, status_reply_dict_lock
7-
from bot.helper.ext_utils.bot_utils import get_readable_message
7+
status_reply_dict, status_reply_dict_lock, download_dict, download_dict_lock
8+
from bot.helper.ext_utils.bot_utils import get_readable_message, get_readable_file_size, MirrorStatus
89
from telegram.error import TimedOut, BadRequest
9-
from bot import bot
1010

1111

1212
def sendMessage(text: str, bot, update: Update):
@@ -68,6 +68,27 @@ def delete_all_messages():
6868

6969
def update_all_messages():
7070
msg = get_readable_message()
71+
msg += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
72+
f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
73+
f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
74+
with download_dict_lock:
75+
dlspeed_bytes = 0
76+
uldl_bytes = 0
77+
for download in list(download_dict.values()):
78+
speedy = download.speed()
79+
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
80+
if 'KiB/s' in speedy:
81+
dlspeed_bytes += float(speedy.split('K')[0]) * 1024
82+
elif 'MiB/s' in speedy:
83+
dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
84+
if download.status() == MirrorStatus.STATUS_UPLOADING:
85+
if 'KB/s' in speedy:
86+
uldl_bytes += float(speedy.split('K')[0]) * 1024
87+
elif 'MB/s' in speedy:
88+
uldl_bytes += float(speedy.split('M')[0]) * 1048576
89+
dlspeed = get_readable_file_size(dlspeed_bytes)
90+
ulspeed = get_readable_file_size(uldl_bytes)
91+
msg += f"\n<b>DL:</b>{dlspeed}ps 🔻| <b>UL:</b>{ulspeed}ps 🔺\n"
7192
with status_reply_dict_lock:
7293
for chat_id in list(status_reply_dict.keys()):
7394
if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text:
@@ -83,6 +104,27 @@ def update_all_messages():
83104

84105
def sendStatusMessage(msg, bot):
85106
progress = get_readable_message()
107+
progress += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
108+
f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
109+
f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
110+
with download_dict_lock:
111+
dlspeed_bytes = 0
112+
uldl_bytes = 0
113+
for download in list(download_dict.values()):
114+
speedy = download.speed()
115+
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
116+
if 'KiB/s' in speedy:
117+
dlspeed_bytes += float(speedy.split('K')[0]) * 1024
118+
elif 'MiB/s' in speedy:
119+
dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
120+
if download.status() == MirrorStatus.STATUS_UPLOADING:
121+
if 'KB/s' in speedy:
122+
uldl_bytes += float(speedy.split('K')[0]) * 1024
123+
elif 'MB/s' in speedy:
124+
uldl_bytes += float(speedy.split('M')[0]) * 1048576
125+
dlspeed = get_readable_file_size(dlspeed_bytes)
126+
ulspeed = get_readable_file_size(uldl_bytes)
127+
progress += f"\n<b>DL:</b>{dlspeed}ps 🔻| <b>UL:</b>{ulspeed}ps 🔺\n"
86128
with status_reply_dict_lock:
87129
if msg.message.chat.id in list(status_reply_dict.keys()):
88130
try:

0 commit comments

Comments
 (0)