From 527d1809d6c5dd0489bb8f328aee5281786677e9 Mon Sep 17 00:00:00 2001 From: Zodiac Date: Thu, 13 Feb 2025 03:33:31 -0800 Subject: [PATCH] add headers to get around bans --- plugins/upload.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/upload.py b/plugins/upload.py index 6580455..532024a 100644 --- a/plugins/upload.py +++ b/plugins/upload.py @@ -34,6 +34,16 @@ import yt_dlp from yt_dlp.utils import DownloadError from urllib.parse import urlparse +# Global headers to mimic a real browser (ban evasion) +HEADERS = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.9", + "Referer": "https://www.google.com/", + "Connection": "keep-alive", + "DNT": "1", + "Upgrade-Insecure-Requests": "1" +} @irc3.plugin class UploadPlugin: @@ -123,7 +133,7 @@ class UploadPlugin: if should_check_headers: try: - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(headers=HEADERS) as session: async with session.head(url) as response: if response.status != 200: self.bot.privmsg( @@ -325,7 +335,7 @@ class UploadPlugin: return try: - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(headers=HEADERS) as session: form = aiohttp.FormData() async with aiofiles.open(downloaded_file, 'rb') as f: file_content = await f.read() @@ -395,4 +405,4 @@ class UploadPlugin: seconds = int(seconds) m, s = divmod(seconds, 60) h, m = divmod(m, 60) - return f"{h}h {m}m {s}s" if h else f"{m}m {s}s" \ No newline at end of file + return f"{h}h {m}m {s}s" if h else f"{m}m {s}s"