Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dp0148755 committed Aug 15, 2022
1 parent e4a89b3 commit 0b977d7
Show file tree
Hide file tree
Showing 72 changed files with 4,782 additions and 2,282 deletions.
494 changes: 246 additions & 248 deletions bot/__init__.py

Large diffs are not rendered by default.

570 changes: 297 additions & 273 deletions bot/__main__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bot/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@

1 change: 0 additions & 1 deletion bot/helper/ext_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

94 changes: 74 additions & 20 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from bot import FINISHED_PROGRESS_STR, UN_FINISHED_PROGRESS_STR, download_dict, download_dict_lock, STATUS_LIMIT, botStartTime, DOWNLOAD_DIR, WEB_PINCODE, BASE_URL
from bot.helper.telegram_helper.button_build import ButtonMaker

import shutil
import psutil
from telegram.error import RetryAfter
from telegram.ext import CallbackQueryHandler
Expand Down Expand Up @@ -40,6 +39,7 @@ class MirrorStatus:
STATUS_CHECKING = "CheckingUp...📝"
STATUS_SEEDING = "Seeding...🌧"


class EngineStatus:
STATUS_ARIA = "Aria2c v1.35.0"
STATUS_GD = "Google Api v2.51.0"
Expand All @@ -51,7 +51,7 @@ class EngineStatus:
STATUS_SPLIT = "FFmpeg v2.9.1"
STATUS_ZIP = "p7zip v16.02"


SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']

PROGRESS_MAX_SIZE = 100 // 9
Expand All @@ -75,6 +75,7 @@ def __setInterval(self):
def cancel(self):
self.stopEvent.set()


def get_readable_file_size(size_in_bytes) -> str:
if size_in_bytes is None:
return '0B'
Expand All @@ -87,14 +88,16 @@ 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 list(download_dict.values()):
status = dl.status()
dl.status()
if dl.gid() == gid:
return dl
return None


def getAllDownload(req_status: str):
with download_dict_lock:
for dl in list(download_dict.values()):
Expand All @@ -103,6 +106,7 @@ def getAllDownload(req_status: str):
return dl
return None


def bt_selection_buttons(id_: str):
if len(id_) > 20:
gid = id_[:12]
Expand All @@ -121,10 +125,13 @@ def bt_selection_buttons(id_: str):
buttons.buildbutton("Select Files", f"{BASE_URL}/app/files/{id_}")
buttons.sbutton("Pincode", f"btsel pin {gid} {pincode}")
else:
buttons.buildbutton("Select Files", f"{BASE_URL}/app/files/{id_}?pin_code={pincode}")
buttons.buildbutton(
"Select Files",
f"{BASE_URL}/app/files/{id_}?pin_code={pincode}")
buttons.sbutton("Done Selecting", f"btsel done {gid} {id_}")
return InlineKeyboardMarkup(buttons.build_menu(2))


def get_progress_bar_string(status):
completed = status.processed_bytes() / 8
total = status.size_raw() / 8
Expand All @@ -139,33 +146,38 @@ def get_progress_bar_string(status):
p_str = f"「{p_str}」"
return p_str


def progress_bar(percentage):
p_used = '⬢'
p_total = '⬡'
if isinstance(percentage, str):
return 'NaN'
try:
percentage=int(percentage)
except:
percentage = int(percentage)
except BaseException:
percentage = 0
return ''.join(
p_used if i <= percentage // 10 else p_total for i in range(1, 11)
)


def get_readable_message():
with download_dict_lock:
msg = ""
if STATUS_LIMIT is not None:
tasks = len(download_dict)
global pages
pages = ceil(tasks/STATUS_LIMIT)
pages = ceil(tasks / STATUS_LIMIT)
if PAGE_NO > pages and pages != 0:
globals()['COUNT'] -= STATUS_LIMIT
globals()['PAGE_NO'] -= 1
for index, download in enumerate(list(download_dict.values())[COUNT:], start=1):
for index, download in enumerate(
list(download_dict.values())[COUNT:], start=1):
msg += f"<b>Name:</b> <code>{escape(str(download.name()))}</code>"
msg += f"\n<b>╭Status:</b> <i>{download.status()}</i>"
if download.status() not in [MirrorStatus.STATUS_SPLITTING, MirrorStatus.STATUS_SEEDING]:
if download.status() not in [
MirrorStatus.STATUS_SPLITTING,
MirrorStatus.STATUS_SEEDING]:
msg += f"\n<b>├</b>{get_progress_bar_string(download)} {download.progress()}"
if download.status() in [MirrorStatus.STATUS_DOWNLOADING,
MirrorStatus.STATUS_WAITING,
Expand All @@ -187,22 +199,22 @@ def get_readable_message():
try:
msg += f"\n<b>├Seeders:</b> {download.aria_download().num_seeders}" \
f" | <b>🧲 Peers:</b> {download.aria_download().connections}"
except:
except BaseException:
pass
try:
msg += f"\n<b>├Seeders:</b> {download.torrent_info().num_seeds}" \
f" | <b>🧲 Leechers:</b> {download.torrent_info().num_leechs}"
except:
except BaseException:
pass
if download.message.chat.type != 'private':
try:
chatid = str(download.message.chat.id)[4:]
msg += f'\n<b>├Source: </b><a href="https://t.me/c/{chatid}/{download.message.message_id}">{download.message.from_user.first_name}</a> | <b>Id :</b> <code>{download.message.from_user.id}</code>'
except:
except BaseException:
pass
else:
msg += f'\n<b>├User:</b> ️<code>{download.message.from_user.first_name}</code> | <b>Id:</b> <code>{download.message.from_user.id}</code>'

elif download.status() == MirrorStatus.STATUS_SEEDING:
msg += f"\n<b>├Size: </b>{download.size()}"
msg += f"\n<b>├Engine:</b> <code>qBittorrent v4.4.2</code>"
Expand Down Expand Up @@ -239,13 +251,13 @@ def get_readable_message():
elif 'MB/s' in spd:
upspeed_bytes += float(spd.split('M')[0]) * 1048576
bmsg += f"\n<b>🔻 DL:</b> {get_readable_file_size(dlspeed_bytes)}/s | <b>🔺 UL:</b> {get_readable_file_size(upspeed_bytes)}/s"

buttons = ButtonMaker()
# buttons.sbutton("Refresh", "status refresh")
buttons.sbutton("📈", str(THREE))
# buttons.sbutton("Close", "status close")
sbutton = InlineKeyboardMarkup(buttons.build_menu(3))

if STATUS_LIMIT is not None and tasks > STATUS_LIMIT:
msg += f"<b>Tasks:</b> {tasks}\n"
buttons = ButtonMaker()
Expand All @@ -258,6 +270,7 @@ def get_readable_message():
return msg + bmsg, button
return msg + bmsg, sbutton


def turn(data):
try:
with download_dict_lock:
Expand All @@ -277,9 +290,31 @@ def turn(data):
COUNT -= STATUS_LIMIT
PAGE_NO -= 1
return True
except:
except BaseException:
return False


def secondsToText():
secs = AUTO_DELETE_UPLOAD_MESSAGE_DURATION
days = secs // 86400
hours = (secs - days * 86400) // 3600
minutes = (secs - days * 86400 - hours * 3600) // 60
seconds = secs - days * 86400 - hours * 3600 - minutes * 60
return (
("{0} ᴅᴀʏ{1}, ".format(days, "s" if days != 1 else "") if days else "")
+ ("{0} ʜᴏᴜʀ{1} ".format(hours, "s" if hours != 1 else "") if hours else "")
+ (
"{0} ᴍɪɴᴜᴛᴇ{1} ".format(minutes, "s" if minutes != 1 else "")
if minutes
else ""
)
+ (
"{0} sᴇᴄᴏɴᴅ{1} ".format(seconds, "s" if seconds != 1 else "")
if seconds
else ""
)
)

def get_readable_time(seconds: int) -> str:
result = ''
(days, remainder) = divmod(seconds, 86400)
Expand All @@ -298,24 +333,30 @@ def get_readable_time(seconds: int) -> str:
result += f'{seconds}s'
return result


def is_url(url: str):
url = re_findall(URL_REGEX, url)
return bool(url)


def is_gdrive_link(url: str):
return "drive.google.com" in url


def is_gdtot_link(url: str):
url = re_match(r'https?://.+\.gdtot\.\S+', url)
return bool(url)


def is_appdrive_link(url: str):
url = re_match(r'https?://(?:\S*\.)?(?:appdrive|driveapp)\.in*/\S+', url)
return bool(url)


def is_mega_link(url: str):
return "mega.nz" in url or "mega.co.nz" in url


def get_mega_link_type(url: str):
if "folder" in url:
return "folder"
Expand All @@ -325,10 +366,12 @@ def get_mega_link_type(url: str):
return "folder"
return "file"


def is_magnet(url: str):
magnet = re_findall(MAGNET_REGEX, url)
return bool(magnet)


def new_thread(fn):
"""To use as decorator to make a function call threaded.
Needs import
Expand All @@ -341,25 +384,35 @@ def wrapper(*args, **kwargs):

return wrapper


def get_content_type(link: str) -> str:
try:
res = rhead(link, allow_redirects=True, timeout=5, headers = {'user-agent': 'Wget/1.12'})
res = rhead(
link,
allow_redirects=True,
timeout=5,
headers={
'user-agent': 'Wget/1.12'})
content_type = res.headers.get('content-type')
except:
except BaseException:
try:
res = urlopen(link, timeout=5)
info = res.info()
content_type = info.get_content_type()
except:
except BaseException:
content_type = None
return content_type


ONE, TWO, THREE = range(3)


def pop_up_stats(update, context):
query = update.callback_query
stats = bot_sys_stats()
query.answer(text=stats, show_alert=True)


def bot_sys_stats():
currentTime = get_readable_time(time() - botStartTime)
total, used, free, disk = disk_usage('/')
Expand All @@ -380,7 +433,8 @@ def bot_sys_stats():
T-DL: {recv} | T-UL: {sent}
Made with ❤️ by Dipesh
"""



dispatcher.add_handler(
CallbackQueryHandler(pop_up_stats, pattern="^" + str(THREE) + "$")
)
Loading

0 comments on commit 0b977d7

Please sign in to comment.