From d0f1b2e268ac8422a13f6521af8cf0ca878c348e Mon Sep 17 00:00:00 2001 From: Dawn India Date: Thu, 15 Aug 2024 14:10:11 +0530 Subject: [PATCH] Minor fix Forgot to add playlist limit checker function. Signed-off-by: Dawn India --- bot/helper/ext_utils/status_utils.py | 8 ++++---- bot/helper/ext_utils/task_manager.py | 12 ++++++++++++ .../task_utils/download_utils/yt_dlp_download.py | 12 ++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bot/helper/ext_utils/status_utils.py b/bot/helper/ext_utils/status_utils.py index 8785388eac56..dc89089ed575 100644 --- a/bot/helper/ext_utils/status_utils.py +++ b/bot/helper/ext_utils/status_utils.py @@ -393,10 +393,10 @@ async def get_readable_message( button = buttons.build_menu(8) msg += ( "▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬\n" - f"ᴄᴘᴜ: {cpu_percent()}% | " - f"ꜰʀᴇᴇ: {get_readable_file_size(disk_usage(DOWNLOAD_DIR).free)}\n" - f"ʀᴀᴍ: {virtual_memory().percent}% | " - f"ᴜᴘᴛᴍ: {get_readable_time(time() - botStartTime)}" + f"CPU: {cpu_percent()}% | " + f"FREE: {get_readable_file_size(disk_usage(DOWNLOAD_DIR).free)}\n" + f"RAM: {virtual_memory().percent}% | " + f"UPTM: {get_readable_time(time() - botStartTime)}" ) return ( msg, diff --git a/bot/helper/ext_utils/task_manager.py b/bot/helper/ext_utils/task_manager.py index 5eca2bea28a3..e92aee0347ac 100644 --- a/bot/helper/ext_utils/task_manager.py +++ b/bot/helper/ext_utils/task_manager.py @@ -260,6 +260,18 @@ async def check_user_tasks(user_id, maxtask): return len(all_tasks) >= maxtask +async def list_checker(listener): + try: + if await isAdmin(listener.message): + return + except Exception as e: + LOGGER.error(f"Error while checking if the user is Admin: {e}") + if listener.is_playlist: + if PLAYLIST_LIMIT := config_dict["PLAYLIST_LIMIT"]: + if listener.playlist_count > PLAYLIST_LIMIT: + return f"Playlist limit is {PLAYLIST_LIMIT}\n⚠ Your Playlist has {listener.playlist_count} items." + + async def limit_checker( listener, isTorrent=False, diff --git a/bot/helper/task_utils/download_utils/yt_dlp_download.py b/bot/helper/task_utils/download_utils/yt_dlp_download.py index 1022f7dcbe99..febff277e03a 100644 --- a/bot/helper/task_utils/download_utils/yt_dlp_download.py +++ b/bot/helper/task_utils/download_utils/yt_dlp_download.py @@ -24,6 +24,7 @@ from bot.helper.ext_utils.task_manager import ( check_running_tasks, limit_checker, + list_checker, stop_duplicate_check ) from bot.helper.task_utils.status_utils.queue_status import QueueStatus @@ -406,6 +407,17 @@ async def add_download(self, path, qual, playlist, options): ymsg ) return + if list_exceeded := await list_checker(self._listener): + LOGGER.info( + f"Yt-Dlp Limit Exceeded: {self._listener.name} | {get_readable_file_size(self._listener.size)} | {self.playlist_count}" + ) + ymsg = await self._listener.onDownloadError(list_exceeded) + await delete_links(self._listener.message) + await auto_delete_message( + self._listener.message, + ymsg + ) + return ( add_to_queue,