From 882b313a181a945037902607a732576da75ac34c Mon Sep 17 00:00:00 2001 From: cpanel10x Date: Sat, 30 Dec 2023 20:59:25 +0700 Subject: [PATCH] Clean resond from yt-dlp download errror (#328) --- ytdlbot/tasks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ytdlbot/tasks.py b/ytdlbot/tasks.py index 4fd63f2..e522f83 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -118,7 +118,11 @@ def ytdl_download_task(chat_id: int, message_id: int, url: str): else: bot_msg.edit_text(f"{e}\nBig file download is not available now. Please /buy or try again later ") except Exception: - bot_msg.edit_text(f"Download failed!❌\n\n`{traceback.format_exc()[-2000:]}`", disable_web_page_preview=True) + error_msg = traceback.format_exc().split("yt_dlp.utils.DownloadError: ERROR: ") + if len(error_msg) > 1: + bot_msg.edit_text(f"Download failed!❌\n\n`{error_msg[-1]}", disable_web_page_preview=True) + else: + bot_msg.edit_text(f"Download failed!❌\n\n`{traceback.format_exc()[-2000:]}`", disable_web_page_preview=True) logging.info("YouTube celery tasks ended.") @@ -191,7 +195,11 @@ def ytdl_download_entrance(client: Client, bot_msg: types.Message, url: str, mod bot_msg.edit_text(f"{e}\nBig file download is not available now. Please /buy or try again later ") except Exception as e: logging.error("Failed to download %s, error: %s", url, e) - bot_msg.edit_text(f"Download failed!❌\n\n`{traceback.format_exc()[-2000:]}`", disable_web_page_preview=True) + error_msg = traceback.format_exc().split("yt_dlp.utils.DownloadError: ERROR: ") + if len(error_msg) > 1: + bot_msg.edit_text(f"Download failed!❌\n\n`{error_msg[-1]}", disable_web_page_preview=True) + else: + bot_msg.edit_text(f"Download failed!❌\n\n`{traceback.format_exc()[-2000:]}`", disable_web_page_preview=True) def direct_download_entrance(client: Client, bot_msg: typing.Union[types.Message, typing.Coroutine], url: str):