diff --git a/bot/__init__.py b/bot/__init__.py index 432a93787..24045f9d3 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -100,9 +100,9 @@ else: config_dict = {} -USER_TD_SA = environ.get('USER_TD_SA', '') -if len(USER_TD_SA) != 0: - USER_TD_SA = USER_TD_SA.lower() +GROUPS_EMAIL = environ.get('GROUPS_EMAIL', '') +if len(GROUPS_EMAIL) != 0: + GROUPS_EMAIL = GROUPS_EMAIL.lower() OWNER_ID = environ.get('OWNER_ID', '') if len(OWNER_ID) == 0: @@ -174,6 +174,8 @@ log_error(f"Failed making client from USER_SESSION_STRING : {e}") user = '' +MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000 + MEGA_EMAIL = environ.get('MEGA_EMAIL', '') MEGA_PASSWORD = environ.get('MEGA_PASSWORD', '') if len(MEGA_EMAIL) == 0 or len(MEGA_PASSWORD) == 0: @@ -197,14 +199,6 @@ if len(STREAMWISH_API) == 0: STREAMWISH_API = '' -MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000 - -LEECH_SPLIT_SIZE = environ.get('LEECH_SPLIT_SIZE', '') -if str(LEECH_SPLIT_SIZE) in ["4194304000", "2097152000"] or len(LEECH_SPLIT_SIZE) == 0 or int(LEECH_SPLIT_SIZE) > MAX_SPLIT_SIZE: - LEECH_SPLIT_SIZE = MAX_SPLIT_SIZE -else: - LEECH_SPLIT_SIZE = int(LEECH_SPLIT_SIZE) - BOT_MAX_TASKS = environ.get('BOT_MAX_TASKS', '') BOT_MAX_TASKS = int(BOT_MAX_TASKS) if BOT_MAX_TASKS.isdigit() else '' @@ -257,9 +251,6 @@ SHOW_MEDIAINFO = environ.get('SHOW_MEDIAINFO', '') SHOW_MEDIAINFO = SHOW_MEDIAINFO.lower() == 'true' -EQUAL_SPLITS = environ.get('EQUAL_SPLITS', '') -EQUAL_SPLITS = EQUAL_SPLITS.lower() == 'true' - MEDIA_GROUP = environ.get('MEDIA_GROUP', '') MEDIA_GROUP = MEDIA_GROUP.lower() == 'true' @@ -336,13 +327,6 @@ '[', '').replace(']', '').replace(",", "")).split() -IMG_SEARCH = environ.get('IMG_SEARCH', '') -IMG_SEARCH = (IMG_SEARCH.replace("'", '').replace('"', '').replace( - '[', '').replace(']', '').replace(",", "")).split() - -IMG_PAGE = environ.get('IMG_PAGE', '') -IMG_PAGE = 1 if not IMG_PAGE else int(IMG_PAGE) - SET_COMMANDS = environ.get('SET_COMMANDS', '') SET_COMMANDS = SET_COMMANDS.lower() == 'true' @@ -372,15 +356,11 @@ 'MIRROR_LOG_ID': MIRROR_LOG_ID, 'LEECH_DUMP_ID': LEECH_DUMP_ID, 'IMAGES': IMAGES, - 'IMG_SEARCH': IMG_SEARCH, - 'IMG_PAGE': IMG_PAGE, - 'EQUAL_SPLITS': EQUAL_SPLITS, 'EXTENSION_FILTER': EXTENSION_FILTER, 'GDRIVE_ID': GDRIVE_ID, 'INDEX_URL': INDEX_URL, 'JIODRIVE_TOKEN': JIODRIVE_TOKEN, 'LEECH_LOG_ID': LEECH_LOG_ID, - 'LEECH_SPLIT_SIZE': LEECH_SPLIT_SIZE, 'TOKEN_TIMEOUT': TOKEN_TIMEOUT, 'MEDIA_GROUP': MEDIA_GROUP, 'MEGA_EMAIL': MEGA_EMAIL, @@ -410,7 +390,7 @@ 'UPSTREAM_REPO': UPSTREAM_REPO, 'UPSTREAM_BRANCH': UPSTREAM_BRANCH, 'USER_SESSION_STRING': USER_SESSION_STRING, - 'USER_TD_SA': USER_TD_SA, + 'GROUPS_EMAIL': GROUPS_EMAIL, 'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS, 'WEB_PINCODE': WEB_PINCODE, 'YT_DLP_OPTIONS': YT_DLP_OPTIONS} diff --git a/bot/__main__.py b/bot/__main__.py index f89fa9c2b..86b854181 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -42,15 +42,14 @@ async def stats(_, message): cpuUsage = cpu_percent(interval=0.5) quote = Quote.print().split('―', 1)[0].strip().replace("“", "").replace("”", "") limit_mapping = { - 'Torrent': config_dict.get('TORRENT_LIMIT', '∞'), - 'Gdrive': config_dict.get('GDRIVE_LIMIT', '∞'), - 'Ytdlp': config_dict.get('YTDLP_LIMIT', '∞'), - 'Direct': config_dict.get('DIRECT_LIMIT', '∞'), - 'Leech': config_dict.get('LEECH_LIMIT', '∞'), - 'Clone': config_dict.get('CLONE_LIMIT', '∞'), - 'Mega': config_dict.get('MEGA_LIMIT', '∞'), - 'User tasks': config_dict.get('USER_MAX_TASKS', '∞'), - } + 'Torrent' : config_dict.get('TORRENT_LIMIT', '∞'), + 'Gdrive' : config_dict.get('GDRIVE_LIMIT', '∞'), + 'Ytdlp' : config_dict.get('YTDLP_LIMIT', '∞'), + 'Direct' : config_dict.get('DIRECT_LIMIT', '∞'), + 'Leech' : config_dict.get('LEECH_LIMIT', '∞'), + 'Clone' : config_dict.get('CLONE_LIMIT', '∞'), + 'Mega' : config_dict.get('MEGA_LIMIT', '∞'), + 'User task': config_dict.get('USER_MAX_TASKS', '∞')} system_info = f'{quote}\n\n'\ f'• Bot uptime : {currentTime}\n'\ f'• Sys uptime : {osUptime}\n'\ @@ -65,7 +64,7 @@ async def stats(_, message): for k, v in limit_mapping.items(): if v == '': v = '∞' - elif k != 'User tasks': + elif k != 'User task': v = f'{v}GB/Link' else: v = f'{v} Tasks/user' @@ -204,30 +203,6 @@ async def log(_, message): await deleteMessage(message) await five_minute_del(reply_message) -async def search_images(): - if not config_dict['IMG_SEARCH']: - return - try: - query_list = config_dict['IMG_SEARCH'] - total_pages = config_dict['IMG_PAGE'] - base_url = "https://www.wallpaperflare.com/search" - - for query in query_list: - query = query.strip().replace(" ", "+") - for page in range(1, total_pages + 1): - url = f"{base_url}?wallpaper={query}&width=1280&height=720&page={page}" - r = rget(url) - soup = BeautifulSoup(r.text, "html.parser") - images = soup.select('img[data-src^="https://c4.wallpaperflare.com/wallpaper"]') - for img in images: - img_url = img['data-src'] - if img_url not in config_dict['IMAGES']: - config_dict['IMAGES'].append(img_url) - if DATABASE_URL: - await DbManager().update_config({'IMAGES': config_dict['IMAGES']}) - except Exception as e: - LOGGER.error(f"An error occurred: {e}") - help_string = f''' NOTE: Try each command without any arguments to see more details. @@ -243,8 +218,7 @@ async def search_images(): /{BotCommands.UserSetCommand} [query]: User settings. /{BotCommands.BotSetCommand} [query]: Bot settings. /{BotCommands.BtSelectCommand}: Select files from torrents by gid or reply. -/{BotCommands.CancelMirror}: Cancels task by gid or reply. -/{BotCommands.CancelAllCommand} [query]: Cancels all [status] tasks. +/{BotCommands.CancelAllCommand} [query]: Cancel all [status] tasks. /{BotCommands.ListCommand} [query]: Searches in Google Drive(s). /{BotCommands.SearchCommand} [query]: Searches for torrents with API. /{BotCommands.StatusCommand}: Shows status of all downloads. @@ -272,27 +246,13 @@ async def bot_help(client, message): async def restart_notification(): - now = datetime.now(timezone('Asia/Dhaka')) - date = now.strftime('%d/%m/%y') - time = now.strftime('%I:%M:%S %p') - rmsg = f'Restarted Successfully!\n\nDate: {date}\nTime: {time}' if await aiopath.isfile(".restartmsg"): with open(".restartmsg") as f: chat_id, msg_id = map(int, f) else: chat_id, msg_id = 0, 0 - - async def send_incompelete_task_message(cid, msg): - try: - if msg.startswith(rmsg): - await bot.edit_message_text(chat_id=chat_id, message_id=msg_id, text=msg) - await aioremove(".restartmsg") - else: - await bot.send_message(chat_id=cid, text=msg, disable_web_page_preview=True, disable_notification=True) - except Exception as e: - LOGGER.error(e) - if await aiopath.isfile(".restartmsg"): + rmsg = 'Restarted Successfully!' try: await bot.edit_message_text(chat_id=chat_id, message_id=msg_id, text=rmsg) except: @@ -301,21 +261,15 @@ async def send_incompelete_task_message(cid, msg): async def main(): - await gather(start_cleanup(), torrent_search.initiate_search_tools(), restart_notification(), search_images(), set_commands(bot)) + await gather(start_cleanup(), torrent_search.initiate_search_tools(), restart_notification(), set_commands(bot)) await sync_to_async(start_aria2_listener, wait=False) - bot.add_handler(MessageHandler(start, filters=command( - BotCommands.StartCommand))) - bot.add_handler(MessageHandler(log, filters=command( - BotCommands.LogCommand) & CustomFilters.sudo)) - bot.add_handler(MessageHandler(restart, filters=command( - BotCommands.RestartCommand) & CustomFilters.sudo)) - bot.add_handler(MessageHandler(ping, filters=command( - BotCommands.PingCommand) & CustomFilters.authorized)) - bot.add_handler(MessageHandler(bot_help, filters=command( - BotCommands.HelpCommand) & CustomFilters.authorized)) - bot.add_handler(MessageHandler(stats, filters=command( - BotCommands.StatsCommand) & CustomFilters.authorized)) + bot.add_handler(MessageHandler(start, filters=command(BotCommands.StartCommand))) + bot.add_handler(MessageHandler(log, filters=command(BotCommands.LogCommand) & CustomFilters.sudo)) + bot.add_handler(MessageHandler(restart, filters=command(BotCommands.RestartCommand) & CustomFilters.sudo)) + bot.add_handler(MessageHandler(ping, filters=command(BotCommands.PingCommand) & CustomFilters.authorized)) + bot.add_handler(MessageHandler(bot_help, filters=command(BotCommands.HelpCommand) & CustomFilters.authorized)) + bot.add_handler(MessageHandler(stats, filters=command(BotCommands.StatsCommand) & CustomFilters.authorized)) bot.add_handler(CallbackQueryHandler(aeoncb, filters=regex(r'^aeon'))) LOGGER.info("Bot Started!") signal(SIGINT, exit_clean_up) diff --git a/bot/helper/ext_utils/bot_utils.py b/bot/helper/ext_utils/bot_utils.py index f8e63aa8c..d64a4e1dd 100644 --- a/bot/helper/ext_utils/bot_utils.py +++ b/bot/helper/ext_utils/bot_utils.py @@ -192,8 +192,7 @@ def get_readable_message(): else: msg += f"\nSize: {download.size()}" msg += f"\nElapsed: {get_readable_time(time() - download.message.date.timestamp())}" - msg += f"\nMode: {download.upload_details['mode']}" - msg += f"\n/{BotCommands.CancelMirror}_{download.gid()[:8]}\n\n" + msg += f"\n/stop_{download.gid()[:8]}\n\n" if len(msg) == 0: return None, None dl_speed = 0 @@ -284,7 +283,7 @@ def is_telegram_link(url): def is_share_link(url): domain = urlparse(url).hostname - return any(x in domain for x in ['appdirve', 'hubdrive', 'jiodrive']) + return any(x in domain for x in ['appdirve', 'hubdrive', 'jiodrive', 'filepress']) def is_mega_link(url): @@ -459,25 +458,22 @@ 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}', '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}', 'Check Bot & System stats'), - BotCommand(f'{BotCommands.CancelAllCommand[0]}', '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'), - BotCommand(f'{BotCommands.BotSetCommand}', 'Open Bot settings'), - BotCommand(f'{BotCommands.LogCommand}', 'View log'), - BotCommand(f'{BotCommands.RestartCommand[0]}', 'Restart bot'), - BotCommand(f'{BotCommands.MediaInfoCommand}', 'Get MediaInfo') - ] - ) + [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}', 'Copy file/folder to Drive'), + BotCommand(f'{BotCommands.StatusCommand[0]}', f'or /{BotCommands.StatusCommand[1]} Get mirror status message'), + BotCommand(f'{BotCommands.StatsCommand[0]}', 'Check Bot & System stats'), + BotCommand(f'{BotCommands.CancelAllCommand[0]}', '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'), + BotCommand(f'{BotCommands.BotSetCommand}', 'Open Bot settings'), + BotCommand(f'{BotCommands.LogCommand}', 'View log'), + BotCommand(f'{BotCommands.MediaInfoCommand}', 'Get MediaInfo'), + BotCommand(f'{BotCommands.CountCommand}', 'Count file/folder of Google Drive.'), + BotCommand(f'{BotCommands.RestartCommand[0]}', 'Restart bot')]) diff --git a/bot/helper/ext_utils/exceptions.py b/bot/helper/ext_utils/exceptions.py index 7bc2fa00a..9611ac512 100644 --- a/bot/helper/ext_utils/exceptions.py +++ b/bot/helper/ext_utils/exceptions.py @@ -3,15 +3,12 @@ class DirectDownloadLinkException(Exception): class NotSupportedExtractionArchive(Exception): - """The archive format use is trying to extract is not supported""" pass class RssShutdownException(Exception): - """This exception should be raised when shutdown is called to stop the montior""" pass class TgLinkException(Exception): - """No Access granted for this chat""" pass \ No newline at end of file diff --git a/bot/helper/ext_utils/leech_utils.py b/bot/helper/ext_utils/leech_utils.py index d886fab74..3441dedac 100644 --- a/bot/helper/ext_utils/leech_utils.py +++ b/bot/helper/ext_utils/leech_utils.py @@ -148,10 +148,8 @@ async def split_file(path, size, file_, dirpath, split_size, listener, start_tim await mkdir(dirpath) user_id = listener.message.from_user.id user_dict = user_data.get(user_id, {}) - leech_split_size = user_dict.get('split_size') or config_dict['LEECH_SPLIT_SIZE'] + leech_split_size = MAX_SPLIT_SIZE parts = -(-size // leech_split_size) - if (user_dict.get('equal_splits') or config_dict['EQUAL_SPLITS'] and 'equal_splits' not in user_dict) and not inLoop: - split_size = ((size + parts - 1) // parts) + 1000 if (await get_document_type(path))[0]: if multi_streams: multi_streams = await is_multi_streams(path) diff --git a/bot/helper/ext_utils/text_utils.py b/bot/helper/ext_utils/text_utils.py index ef8068df4..9ed9179da 100644 --- a/bot/helper/ext_utils/text_utils.py +++ b/bot/helper/ext_utils/text_utils.py @@ -13,8 +13,6 @@ 'YTDLP_LIMIT': 'To limit the size of ytdlp download. the default unit is GB. Int', 'PLAYLIST_LIMIT': 'To limit Maximum Playlist Number. Int', 'IMAGES': 'Add multiple telgraph(graph.org) image links that are seperated by spaces.', - 'IMG_SEARCH': 'Put Keyword to Download Images. Sperarte each name by , like anime, iron man, god of war', - 'IMG_PAGE': 'Set the page value for downloading a image. Each page have approx 70 images. Deafult is 1. Int', 'USER_MAX_TASKS': 'Limit the Maximum task for users of group at a time. use the Int', 'GDRIVE_LIMIT': 'To limit the size of Google Drive folder/file link for leech, Zip, Unzip. the default unit is GB. Int', 'USER_TASKS_LIMIT': 'The maximum limit on every users for all tasks. Int', @@ -25,13 +23,11 @@ 'DEFAULT_UPLOAD': 'Whether rc to upload to RCLONE_PATH or gd to upload to GDRIVE_ID. Default is gd.', 'LEECH_DUMP_ID': "Chat ID to where leeched files would be uploaded. Int. NOTE: Only available for superGroup/channel. Add -100 before channel/superGroup id. In short don't add bot id or your id!", 'MIRROR_LOG_ID': "Chat ID to where Mirror files would be Send. Int. NOTE: Only available for superGroup/channel. Add -100 before channel/superGroup id. In short don't add bot id or your id!. For Multiple id Separate them by space.", - 'EQUAL_SPLITS': 'Split files larger than LEECH_SPLIT_SIZE into equal parts size (Not working with zip cmd). Default is False.', 'EXTENSION_FILTER': "File extensions that won't upload/clone. Separate them by space.", 'GDRIVE_ID': 'This is the Folder/TeamDrive ID of the Google Drive OR root to which you want to upload all the mirrors using google-api-python-client.', 'INDEX_URL': 'Refer to https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index.', 'SHOW_MEDIAINFO': 'Add Button to Show MediaInfo in Leeched file. Bool', 'TOKEN_TIMEOUT': 'Token timeout for each group member in sec. Int', - 'LEECH_SPLIT_SIZE': 'Size of split in bytes. Default is 2GB. Default is 4GB if your account is premium.', 'MEDIA_GROUP': 'View Uploaded splitted file parts in media group. Default is False.', 'MEGA_EMAIL': 'E-Mail used to sign-in on mega.nz for using premium account. Str', 'MEGA_PASSWORD': 'Password for mega.nz account. Str', @@ -73,7 +69,7 @@ 'thumb': ['Custom Thumbnail to appear on the Leeched files uploaded by the bot', 'Send a photo to save it as custom thumbnail. Timeout: 60 sec'], 'yt_opt': ['YT-DLP Options is the Custom Quality for the extraction of videos from the yt-dlp supported sites.', 'Send YT-DLP Options. Timeout: 60 sec\nFormat: key:value|key:value|key:value.\nExample: format:bv*+mergeall[vcodec=none]|nocheckcertificate:True\nCheck all yt-dlp api options from this FILE or use this script to convert cli arguments to api options.'], 'split_size': ['Leech Splits Size is the size to split the Leeched File before uploading', f'Send Leech split size in bytes. IS_PREMIUM_USER: {IS_PREMIUM_USER}. Timeout: 60 sec'], - 'user_tds': [f'UserTD helps to upload files via Bot to your Custom Drive Destination through Global SA Mail.\n\nSA Mail: {SA if (SA := config_dict["USER_TD_SA"]) else "Not Specified"}','Send User TD details for use while Mirror/Clone.\nFormat: \nname drive_id/link index(optional)\n\nNOTE: \n1. Must add our sa mail in your drive with write permission\n2. Names can have spaces.\n3. Drive ID must be valid for acceptance.\n\nTimeout: 60 sec.'], + 'user_tds': [f'UserTD helps to upload files via Bot to your Custom Drive Destination through Global SA Mail.\n\nSA Mail: {SA if (SA := config_dict["GROUPS_EMAIL"]) else "Not Specified"}','Send User TD details for use while Mirror/Clone.\nFormat: \nname drive_id/link index(optional)\n\nNOTE: \n1. Must add our sa mail in your drive with write permission\n2. Names can have spaces.\n3. Drive ID must be valid for acceptance.\n\nTimeout: 60 sec.'], } nsfw_keywords = [ diff --git a/bot/helper/listeners/tasks_listener.py b/bot/helper/listeners/tasks_listener.py index 7b6d32848..0f398f6a0 100644 --- a/bot/helper/listeners/tasks_listener.py +++ b/bot/helper/listeners/tasks_listener.py @@ -60,7 +60,6 @@ def __init__(self, message, compress=False, extract=False, isQbit=False, isLeech self.linkslogmsg = None self.botpmmsg = None self.upload_details = {} - self.__setModeEng() self.drive_id = drive_id self.index_link = index_link self.leech_utils = leech_utils @@ -76,22 +75,9 @@ async def clean(self): except: pass - def __setModeEng(self): - mode = ( - 'leech' - if self.isLeech - else 'clone' - if self.isClone - else 'rclone' - if self.upPath != 'gd' - else 'mirror' - ) + (' as zip' if self.compress else ' as unzip' if self.extract else '') - self.upload_details['mode'] = mode - async def onDownloadStart(self): if config_dict['LEECH_LOG_ID']: msg = f'Task Started\n\n' - msg += f"• Mode: {self.upload_details['mode']}\n" msg += f'• Task by: {self.tag}\n' msg += f'• User ID: {self.message.from_user.id}' self.linkslogmsg = await sendCustomMsg(config_dict['LEECH_LOG_ID'], msg) @@ -175,8 +161,7 @@ async def onDownloadComplete(self): f_path = ospath.join(dirpath, file_) t_path = dirpath.replace( self.dir, self.newDir) if self.seed else dirpath - cmd = [ - "7z", "x", f"-p{pswd}", f_path, f"-o{t_path}", "-aot", "-xr!@PaxHeader"] + cmd = ["7z", "x", f"-p{pswd}", f_path, f"-o{t_path}", "-aot", "-xr!@PaxHeader"] if not pswd: del cmd[2] if self.suproc == 'cancelled' or self.suproc is not None and self.suproc.returncode == -9: @@ -186,8 +171,7 @@ async def onDownloadComplete(self): if code == -9: return elif code != 0: - LOGGER.error( - 'Unable to extract archive splits!') + LOGGER.error('Unable to extract archive splits!') if not self.seed and self.suproc is not None and self.suproc.returncode == 0: for file_ in files: if is_archive_split(file_) or is_archive(file_): @@ -200,8 +184,7 @@ async def onDownloadComplete(self): if self.seed: self.newDir = f"{self.dir}10000" up_path = up_path.replace(self.dir, self.newDir) - cmd = ["7z", "x", f"-p{pswd}", dl_path, - f"-o{up_path}", "-aot", "-xr!@PaxHeader"] + cmd = ["7z", "x", f"-p{pswd}", dl_path, f"-o{up_path}", "-aot", "-xr!@PaxHeader"] if not pswd: del cmd[2] if self.suproc == 'cancelled': @@ -239,7 +222,7 @@ async def onDownloadComplete(self): up_path = f"{dl_path}.zip" async with download_dict_lock: download_dict[self.uid] = ZipStatus(name, size, gid, self) - LEECH_SPLIT_SIZE = user_dict.get('split_size', False) or config_dict['LEECH_SPLIT_SIZE'] + LEECH_SPLIT_SIZE = MAX_SPLIT_SIZE cmd = ["7z", f"-v{LEECH_SPLIT_SIZE}b", "a", "-mx=0", f"-p{pswd}", up_path, dl_path] for ext in GLOBAL_EXTENSION_FILTER: @@ -273,8 +256,7 @@ async def onDownloadComplete(self): o_files = [] if not self.compress: checked = False - LEECH_SPLIT_SIZE = user_dict.get( - 'split_size', False) or config_dict['LEECH_SPLIT_SIZE'] + LEECH_SPLIT_SIZE = MAX for dirpath, _, files in await sync_to_async(walk, up_dir, topdown=False): for file_ in files: f_path = ospath.join(dirpath, file_) @@ -283,8 +265,7 @@ async def onDownloadComplete(self): if not checked: checked = True async with download_dict_lock: - download_dict[self.uid] = SplitStatus( - up_name, size, gid, self) + download_dict[self.uid] = SplitStatus(up_name, size, gid, self) LOGGER.info(f"Splitting: {up_name}") res = await split_file(f_path, f_size, file_, dirpath, LEECH_SPLIT_SIZE, self) if not res: @@ -365,14 +346,14 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc msg = f'{escape(name)}\n\n' msg += f'• Size: {get_readable_file_size(size)}\n' msg += f'• Elapsed: {get_readable_time(time() - self.message.date.timestamp())}\n' - msg += f'• Mode: {self.upload_details["mode"]}\n' LOGGER.info(f'Task Done: {name}') buttons = ButtonMaker() if self.isLeech: - msg += f'• Total files: {folders}\n' + if folders > 1: + msg += f'• Total files: {folders}\n' if mime_type != 0: msg += f'• Corrupted files: {mime_type}\n' - msg += f'• Leeched by: {self.tag}\n' + msg += f'• Uploaded by: {self.tag}\n' msg += f'• User ID: {self.message.from_user.id}\n\n' if not files: if self.isPrivate: @@ -415,10 +396,8 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc await start_from_queued() return else: - msg += f'• Type: {mime_type}\n' if mime_type == "Folder": - msg += f'• SubFolders: {folders}\n' - msg += f'• Files: {files}\n' + msg += f'• Total files: {files}\n' if link or rclonePath and config_dict['RCLONE_SERVE_URL']: if link: buttons.ubutton('Cloud link', link) diff --git a/bot/helper/mirror_utils/download_utils/direct_link_generator.py b/bot/helper/mirror_utils/download_utils/direct_link_generator.py index f97b9129d..4218c0ae5 100644 --- a/bot/helper/mirror_utils/download_utils/direct_link_generator.py +++ b/bot/helper/mirror_utils/download_utils/direct_link_generator.py @@ -90,7 +90,8 @@ 'kitabmarkaz.xyz', 'wishfast.top'], 'linkBox': ['linkbox.to', - 'lbx.to'] + 'lbx.to'], + 'filepress': ['filepress'] } def direct_link_generator(link): @@ -180,6 +181,24 @@ def hxfile(url): raise DirectDownloadLinkException("ERROR: Direct download link not found") +def filepress(url): + with create_scraper() as session: + try: + url = session.get(url).url + raw = urlparse(url) + json_data = { + 'id': raw.path.split('/')[-1], + 'method': 'publicDownlaod', + } + api = f'{raw.scheme}://{raw.hostname}/api/file/downlaod/' + res = session.post(api, headers={'Referer': f'{raw.scheme}://{raw.hostname}'}, json=json_data).json() + except Exception as e: + raise DirectDownloadLinkException(f'ERROR: {e.__class__.__name__}') + if 'data' not in res: + raise DirectDownloadLinkException(f'ERROR: {res["statusText"]}') + return f'https://drive.google.com/uc?id={res["data"]}&export=download' + + def onedrive(link): with create_scraper() as session: try: diff --git a/bot/helper/mirror_utils/gdrive_utils/clone.py b/bot/helper/mirror_utils/gdrive_utils/clone.py index 3c8cd8761..24b62f2ef 100644 --- a/bot/helper/mirror_utils/gdrive_utils/clone.py +++ b/bot/helper/mirror_utils/gdrive_utils/clone.py @@ -63,8 +63,7 @@ async def rcloneNode(client, message, link, dst_path, rcf, tag): remote, src_path = link.split(':', 1) src_path = src_path.strip('/') - cmd = ['zcl', 'lsjson', '--fast-list', '--stat', - '--no-modtime', '--config', config_path, f'{remote}:{src_path}'] + cmd = ['zcl', 'lsjson', '--fast-list', '--stat', '--no-modtime', '--config', config_path, f'{remote}:{src_path}'] res = await cmd_exec(cmd) if res[2] != 0: if res[2] != -9: @@ -176,27 +175,20 @@ async def gdcloneNode(message, link, listen_up): @new_task async def clone(client, message): input_list = message.text.split(' ') - - arg_base = {'link': '', - '-i': 0, - '-up': '', '-upload': '', - '-rcf': '', - '-id': '', - '-index': '', - } - - args = arg_parser(input_list[1:], arg_base) - - try: - multi = int(args['-i']) - except: - multi = 0 - - dst_path = args['-up'] or args['-upload'] + arg_base = {'link' : '', + '-i' : '0', + '-up' : '', + '-rcf' : '', + '-id' : '', + '-index' : ''} + args = arg_parser(input_list[1:], arg_base) + i = args['-i'] + dst_path = args['-up'] rcf = args['-rcf'] link = args['link'] drive_id = args['-id'] index_link = args['-index'] + multi = int(i) if i.isdigit() else 0 if username := message.from_user.username: tag = f"@{username}" diff --git a/bot/helper/mirror_utils/gdrive_utils/count.py b/bot/helper/mirror_utils/gdrive_utils/count.py index d9acd9c4e..c08b1eb67 100644 --- a/bot/helper/mirror_utils/gdrive_utils/count.py +++ b/bot/helper/mirror_utils/gdrive_utils/count.py @@ -31,7 +31,6 @@ async def countNode(_, message): await deleteMessage(msg) msg = f'{name}\n\n' msg += f'• Size: {get_readable_file_size(size)}\n' - msg += f'• Type: {mime_type}\n' if mime_type == 'Folder': msg += f'• SubFolders: {folders}\n' msg += f'• Files: {files}\n' diff --git a/bot/helper/mirror_utils/upload_utils/gdriveTools.py b/bot/helper/mirror_utils/upload_utils/gdriveTools.py index e6ffa71a4..0214333a8 100644 --- a/bot/helper/mirror_utils/upload_utils/gdriveTools.py +++ b/bot/helper/mirror_utils/upload_utils/gdriveTools.py @@ -186,8 +186,7 @@ def upload(self, file_name, size, gdrive_id): if item_path.lower().endswith(tuple(GLOBAL_EXTENSION_FILTER)): raise Exception('This file extension is excluded by extension filter!') mime_type = get_mime_type(item_path) - link = self.__upload_file( - item_path, file_name, mime_type, gdrive_id, is_dir=False) + link = self.__upload_file(item_path, file_name, mime_type, gdrive_id, is_dir=False) if self.__is_cancelled: return if link is None: @@ -206,8 +205,7 @@ def upload(self, file_name, size, gdrive_id): LOGGER.info(f"Uploaded To G-Drive: {file_name}") except Exception as err: if isinstance(err, RetryError): - LOGGER.info( - f"Total Attempts: {err.last_attempt.attempt_number}") + LOGGER.info(f"Total Attempts: {err.last_attempt.attempt_number}") err = err.last_attempt.exception() err = str(err).replace('>', '').replace('<', '') async_to_sync(self.__listener.onUploadError, err) @@ -222,8 +220,7 @@ def upload(self, file_name, size, gdrive_id): return elif self.__is_errored: return - async_to_sync(self.__listener.onUploadComplete, link, size, self.__total_files, - self.__total_folders, mime_type, file_name) + async_to_sync(self.__listener.onUploadComplete, link, size, self.__total_files, self.__total_folders, mime_type, file_name) def __upload_dir(self, input_directory, dest_id): list_dirs = listdir(input_directory) @@ -239,8 +236,7 @@ def __upload_dir(self, input_directory, dest_id): elif not item.lower().endswith(tuple(GLOBAL_EXTENSION_FILTER)): mime_type = get_mime_type(current_file_name) file_name = current_file_name.split("/")[-1] - self.__upload_file(current_file_name, - file_name, mime_type, dest_id) + self.__upload_file(current_file_name, file_name, mime_type, dest_id) self.__total_files += 1 new_id = dest_id else: @@ -250,8 +246,7 @@ def __upload_dir(self, input_directory, dest_id): break return new_id - @retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(3), - retry=retry_if_exception_type(Exception)) + @retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(3), retry=retry_if_exception_type(Exception)) def __create_directory(self, directory_name, dest_id): directory_name, _ = async_to_sync(format_filename, directory_name, self.__user_id, isMirror=True) file_metadata = { @@ -267,8 +262,7 @@ def __create_directory(self, directory_name, dest_id): LOGGER.info(f'Created G-Drive Folder:\nName: {file.get("name")}\nID: {file_id}') return file_id - @retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(3), - retry=(retry_if_exception_type(Exception))) + @retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(3), retry=(retry_if_exception_type(Exception))) def __upload_file(self, file_path, file_name, mime_type, dest_id, is_dir=True): file_name, _ = async_to_sync(format_filename, file_name, self.__user_id, isMirror=True) file_metadata = { diff --git a/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py b/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py index 74a9bd6de..f2fd5e56d 100644 --- a/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py +++ b/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py @@ -34,7 +34,6 @@ def __init__(self, name=None, path=None, listener=None): self.__start_time = time() self.__total_files = 0 self.__is_cancelled = False - self.__thumb = f"Thumbnails/{listener.message.from_user.id}.jpg" self.__sent_msg = None self.__has_buttons = False self.__msgs_dict = {} @@ -53,6 +52,7 @@ def __init__(self, name=None, path=None, listener=None): self.__user_id = listener.message.from_user.id self.__leechmsg = {} self.__leech_utils = self.__listener.leech_utils + self.__thumb = f"Thumbnails/{listener.message.from_user.id}.jpg" async def get_custom_thumb(self, thumb): if is_telegram_link(thumb): diff --git a/bot/helper/telegram_helper/bot_commands.py b/bot/helper/telegram_helper/bot_commands.py index 1d01e6317..a028d8686 100644 --- a/bot/helper/telegram_helper/bot_commands.py +++ b/bot/helper/telegram_helper/bot_commands.py @@ -12,8 +12,7 @@ def __init__(self): self.CloneCommand = f'clone{CMD_SUFFIX}' self.CountCommand = f'count{CMD_SUFFIX}' self.DeleteCommand = f'del{CMD_SUFFIX}' - self.CancelMirror = f'cancel{CMD_SUFFIX}' - self.CancelAllCommand = [f'cancelall{CMD_SUFFIX}', 'cancellallbot'] + self.CancelAllCommand = [f'stopall{CMD_SUFFIX}', 'stopallbot'] self.ListCommand = f'list{CMD_SUFFIX}' self.SearchCommand = f'search{CMD_SUFFIX}' self.StatusCommand = [f'status{CMD_SUFFIX}', 'statusall'] @@ -24,7 +23,7 @@ def __init__(self): self.RmSudoCommand = f'rmsudo{CMD_SUFFIX}' self.PingCommand = [f'ping{CMD_SUFFIX}', 'pingall'] self.RestartCommand = [f'restart{CMD_SUFFIX}', 'restartall'] - self.StatsCommand = f'stats{CMD_SUFFIX}' + self.StatsCommand = [f'stats{CMD_SUFFIX}', 'statsall'] self.HelpCommand = f'help{CMD_SUFFIX}' self.LogCommand = f'log{CMD_SUFFIX}' self.ShellCommand = f'shell{CMD_SUFFIX}' diff --git a/bot/modules/bot_settings.py b/bot/modules/bot_settings.py index e1157caa2..eaa746f9e 100644 --- a/bot/modules/bot_settings.py +++ b/bot/modules/bot_settings.py @@ -30,19 +30,16 @@ STATE = 'view' handler_dict = {} default_values = {'DEFAULT_UPLOAD': 'gd', - 'LEECH_SPLIT_SIZE': MAX_SPLIT_SIZE, 'RSS_DELAY': 900, 'SEARCH_LIMIT': 0, 'UPSTREAM_BRANCH': 'main', - 'IMG_PAGE': 1, 'TORRENT_TIMEOUT': 3000} bool_vars = ['AS_DOCUMENT', 'STOP_DUPLICATE', 'SET_COMMANDS', 'SHOW_MEDIAINFO', 'USE_SERVICE_ACCOUNTS', - 'WEB_PINCODE', - 'EQUAL_SPLITS',] + 'WEB_PINCODE'] async def load_config(): @@ -67,9 +64,9 @@ async def load_config(): OWNER_ID = environ.get('OWNER_ID', '') OWNER_ID = config_dict['OWNER_ID'] if len(OWNER_ID) == 0 else int(OWNER_ID) - USER_TD_SA = environ.get('USER_TD_SA', '') - if len(USER_TD_SA) != 0: - USER_TD_SA = USER_TD_SA.lower() + GROUPS_EMAIL = environ.get('GROUPS_EMAIL', '') + if len(GROUPS_EMAIL) != 0: + GROUPS_EMAIL = GROUPS_EMAIL.lower() DATABASE_URL = environ.get('DATABASE_URL', '') if len(DATABASE_URL) == 0: @@ -138,14 +135,6 @@ async def load_config(): LEECH_LOG_ID = environ.get('LEECH_LOG_ID', '') LEECH_LOG_ID = '' if len(LEECH_LOG_ID) == 0 else int(LEECH_LOG_ID) - MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000 - - LEECH_SPLIT_SIZE = environ.get('LEECH_SPLIT_SIZE', '') - if len(LEECH_SPLIT_SIZE) == 0 or int(LEECH_SPLIT_SIZE) > MAX_SPLIT_SIZE: - LEECH_SPLIT_SIZE = MAX_SPLIT_SIZE - else: - LEECH_SPLIT_SIZE = int(LEECH_SPLIT_SIZE) - if len(download_dict) != 0: async with status_reply_dict_lock: if Interval: @@ -228,9 +217,6 @@ async def load_config(): SHOW_MEDIAINFO = environ.get('SHOW_MEDIAINFO', '') SHOW_MEDIAINFO = SHOW_MEDIAINFO.lower() == 'true' - EQUAL_SPLITS = environ.get('EQUAL_SPLITS', '') - EQUAL_SPLITS = EQUAL_SPLITS.lower() == 'true' - MEDIA_GROUP = environ.get('MEDIA_GROUP', '') MEDIA_GROUP = MEDIA_GROUP.lower() == 'true' @@ -304,13 +290,6 @@ async def load_config(): PLAYLIST_LIMIT = environ.get('PLAYLIST_LIMIT', '') PLAYLIST_LIMIT = '' if len(PLAYLIST_LIMIT) == 0 else int(PLAYLIST_LIMIT) - IMG_SEARCH = environ.get('IMG_SEARCH', '') - IMG_SEARCH = (IMG_SEARCH.replace("'", '').replace('"', '').replace( - '[', '').replace(']', '').replace(",", "")).split() - - IMG_PAGE = environ.get('IMG_PAGE', '') - IMG_PAGE = 1 if not IMG_PAGE else int(IMG_PAGE) - IMAGES = environ.get('IMAGES', '') IMAGES = (IMAGES.replace("'", '').replace('"', '').replace( '[', '').replace(']', '').replace(",", "")).split() @@ -378,15 +357,11 @@ async def load_config(): 'MIRROR_LOG_ID': MIRROR_LOG_ID, 'LEECH_DUMP_ID': LEECH_DUMP_ID, 'IMAGES': IMAGES, - 'IMG_SEARCH': IMG_SEARCH, - 'IMG_PAGE': IMG_PAGE, - 'EQUAL_SPLITS': EQUAL_SPLITS, 'EXTENSION_FILTER': EXTENSION_FILTER, 'GDRIVE_ID': GDRIVE_ID, 'INDEX_URL': INDEX_URL, 'JIODRIVE_TOKEN': JIODRIVE_TOKEN, 'LEECH_LOG_ID': LEECH_LOG_ID, - 'LEECH_SPLIT_SIZE': LEECH_SPLIT_SIZE, 'TOKEN_TIMEOUT': TOKEN_TIMEOUT, 'MEDIA_GROUP': MEDIA_GROUP, 'MEGA_EMAIL': MEGA_EMAIL, @@ -416,7 +391,7 @@ async def load_config(): 'UPSTREAM_REPO': UPSTREAM_REPO, 'UPSTREAM_BRANCH': UPSTREAM_BRANCH, 'USER_SESSION_STRING': USER_SESSION_STRING, - 'USER_TD_SA': USER_TD_SA, + 'GROUPS_EMAIL': GROUPS_EMAIL, 'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS, 'WEB_PINCODE': WEB_PINCODE, 'YT_DLP_OPTIONS': YT_DLP_OPTIONS}) @@ -446,18 +421,14 @@ async def get_buttons(key=None, edit_type=None, edit_mode=None, mess=None): elif key == 'private': buttons.ibutton('Back', "botset back") buttons.ibutton('Close', "botset close") - msg = '''Send private file: config.env, token.pickle, accounts.zip, list_drives.txt, cookies.txt, terabox.txt, .netrc or any other file! -To delete private file send only the file name as text message. -Note: Changing .netrc will not take effect for aria2c until restart. -Timeout: 60 sec''' + msg = 'Send private file: config.env, token.pickle, accounts.zip, list_drives.txt, cookies.txt, terabox.txt, .netrc or any other file!\nTo delete private file send only the file name as text message. \nNote: Changing .netrc will not take effect for aria2c until restart.\nTimeout: 60 sec' elif edit_type == 'editvar': msg = f'Variable: {key}\n\n' msg += f'Description: {bset_display_dict.get(key, "No Description Provided")}\n\n' if mess.chat.type == ChatType.PRIVATE: msg += f'Value: {config_dict.get(key, "None")}\n\n' else: - buttons.ibutton('View Var Value', - f"botset showvar {key}", position="header") + buttons.ibutton('View Var Value', f"botset showvar {key}", position="header") buttons.ibutton('Back', "botset back var", position="footer") if key not in bool_vars: if not edit_mode: @@ -467,8 +438,12 @@ async def get_buttons(key=None, edit_type=None, edit_mode=None, mess=None): if key not in ['TELEGRAM_HASH', 'TELEGRAM_API', 'OWNER_ID', 'BOT_TOKEN'] and key not in bool_vars: buttons.ibutton('Reset', f"botset resetvar {key}") buttons.ibutton('Close', "botset close", position="footer") - if edit_mode and key in ['SUDO_USERS', 'CMD_SUFFIX', 'OWNER_ID', 'USER_SESSION_STRING', 'TELEGRAM_HASH', - 'TELEGRAM_API', 'AUTHORIZED_CHATS', 'DATABASE_URL', 'BOT_TOKEN']: + if edit_mode and key in ['SUDO_USERS', + 'CMD_SUFFIX', + 'OWNER_ID', + 'USER_SESSION_STRING', 'TELEGRAM_HASH', + 'TELEGRAM_API', 'AUTHORIZED_CHATS', 'DATABASE_URL', + 'BOT_TOKEN']: msg += 'Note: Restart required for this edit to take effect!\n\n' if edit_mode and key not in bool_vars: msg += 'Send a valid value for the above Var. Timeout: 60 sec' @@ -503,8 +478,6 @@ async def edit_variable(_, message, pre_message, key): except Exception as e: LOGGER.error(e) aria2_options['bt-stop-timeout'] = f'{value}' - elif key == 'LEECH_SPLIT_SIZE': - value = min(int(value), MAX_SPLIT_SIZE) elif key == 'EXTENSION_FILTER': fx = value.split() GLOBAL_EXTENSION_FILTER.clear() @@ -737,7 +710,5 @@ async def bot_settings(_, message): await sendMessage(message, msg, button) -bot.add_handler(MessageHandler(bot_settings, filters=command( - BotCommands.BotSetCommand) & CustomFilters.sudo)) -bot.add_handler(CallbackQueryHandler(edit_bot_settings, - filters=regex("^botset") & CustomFilters.sudo)) +bot.add_handler(MessageHandler(bot_settings, filters=command(BotCommands.BotSetCommand) & CustomFilters.sudo)) +bot.add_handler(CallbackQueryHandler(edit_bot_settings, filters=regex("^botset") & CustomFilters.sudo)) diff --git a/bot/modules/cancel_mirror.py b/bot/modules/cancel_mirror.py index ac38712f9..06ae47c64 100644 --- a/bot/modules/cancel_mirror.py +++ b/bot/modules/cancel_mirror.py @@ -21,26 +21,19 @@ async def cancel_mirror(_, message): gid = cmd_data[0] dl = await getDownloadByGid(gid) if dl is None: - x = await sendMessage(message, f"GID: {gid} Not Found.") - await one_minute_del(x) + await deleteMessage(message) return elif reply_to_id := message.reply_to_message_id: async with download_dict_lock: dl = download_dict.get(reply_to_id, None) if dl is None: - x = await sendMessage(message, "This is not an active task!") - await one_minute_del(x) + await deleteMessage(message) return elif len(msg) == 1: - msg = "Reply to an active Command message which was used to start the download" \ - f" or send /{BotCommands.CancelMirror}_GID to cancel it!" - x = await sendMessage(message, msg) - await one_minute_del(x) + await deleteMessage(message) return - if OWNER_ID != user_id and dl.message.from_user.id != user_id and \ - (user_id not in user_data or not user_data[user_id].get('is_sudo')): - x = await sendMessage(message, "This task is not for you!") - await one_minute_del(x) + if OWNER_ID != user_id and dl.message.from_user.id != user_id and (user_id not in user_data or not user_data[user_id].get('is_sudo')): + await deleteMessage(message) return obj = dl.download() await obj.cancel_download() @@ -96,8 +89,6 @@ async def cancel_all_update(_, query): await sendMessage(reply_to, f"No matching tasks for {data[1]}!") -bot.add_handler(MessageHandler(cancel_mirror, filters=regex( - f"^/{BotCommands.CancelMirror}(_\w+)?(?!all)") & CustomFilters.authorized)) -bot.add_handler(MessageHandler(cancell_all_buttons, filters=command( - BotCommands.CancelAllCommand) & CustomFilters.sudo)) +bot.add_handler(MessageHandler(cancel_mirror, filters=regex(f"^/stop(_\w+)?(?!all)") & CustomFilters.authorized)) +bot.add_handler(MessageHandler(cancell_all_buttons, filters=command(BotCommands.CancelAllCommand) & CustomFilters.sudo)) bot.add_handler(CallbackQueryHandler(cancel_all_update, filters=regex(r"^canall"))) diff --git a/bot/modules/images.py b/bot/modules/images.py index e31695334..e7589d670 100644 --- a/bot/modules/images.py +++ b/bot/modules/images.py @@ -63,7 +63,7 @@ async def pictures(_, message): buttons.ibutton("Close", f"images {user_id} close") buttons.ibutton("Remove All", f"images {user_id} removall", 'footer') await deleteMessage(to_edit) - await sendMessage(message, f'🌄 Image No. : 1 / {len(config_dict["IMAGES"])}', buttons.build_menu(2), config_dict['IMAGES'][0]) + await sendMessage(message, f'Image No. : 1 / {len(config_dict["IMAGES"])}', buttons.build_menu(2), config_dict['IMAGES'][0]) @new_task @@ -78,7 +78,7 @@ async def pics_callback(_, query): await query.answer() ind = handleIndex(int(data[3]), config_dict['IMAGES']) no = len(config_dict['IMAGES']) - abs(ind+1) if ind < 0 else ind + 1 - pic_info = f'🌄 Image No. : {no} / {len(config_dict["IMAGES"])}' + pic_info = f'Image No. : {no} / {len(config_dict["IMAGES"])}' buttons = ButtonMaker() buttons.ibutton("<<", f"images {data[1]} turn {ind-1}") buttons.ibutton(">>", f"images {data[1]} turn {ind+1}") @@ -97,7 +97,7 @@ async def pics_callback(_, query): return ind = int(data[3])+1 ind = len(config_dict['IMAGES']) - abs(ind) if ind < 0 else ind - pic_info = f'🌄 Image No. : {ind+1} / {len(config_dict["IMAGES"])}' + pic_info = f'Image No. : {ind+1} / {len(config_dict["IMAGES"])}' buttons = ButtonMaker() buttons.ibutton("<<", f"images {data[1]} turn {ind-1}") buttons.ibutton(">>", f"images {data[1]} turn {ind+1}") diff --git a/bot/modules/users_settings.py b/bot/modules/users_settings.py index a5b6bfbd0..dac05b2f4 100644 --- a/bot/modules/users_settings.py +++ b/bot/modules/users_settings.py @@ -44,7 +44,7 @@ async def get_user_settings(from_user, key=None, edit_type=None, edit_mode=None) buttons.ibutton("Universal", f"userset {user_id} universal") buttons.ibutton("Mirror", f"userset {user_id} mirror") buttons.ibutton("Leech", f"userset {user_id} leech") - if user_dict and any(key in user_dict for key in ['prefix', 'suffix', 'remname', 'ldump', 'yt_opt', 'media_group', 'equal_splits', 'split_size', 'rclone', 'thumb', 'as_doc']): + if user_dict and any(key in user_dict for key in ['prefix', 'suffix', 'remname', 'ldump', 'yt_opt', 'media_group', 'split_size', 'rclone', 'thumb', 'as_doc']): buttons.ibutton("Reset Setting", f"userset {user_id} reset_all") buttons.ibutton("Close", f"userset {user_id} close") text = f'User Settings for {name}' @@ -99,9 +99,10 @@ async def get_user_settings(from_user, key=None, edit_type=None, edit_mode=None) buttons.ibutton("Thumbnail", f"userset {user_id} thumb") thumbmsg = "Exists" if await aiopath.exists(thumbpath) else "Not Exists" - buttons.ibutton("Leech Splits", f"userset {user_id} split_size") - split_size = get_readable_file_size(config_dict['LEECH_SPLIT_SIZE']) + ' (Default)' if user_dict.get('split_size', '') == '' else get_readable_file_size(user_dict['split_size']) - equal_splits = 'Enabled' if user_dict.get('equal_splits', config_dict.get('EQUAL_SPLITS')) else 'Disabled' + if user_dict.get('media_group', False) or ('media_group' not in user_dict and config_dict['MEDIA_GROUP']): + buttons.ibutton("Disable Media Group", f"userset {user_id} mgroup") + else: + buttons.ibutton("Enable Media Group", f"userset {user_id} mgroup") media_group = 'Enabled' if user_dict.get('media_group', config_dict.get('MEDIA_GROUP')) else 'Disabled' buttons.ibutton("Leech Caption", f"userset {user_id} lcaption") @@ -113,8 +114,6 @@ async def get_user_settings(from_user, key=None, edit_type=None, edit_mode=None) text = f'Leech Settings for {name}\n\n' text += f'• Leech Type: {ltype}\n' text += f'• Custom Thumbnail: {thumbmsg}\n' - text += f'• Leech Split Size: {split_size}\n' - text += f'• Equal Splits: {equal_splits}\n' text += f'• Media Group: {media_group}\n' text += f'• Leech Caption: {escape(lcaption)}\n' text += f'• Leech Dump: {ldump}\n' @@ -134,17 +133,6 @@ async def get_user_settings(from_user, key=None, edit_type=None, edit_mode=None) elif key == 'yt_opt': set_exist = 'Not Exists' if (val:=user_dict.get('yt_opt', config_dict.get('YT_DLP_OPTIONS', ''))) == '' else val text += f"YT-DLP Options : {escape(set_exist)}\n\n" - elif key == 'split_size': - set_exist = get_readable_file_size(config_dict['LEECH_SPLIT_SIZE']) + ' (Default)' if user_dict.get('split_size', '') == '' else get_readable_file_size(user_dict['split_size']) - text += f"Leech Split Size : {set_exist}\n\n" - if user_dict.get('equal_splits', False) or ('equal_splits' not in user_dict and config_dict['EQUAL_SPLITS']): - buttons.ibutton("Disable Equal Splits", f"userset {user_id} esplits", "header") - else: - buttons.ibutton("Enable Equal Splits", f"userset {user_id} esplits", "header") - if user_dict.get('media_group', False) or ('media_group' not in user_dict and config_dict['MEDIA_GROUP']): - buttons.ibutton("Disable Media Group", f"userset {user_id} mgroup", "header") - else: - buttons.ibutton("Enable Media Group", f"userset {user_id} mgroup", "header") elif key in ['prefix', 'remname', 'suffix', 'lcaption', 'ldump']: set_exist = 'Not Exists' if (val:=user_dict.get(key, '')) == '' else val text += f"Filename {fname_dict[key]} : {set_exist}\n\n" @@ -160,8 +148,8 @@ async def get_user_settings(from_user, key=None, edit_type=None, edit_mode=None) text += '\n\n' + uset_display_dict[key][1] buttons.ibutton("Stop Change", f"userset {user_id} {key}") elif key != 'user_tds' or set_exist == 'Not Exists': - buttons.ibutton(f"Change {fname_dict[key]}" if set_exist and set_exist != 'Not Exists' and (set_exist != get_readable_file_size(config_dict['LEECH_SPLIT_SIZE']) + ' (Default)') else f"Set {fname_dict[key]}", f"userset {user_id} {key} edit") - if set_exist and set_exist != 'Not Exists' and (set_exist != get_readable_file_size(config_dict['LEECH_SPLIT_SIZE']) + ' (Default)'): + buttons.ibutton(f"Change {fname_dict[key]}" if set_exist and set_exist != 'Not Exists' else f"Set {fname_dict[key]}", f"userset {user_id} {key} edit") + if set_exist and set_exist != 'Not Exists': if key == 'user_tds': buttons.ibutton('Show UserTDs', f"userset {user_id} show_tds", "header") buttons.ibutton("Delete", f"userset {user_id} d{key}") @@ -266,22 +254,6 @@ async def add_rclone(client, message, pre_event): await DbManager().update_user_doc(user_id, 'rclone', des_dir) -async def leech_split_size(client, message, pre_event): - user_id = message.from_user.id - handler_dict[user_id] = False - sdic = ['b', 'kb', 'mb', 'gb'] - value = message.text.strip() - slice = -2 if value[-2].lower() in ['k', 'm', 'g'] else -1 - out = value[slice:].strip().lower() - if out in sdic: - value = min((float(value[:slice].strip()) * 1024**sdic.index(out)), MAX_SPLIT_SIZE) - update_user_ldata(user_id, 'split_size', int(round(value))) - await message.delete() - await update_user_settings(pre_event, 'split_size', 'leech') - if DATABASE_URL: - await DbManager().update_user_data(user_id) - - async def event_handler(client, query, pfunc, rfunc, photo=False, document=False): user_id = query.from_user.id handler_dict[user_id] = True @@ -330,7 +302,7 @@ async def edit_user_settings(client, query): elif data[2] == 'show_tds': handler_dict[user_id] = False user_tds = user_dict.get('user_tds', {}) - msg = f'User TD(s) Details\n\nTotal UserTD(s) : {len(user_tds)}\n\n' + msg = f'User TD Details\n\n' for index_no, (drive_name, drive_dict) in enumerate(user_tds.items(), start=1): msg += f'{index_no}: Name: {drive_name}\n' msg += f" Drive ID: {drive_dict['drive_id']}\n" @@ -394,28 +366,6 @@ async def edit_user_settings(client, query): await update_user_settings(query, 'leech') if DATABASE_URL: await DbManager().update_user_data(user_id) - elif data[2] == 'split_size': - await query.answer() - edit_mode = len(data) == 4 - await update_user_settings(query, data[2], 'leech', edit_mode) - if not edit_mode: return - pfunc = partial(leech_split_size, pre_event=query) - rfunc = partial(update_user_settings, query, data[2], 'leech') - await event_handler(client, query, pfunc, rfunc) - elif data[2] == 'dsplit_size': - handler_dict[user_id] = False - await query.answer() - update_user_ldata(user_id, 'split_size', '') - await update_user_settings(query, 'split_size', 'leech') - if DATABASE_URL: - await DbManager().update_user_data(user_id) - elif data[2] == 'esplits': - handler_dict[user_id] = False - await query.answer() - update_user_ldata(user_id, 'equal_splits', not user_dict.get('equal_splits', False)) - await update_user_settings(query, 'leech') - if DATABASE_URL: - await DbManager().update_user_data(user_id) elif data[2] == 'mgroup': handler_dict[user_id] = False await query.answer() diff --git a/bot/modules/ytdlp.py b/bot/modules/ytdlp.py index 54ac08c9f..2e88bcaa0 100644 --- a/bot/modules/ytdlp.py +++ b/bot/modules/ytdlp.py @@ -128,14 +128,14 @@ async def get_quality(self, result): if item.get('audio_ext') == 'm4a': self.__is_m4a = True b_name = f"{item['acodec']}-{item['ext']}" - v_format = f'ba[format_id={format_id}]' + v_format = format_id elif item.get('height'): height = item['height'] ext = item['ext'] fps = item['fps'] if item.get('fps') else '' b_name = f'{height}p{fps}-{ext}' ba_ext = '[ext=m4a]' if self.__is_m4a and ext == 'mp4' else '' - v_format = f'bv*[format_id={format_id}]+ba{ba_ext}/b[height=?{height}]' + v_format = f'{format_id}+ba{ba_ext}/b[height=?{height}]' else: continue