Skip to content

Commit

Permalink
🛃 More Bug Fixes & More Stable !
Browse files Browse the repository at this point in the history
> Fixed MediaInfo UI ( Added in Leech Files )
> More Error Handling on MediaInfo Generate, No Crash
> Fix Thread ( No Response ) issue in /exportsession ( Now Using, Several Multi Thread )
> Sync All Arg Parse Changes from Base MLTB !
> Added Cancel Button on Torrent Select ( Mr. M contributed)
> Fixed Index Issue & all Filename Showing 
> Fixed Multiple Bot Using Db for PM Users ( Used via Broadcast Module )
> Added all New Cmds in SET_COMMANDS & Help Msg Refreshed with all new short cmds.
( Only Bug Fixes, Report More to get it Fixed, 1 step ahead to Stability ) 

THANK YOU !! [ ⭐️ Star or 🍴 Fork Now (More Features Coming Soon ⚠️)]
  • Loading branch information
SilentDemonSD authored Jul 4, 2023
1 parent 40d9420 commit 34338a3
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 164 deletions.
3 changes: 1 addition & 2 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ def changetz(*args):
if len(EXTENSION_FILTER) > 0:
fx = EXTENSION_FILTER.split()
for x in fx:
if x.strip().startswith('.'):
x = x.lstrip('.')
x = x.lstrip('.')
GLOBAL_EXTENSION_FILTER.append(x.strip().lower())

IS_PREMIUM_USER = False
Expand Down
20 changes: 10 additions & 10 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ async def search_images():
➥ /{BotCommands.YtdlLeechCommand[0]} or /{BotCommands.YtdlLeechCommand[1]}: Download using Yt-Dlp(supported link) and upload to telegram.
<b>G-Drive commands:</b>
➥ /{BotCommands.CloneCommand}: Copy file/folder to Cloud Drive.
➥ /{BotCommands.CloneCommand[0]}: Copy file/folder to Cloud Drive.
➥ /{BotCommands.CountCommand} [drive_url]: Count file/folder of Google Drive.
➥ /{BotCommands.DeleteCommand} [drive_url]: Delete file/folder from Google Drive (Only Owner & Sudo).
➥ /{BotCommands.GDCleanCommand} [drive_id]: Delete all files from specific folder in Google Drive.
➥ /{BotCommands.GDCleanCommand[0]} or /{BotCommands.GDCleanCommand[1]} [drive_id]: Delete all files from specific folder in Google Drive.
<b>Cancel Tasks:</b>
➥ /{BotCommands.CancelMirror}: Cancel task by cancel_gid or reply.
Expand All @@ -237,20 +237,20 @@ async def search_images():
<b>Authentication:</b>
➥ /login: Login to Bot to Access Bot without Temp Pass System (Private)
➥ /{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Only Owner & Sudo).
➥ /{BotCommands.UnAuthorizeCommand}: Unauthorize a chat or a user to use the bot (Only Owner & Sudo).
➥ /{BotCommands.AuthorizeCommand[0]} or /{BotCommands.AuthorizeCommand[1]}: Authorize a chat or a user to use the bot (Only Owner & Sudo).
➥ /{BotCommands.UnAuthorizeCommand[0]} or /{BotCommands.UnAuthorizeCommand[1]}: Unauthorize a chat or a user to use the bot (Only Owner & Sudo).
➥ /{BotCommands.AddSudoCommand}: Add sudo user (Only Owner).
➥ /{BotCommands.RmSudoCommand}: Remove sudo users (Only Owner).
<b>Bot Stats:</b>
➥ /{BotCommands.BroadcastCommand[0]} or /{BotCommands.BroadcastCommand[1]} [reply_msg]: Broadcast to PM users who have started the bot anytime.
➥ /{BotCommands.StatusCommand[0]} or /{BotCommands.StatusCommand[1]}: Shows a status page of all active tasks.
➥ /{BotCommands.StatsCommand}: Show Server detailed stats.
➥ /{BotCommands.PingCommand}: Check how long it takes to Ping the Bot.
➥ /{BotCommands.StatsCommand[0]} or /{BotCommands.StatsCommand[1]}: Show Server detailed stats.
➥ /{BotCommands.PingCommand[0]} or /{BotCommands.PingCommand[1]}: Check how long it takes to Ping the Bot.
<b>Maintainance:</b>
➥ /{BotCommands.RestartCommand[0]}: Restart and Update the Bot (Only Owner & Sudo).
➥ /{BotCommands.RestartCommand[1]}: Restart and Update all Bots (Only Owner & Sudo).
➥ /{BotCommands.RestartCommand[0]} or /{BotCommands.RestartCommand[1]}: Restart and Update the Bot (Only Owner & Sudo).
➥ /{BotCommands.RestartCommand[2]}: Restart and Update all Bots (Only Owner & Sudo).
➥ /{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports (Only Owner & Sudo).
<b>Executors:</b>
Expand All @@ -261,10 +261,10 @@ async def search_images():
➥ /exportsession: Generate User StringSession of Same Pyro Version (Only Owner).
<b>Extras:</b>
➥ /{BotCommands.SpeedCommand}: Check Speed in VPS/Server.
➥ /{BotCommands.SpeedCommand[0]} or /{BotCommands.SpeedCommand[1]}: Check Speed in VPS/Server.
➥ /{BotCommands.AddImageCommand} [url/photo]: Add Images in Bot
➥ /{BotCommands.ImagesCommand}: Generate grid of Stored Images.
➥ /{BotCommands.MediaInfoCommand} [url/media]: Generate MediaInfo of Media or DL Urls
➥ /{BotCommands.MediaInfoCommand[0]} or /{BotCommands.MediaInfoCommand[1]} [url/media]: Generate MediaInfo of Media or DL Urls
<b>Movie/TV Shows/Drama Search:</b>
➥ /{BotCommands.IMDBCommand}: Search in IMDB.
Expand Down
81 changes: 51 additions & 30 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def bt_selection_buttons(id_):
buttons.ibutton("Pincode", f"btsel pin {gid} {pincode}")
else:
buttons.ubutton("Select Files", f"{BASE_URL}/app/files/{id_}?pin_code={pincode}")
buttons.ibutton("Cancel", f"btsel rm {gid} {id_}")
buttons.ibutton("Done Selecting", f"btsel done {gid} {id_}")
return buttons.build_menu(2)

Expand Down Expand Up @@ -275,7 +276,7 @@ def convert_speed_to_bytes_per_second(spd):
buttons.ibutton(BotTheme('NEXT'), "status nex")
button = buttons.build_menu(3)
msg += BotTheme('Cpu', cpu=cpu_percent())
msg += BotTheme('FREE', free=get_readable_file_size(disk_usage(config_dict['DOWNLOAD_DIR']).free), free_p=100-disk_usage(config_dict['DOWNLOAD_DIR']).percent)
msg += BotTheme('FREE', free=get_readable_file_size(disk_usage(config_dict['DOWNLOAD_DIR']).free), free_p=round(100-disk_usage(config_dict['DOWNLOAD_DIR']).percent, 1))
msg += BotTheme('Ram', ram=virtual_memory().percent)
msg += BotTheme('uptime', uptime=get_readable_time(time() - botStartTime))
msg += BotTheme('DL', DL=get_readable_file_size(dl_speed))
Expand Down Expand Up @@ -348,31 +349,40 @@ def get_mega_link_type(url):
def arg_parser(items, arg_base):
if not items:
return arg_base
bool_arg_set = {'-b', '-e', '-z', '-s', '-j', '-d'}
t = len(items)
i = 0
arg_start = -1

while i + 1 <= t:
part = items[i]
part = items[i].strip()
if part in arg_base:
if part in ['-s', '-j']:
if arg_start == -1:
arg_start = i
if i + 1 == t and part in bool_arg_set or part in ['-s', '-j']:
arg_base[part] = True
elif t == i + 1:
if part in ['-b', '-e', '-z', '-s', '-j', '-d']:
arg_base[part] = True
else:
sub_list = []
for j in range(i+1, t):
item = items[j]
for j in range(i + 1, t):
item = items[j].strip()
if item in arg_base:
if part in ['-b', '-e', '-z', '-s', '-j', '-d']:
if part in bool_arg_set and not sub_list:
arg_base[part] = True
break
sub_list.append(item)
sub_list.append(item.strip())
i += 1
if sub_list:
arg_base[part] = " ".join(sub_list)
i += 1
if items[0] not in arg_base:
arg_base['link'] = items[0]

link = []
if items[0].strip() not in arg_base:
if arg_start == -1:
link.extend(item.strip() for item in items)
else:
link.extend(items[r].strip() for r in range(arg_start))
if link:
arg_base['link'] = " ".join(link)
return arg_base


Expand Down Expand Up @@ -523,25 +533,36 @@ def extra_btns(buttons):

async def set_commands(client):
if config_dict['SET_COMMANDS']:
await client.set_bot_commands([
BotCommand(f'{BotCommands.MirrorCommand[0]}', f'or /{BotCommands.MirrorCommand[1]} Mirror'),
BotCommand(f'{BotCommands.LeechCommand[0]}', f'or /{BotCommands.LeechCommand[1]} Leech'),
BotCommand(f'{BotCommands.QbMirrorCommand[0]}', f'or /{BotCommands.QbMirrorCommand[1]} Mirror torrent using qBittorrent'),
BotCommand(f'{BotCommands.QbLeechCommand[0]}', f'or /{BotCommands.QbLeechCommand[1]} Leech torrent using qBittorrent'),
BotCommand(f'{BotCommands.YtdlCommand[0]}', f'or /{BotCommands.YtdlCommand[1]} Mirror yt-dlp supported link'),
BotCommand(f'{BotCommands.YtdlLeechCommand[0]}', f'or /{BotCommands.YtdlLeechCommand[1]} Leech through yt-dlp supported link'),
BotCommand(f'{BotCommands.CloneCommand[0]}', 'Copy file/folder to Drive'),
BotCommand(f'{BotCommands.CountCommand}', '[drive_url]: Count file/folder of Google Drive.'),
BotCommand(f'{BotCommands.StatusCommand[0]}', f'or /{BotCommands.StatusCommand[1]} Get mirror status message'),
BotCommand(f'{BotCommands.StatsCommand}', f'Check Bot & System stats'),
BotCommand(f'{BotCommands.BtSelectCommand}', 'Select files to download only torrents'),
BotCommand(f'{BotCommands.CancelMirror}', f'Cancel a Task'),
BotCommand(f'{BotCommands.CancelAllCommand[0]}', f'Cancel all tasks which added by you to in bots.'),
BotCommand(f'{BotCommands.ListCommand}', 'Search in Drive'),
BotCommand(f'{BotCommands.SearchCommand}', 'Search in Torrent'),
BotCommand(f'{BotCommands.UserSetCommand[0]}', 'Users settings'),
BotCommand(f'{BotCommands.HelpCommand}', 'Get detailed help'),
try:
await client.set_bot_commands([
BotCommand(BotCommands.MirrorCommand[0], f'or /{BotCommands.MirrorCommand[1]} Mirror [links/media/rclone_path]'),
BotCommand(BotCommands.LeechCommand[0], f'or /{BotCommands.LeechCommand[1]} Leech [links/media/rclone_path]'),
BotCommand(BotCommands.QbMirrorCommand[0], f'or /{BotCommands.QbMirrorCommand[1]} Mirror magnet/torrent using qBittorrent'),
BotCommand(BotCommands.QbLeechCommand[0], f'or /{BotCommands.QbLeechCommand[1]} Leech magnet/torrent using qBittorrent'),
BotCommand(BotCommands.YtdlCommand[0], f'or /{BotCommands.YtdlCommand[1]} Mirror yt-dlp supported links via bot'),
BotCommand(BotCommands.YtdlLeechCommand[0], f'or /{BotCommands.YtdlLeechCommand[1]} Leech yt-dlp supported links via bot'),
BotCommand(BotCommands.CloneCommand[0], f'or /{BotCommands.CloneCommand[1]} Copy file/folder to Drive (GDrive/RClone)'),
BotCommand(BotCommands.CountCommand, '[drive_url]: Count file/folder of Google Drive/RClone Drives'),
BotCommand(BotCommands.StatusCommand[0], f'or /{BotCommands.StatusCommand[1]} Get Bot All Status Stats Message'),
BotCommand(BotCommands.StatsCommand[0], f'or /{BotCommands.StatsCommand[1]}Check Bot & System stats'),
BotCommand(BotCommands.BtSelectCommand, 'Select files to download only torrents/magnet qbit/aria2c'),
BotCommand(BotCommands.CancelMirror, 'Cancel a Task of yours!'),
BotCommand(BotCommands.CancelAllCommand[0], f'Cancel all Tasks in whole Bots.'),
BotCommand(BotCommands.ListCommand, 'Search in Drive(s)'),
BotCommand(BotCommands.SearchCommand, 'Search in Torrent via qBit clients!'),
BotCommand(BotCommands.HelpCommand, 'Get detailed help about the WZML-X Bot'),
BotCommand(BotCommands.UserSetCommand[0], f"or /{BotCommands.UserSetCommand[1]} User's Personal Settings (Open in PM)"),
BotCommand(BotCommands.IMDBCommand, 'Search Movies/Series on IMDB.com and fetch details'),
BotCommand(BotCommands.AniListCommand, 'Search Animes on AniList.com and fetch details'),
BotCommand(BotCommands.MyDramaListCommand, 'Search Dramas on MyDramaList.com and fetch details'),
BotCommand(BotCommands.SpeedCommand[0], f'or /{BotCommands.SpeedCommand[1]} Check Server Up & Down Speed & Details'),
BotCommand(BotCommands.MediaInfoCommand[0], f'or /{BotCommands.MediaInfoCommand[1]} Generate Mediainfo for Replied Media or DL links'),
BotCommand(BotCommands.BotSetCommand[0], f"or /{BotCommands.BotSetCommand[1]} Bot's Personal Settings (Owner or Sudo Only)"),
BotCommand(BotCommands.RestartCommand[0], f'or /{BotCommands.RestartCommand[1]} Restart & Update the Bot (Owner or Sudo Only)'),
])
LOGGER.info('Bot Commands have been Set & Updated')
except Exception as err:
LOGGER.error(err)


def is_valid_token(url, token):
Expand Down
8 changes: 4 additions & 4 deletions bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ async def update_user_doc(self, user_id, key, path=''):
async def get_pm_uids(self):
if self.__err:
return
return [doc['_id'] async for doc in self.__db.pm_users.find({})]
return [doc['_id'] async for doc in self.__db.pm_users[bot_id].find({})]
self.__conn.close

async def update_pm_users(self, user_id):
if self.__err:
return
if not bool(await self.__db.pm_users.find_one({'_id': user_id})):
await self.__db.pm_users.insert_one({'_id': user_id})
if not bool(await self.__db.pm_users[bot_id].find_one({'_id': user_id})):
await self.__db.pm_users[bot_id].insert_one({'_id': user_id})
LOGGER.info(f'New PM User Added : {user_id}')
self.__conn.close

async def rm_pm_user(self, user_id):
if self.__err:
return
await self.__db.pm_users.delete_one({'_id': user_id})
await self.__db.pm_users[bot_id].delete_one({'_id': user_id})
self.__conn.close

async def rss_update_all(self):
Expand Down
20 changes: 8 additions & 12 deletions bot/helper/ext_utils/leech_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from asyncio.subprocess import PIPE

from bot import LOGGER, MAX_SPLIT_SIZE, config_dict, user_data
from bot.modules.mediainfo import parseinfo
from bot.helper.ext_utils.bot_utils import cmd_exec, sync_to_async, get_readable_file_size, get_readable_time
from bot.helper.ext_utils.fs_utils import ARCH_EXT, get_mime_type
from bot.helper.ext_utils.telegraph_helper import telegraph
Expand Down Expand Up @@ -217,7 +218,7 @@ async def format_filename(file_, user_id, dirpath=None, isMirror=False):
elif len(args) == 1:
__newFileName = re_sub(args[0], '', __newFileName)
file_ = __newFileName + ospath.splitext(file_)[1]
LOGGER.info(f"New Filename : {file_}")
LOGGER.info(f"New Remname : {file_}")

nfile_ = file_
if prefix:
Expand Down Expand Up @@ -246,7 +247,7 @@ async def format_filename(file_, user_id, dirpath=None, isMirror=False):


cap_mono = f"<{config_dict['CAP_FONT']}>{nfile_}</{config_dict['CAP_FONT']}>" if config_dict['CAP_FONT'] else nfile_
if lcaption and not isMirror:
if lcaption and dirpath and not isMirror:
lcaption = lcaption.replace('\|', '%%').replace('\s', ' ')
slit = lcaption.split("|")
up_path = ospath.join(dirpath, prefile_)
Expand All @@ -265,20 +266,15 @@ async def format_filename(file_, user_id, dirpath=None, isMirror=False):
elif len(args) == 1:
cap_mono = cap_mono.replace(args[0], '')
cap_mono = cap_mono.replace('%%', '|')

if isMirror:
return file_
return cap_mono, file_
return file_, cap_mono


async def get_mediainfo_link(up_path):
stdout, stderr, _ = await cmd_exec(ssplit(f'mediainfo "{up_path}"'))
tele_content = f"<h4>{ospath.basename(up_path)}</h4><br><br>"
stdout, __, _ = await cmd_exec(ssplit(f'mediainfo "{up_path}"'))
tc = f"📌 <h4>{ospath.basename(up_path)}</h4><br><br>"
if len(stdout) != 0:
tele_content += f"<br><br><pre>{stdout}</pre><br>"
if len(stderr) != 0:
tele_content += f"<br><br><pre>{stderr}</pre><br>"
link_id = (await telegraph.create_page(title="MediaInfo", content=tele_content))["path"]
tc += parseinfo(stdout)
link_id = (await telegraph.create_page(title="MediaInfo X", content=tc))["path"]
return f"https://graph.org/{link_id}"


Expand Down
11 changes: 8 additions & 3 deletions bot/helper/listeners/tasks_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from bot.helper.ext_utils.bot_utils import extra_btns, sync_to_async, get_readable_file_size, get_readable_time, is_mega_link, is_gdrive_link
from bot.helper.ext_utils.fs_utils import get_base_name, get_path_size, clean_download, clean_target, \
is_first_archive_split, is_archive, is_archive_split, join_files
from bot.helper.ext_utils.leech_utils import split_file
from bot.helper.ext_utils.leech_utils import split_file, format_filename
from bot.helper.ext_utils.exceptions import NotSupportedExtractionArchive
from bot.helper.ext_utils.task_manager import start_from_queued
from bot.helper.mirror_utils.status_utils.extract_status import ExtractStatus
Expand Down Expand Up @@ -123,7 +123,11 @@ async def onDownloadComplete(self):
await self.onUploadError('Downloaded! Starting other part of the Task...')
return
if name == "None" or self.isQbit or not await aiopath.exists(f"{self.dir}/{name}"):
files = await listdir(self.dir)
try:
files = await listdir(self.dir)
except Exception as e:
await self.onUploadError(str(e))
return
name = files[-1]
if name == "yt-dlp-thumb":
name = files[0]
Expand Down Expand Up @@ -358,6 +362,7 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc
if self.isSuperGroup and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DATABASE_URL:
await DbManger().rm_complete_task(self.message.link)
user_id = self.message.from_user.id
name, _ = await format_filename(name, user_id, isMirror=not self.isLeech)
user_dict = user_data.get(user_id, {})
msg = BotTheme('NAME', Name="Task has been Completed!"if config_dict['SAFE_MODE'] else escape(name))
msg += BotTheme('SIZE', Size=get_readable_file_size(size))
Expand Down Expand Up @@ -500,7 +505,7 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc
await start_from_queued()
return

# await clean_download(self.dir)
await clean_download(self.dir)
async with download_dict_lock:
if self.uid in download_dict.keys():
del download_dict[self.uid]
Expand Down
8 changes: 6 additions & 2 deletions bot/helper/mirror_utils/download_utils/rclone_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ async def add_rclone_download(rc_path, config_path, path, name, listener):
msg = f'Error: While getting rclone stat/size. Path: {remote}:{rc_path}. Stderr: {err[:4000]}'
await sendMessage(listener.message, msg)
return
rstat = loads(res1[0])
rsize = loads(res2[0])
try:
rstat = loads(res1[0])
rsize = loads(res2[0])
except Exception as err:
await sendMessage(listener.message, f'RcloneDownload JsonLoad: {err}')
return
if rstat['IsDir']:
if not name:
name = rc_path.rsplit('/', 1)[-1] if rc_path else remote
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_utils/download_utils/yt_dlp_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __onDownloadProgress(self, d):
elif d.get('total_bytes_estimate'):
self.__size = d['total_bytes_estimate']
self.__downloaded_bytes = d['downloaded_bytes']
self.__eta = d.get('eta', '-')
self.__eta = d.get('eta', '-') or '-'
try:
self.__progress = (self.__downloaded_bytes / self.__size) * 100
except:
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/mirror_utils/rclone_utils/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def download(self, remote, rc_path, config_path, path):
remote_type = remote_opts['type']

if remote_type == 'drive' and config_dict['USE_SERVICE_ACCOUNTS'] and config_path == 'rclone.conf' \
and await aiopath.isdir('accounts'):
and await aiopath.isdir('accounts') and not remote_opts.get('service_account_file'):
config_path = await self.__create_rc_sa(remote, remote_opts)
if config_path != 'rclone.conf':
sa_files = await listdir('accounts')
Expand Down Expand Up @@ -244,7 +244,7 @@ async def upload(self, path, size):
fremote = oremote
fconfig_path = oconfig_path
if remote_type == 'drive' and config_dict['USE_SERVICE_ACCOUNTS'] and fconfig_path == 'rclone.conf' \
and await aiopath.isdir('accounts'):
and await aiopath.isdir('accounts') and not remote_opts.get('service_account_file'):
fconfig_path = await self.__create_rc_sa(oremote, remote_opts)
if fconfig_path != 'rclone.conf':
sa_files = await listdir('accounts')
Expand Down Expand Up @@ -328,7 +328,7 @@ async def clone(self, config_path, src_remote, src_path, destination, rcflags, m
await self.__listener.onUploadError(error[:4000])
return None, None
else:
if dst_remote_opt == 'drive':
if dst_remote_type == 'drive':
link, destination = await self.__get_gdrive_link(config_path, dst_remote, dst_path, mime_type)
return (None, None) if self.__is_cancelled else (link, destination)
else:
Expand Down
Loading

0 comments on commit 34338a3

Please sign in to comment.