From 2d22543c797412af9fe3f42658aa2935d502dc11 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:09:37 +0000 Subject: [PATCH 1/4] Initial plan From 6db46d7ca0af6bd12230da89432d6e1b6ae25e4c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:13:23 +0000 Subject: [PATCH 2/4] Add check to disable ytdlp download in saved messages Co-authored-by: athphane <13810742+athphane@users.noreply.github.com> --- userbot/plugins/video_dl.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/userbot/plugins/video_dl.py b/userbot/plugins/video_dl.py index e38de8a9..dd021dfd 100644 --- a/userbot/plugins/video_dl.py +++ b/userbot/plugins/video_dl.py @@ -54,6 +54,11 @@ async def video_downloader(bot: UserBot, message: Message, from_reply=False): # Extract the video URL from the message message_text = message.text or message.caption + # Don't download if the message is sent to saved messages (to myself) + me = await bot.get_me() + if message.chat.id == me.id: + return + # Don't download if there is additional content in the message if not message_text.startswith("http") and not from_reply: return From f475be3e0e75caaa4ca0f73b5e8994182b5d50ad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:14:49 +0000 Subject: [PATCH 3/4] Optimize by caching bot user ID to avoid repeated API calls Co-authored-by: athphane <13810742+athphane@users.noreply.github.com> --- userbot/plugins/video_dl.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/userbot/plugins/video_dl.py b/userbot/plugins/video_dl.py index dd021dfd..d1ea7813 100644 --- a/userbot/plugins/video_dl.py +++ b/userbot/plugins/video_dl.py @@ -26,6 +26,9 @@ # Combined regex for function trigger video_url_regex = f"({instagram_regex}|{tiktok_regex}|{youtube_regex}|{facebook_regex})" +# Cache for the bot's user ID to avoid repeated API calls +_bot_user_id = None + async def get_final_url(url): timeout = aiohttp.ClientTimeout(total=10) @@ -51,12 +54,17 @@ async def process_urls(url): @UserBot.on_message(filters.regex(video_url_regex) & filters.me) async def video_downloader(bot: UserBot, message: Message, from_reply=False): + global _bot_user_id + # Extract the video URL from the message message_text = message.text or message.caption # Don't download if the message is sent to saved messages (to myself) - me = await bot.get_me() - if message.chat.id == me.id: + if _bot_user_id is None: + me = await bot.get_me() + _bot_user_id = me.id + + if message.chat.id == _bot_user_id: return # Don't download if there is additional content in the message From fd4a5a3b6b7d5a21a0877708311d2a8171d3694a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:15:48 +0000 Subject: [PATCH 4/4] Move saved messages check before message text extraction for better performance Co-authored-by: athphane <13810742+athphane@users.noreply.github.com> --- userbot/plugins/video_dl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/userbot/plugins/video_dl.py b/userbot/plugins/video_dl.py index d1ea7813..b76cb302 100644 --- a/userbot/plugins/video_dl.py +++ b/userbot/plugins/video_dl.py @@ -56,9 +56,6 @@ async def process_urls(url): async def video_downloader(bot: UserBot, message: Message, from_reply=False): global _bot_user_id - # Extract the video URL from the message - message_text = message.text or message.caption - # Don't download if the message is sent to saved messages (to myself) if _bot_user_id is None: me = await bot.get_me() @@ -66,6 +63,9 @@ async def video_downloader(bot: UserBot, message: Message, from_reply=False): if message.chat.id == _bot_user_id: return + + # Extract the video URL from the message + message_text = message.text or message.caption # Don't download if there is additional content in the message if not message_text.startswith("http") and not from_reply: