add headers to get around bans
This commit is contained in:
parent
8c5d17e202
commit
527d1809d6
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user