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 yt_dlp.utils import DownloadError
|
||||||
from urllib.parse import urlparse
|
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
|
@irc3.plugin
|
||||||
class UploadPlugin:
|
class UploadPlugin:
|
||||||
@ -123,7 +133,7 @@ class UploadPlugin:
|
|||||||
|
|
||||||
if should_check_headers:
|
if should_check_headers:
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession(headers=HEADERS) as session:
|
||||||
async with session.head(url) as response:
|
async with session.head(url) as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
self.bot.privmsg(
|
self.bot.privmsg(
|
||||||
@ -325,7 +335,7 @@ class UploadPlugin:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession(headers=HEADERS) as session:
|
||||||
form = aiohttp.FormData()
|
form = aiohttp.FormData()
|
||||||
async with aiofiles.open(downloaded_file, 'rb') as f:
|
async with aiofiles.open(downloaded_file, 'rb') as f:
|
||||||
file_content = await f.read()
|
file_content = await f.read()
|
||||||
@ -395,4 +405,4 @@ class UploadPlugin:
|
|||||||
seconds = int(seconds)
|
seconds = int(seconds)
|
||||||
m, s = divmod(seconds, 60)
|
m, s = divmod(seconds, 60)
|
||||||
h, m = divmod(m, 60)
|
h, m = divmod(m, 60)
|
||||||
return f"{h}h {m}m {s}s" if h else f"{m}m {s}s"
|
return f"{h}h {m}m {s}s" if h else f"{m}m {s}s"
|
||||||
|
Loading…
Reference in New Issue
Block a user