reset
This commit is contained in:
parent
c292fb2d1c
commit
3893b2a12e
@ -3,7 +3,7 @@
|
|||||||
IRC Bot Plugin for Uploading Files to hardfiles.org
|
IRC Bot Plugin for Uploading Files to hardfiles.org
|
||||||
|
|
||||||
This plugin allows users to upload files to hardfiles.org using yt-dlp for downloads.
|
This plugin allows users to upload files to hardfiles.org using yt-dlp for downloads.
|
||||||
It supports downloading files from various sources (YouTube, Instagram, Reddit, etc.) and can
|
It supports downloading files from various sources (YouTube, Instagram, etc.) and can
|
||||||
optionally convert videos to MP3 format before uploading. Files larger than 100MB are rejected.
|
optionally convert videos to MP3 format before uploading. Files larger than 100MB are rejected.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@ -134,6 +134,7 @@ class UploadPlugin:
|
|||||||
"facebook.com",
|
"facebook.com",
|
||||||
"dailymotion.com",
|
"dailymotion.com",
|
||||||
)
|
)
|
||||||
|
|
||||||
should_check_headers = not any(domain.endswith(d) for d in skip_check_domains)
|
should_check_headers = not any(domain.endswith(d) for d in skip_check_domains)
|
||||||
|
|
||||||
if should_check_headers:
|
if should_check_headers:
|
||||||
@ -189,51 +190,34 @@ class UploadPlugin:
|
|||||||
'preferredcodec': 'mp3',
|
'preferredcodec': 'mp3',
|
||||||
'preferredquality': '192',
|
'preferredquality': '192',
|
||||||
}
|
}
|
||||||
] if mp3 else [],
|
]
|
||||||
|
if mp3
|
||||||
|
else [],
|
||||||
}
|
}
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
try:
|
try:
|
||||||
# Try to extract info without downloading
|
|
||||||
info = await asyncio.to_thread(ydl.extract_info, url, download=False)
|
info = await asyncio.to_thread(ydl.extract_info, url, download=False)
|
||||||
except DownloadError as e:
|
except DownloadError as e:
|
||||||
err_msg = self._ensure_str(e)
|
err_msg = self._ensure_str(e)
|
||||||
# If authentication is required (e.g. for Reddit), skip info extraction
|
self.bot.privmsg(
|
||||||
if "Account authentication is required" in err_msg or "[Reddit]" in err_msg:
|
target,
|
||||||
self.bot.privmsg(
|
ircstyle.style(
|
||||||
target,
|
f"Info extraction failed: {err_msg}", fg="red", bold=True, reset=True
|
||||||
ircstyle.style(
|
),
|
||||||
f"Info extraction failed (auth error): {err_msg}. Skipping info extraction and proceeding with download.",
|
)
|
||||||
fg="yellow",
|
return
|
||||||
bold=True,
|
except UnicodeDecodeError:
|
||||||
reset=True,
|
self.bot.privmsg(
|
||||||
),
|
target,
|
||||||
)
|
ircstyle.style(
|
||||||
try:
|
"Error: Received non-UTF-8 output during info extraction",
|
||||||
info = await asyncio.to_thread(ydl.extract_info, url, download=True)
|
fg="red",
|
||||||
except Exception as e2:
|
bold=True,
|
||||||
err_msg2 = self._ensure_str(e2)
|
reset=True,
|
||||||
self.bot.privmsg(
|
),
|
||||||
target,
|
)
|
||||||
ircstyle.style(
|
return
|
||||||
f"Download failed: {err_msg2}",
|
|
||||||
fg="red",
|
|
||||||
bold=True,
|
|
||||||
reset=True,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
self.bot.privmsg(
|
|
||||||
target,
|
|
||||||
ircstyle.style(
|
|
||||||
f"Info extraction failed: {err_msg}",
|
|
||||||
fg="red",
|
|
||||||
bold=True,
|
|
||||||
reset=True,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
estimated_size = info.get('filesize') or info.get('filesize_approx')
|
estimated_size = info.get('filesize') or info.get('filesize_approx')
|
||||||
if estimated_size and estimated_size > max_size:
|
if estimated_size and estimated_size > max_size:
|
||||||
@ -249,17 +233,13 @@ class UploadPlugin:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Proceed with the download (this may overwrite info if not already downloaded)
|
|
||||||
info = await asyncio.to_thread(ydl.extract_info, url, download=True)
|
info = await asyncio.to_thread(ydl.extract_info, url, download=True)
|
||||||
except DownloadError as e:
|
except DownloadError as e:
|
||||||
err_msg = self._ensure_str(e)
|
err_msg = self._ensure_str(e)
|
||||||
self.bot.privmsg(
|
self.bot.privmsg(
|
||||||
target,
|
target,
|
||||||
ircstyle.style(
|
ircstyle.style(
|
||||||
f"Download failed: {err_msg}",
|
f"Download failed: {err_msg}", fg="red", bold=True, reset=True
|
||||||
fg="red",
|
|
||||||
bold=True,
|
|
||||||
reset=True,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -275,7 +255,7 @@ class UploadPlugin:
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Safely convert metadata to strings
|
# Safely convert metadata to strings.
|
||||||
metadata_parts = []
|
metadata_parts = []
|
||||||
title = self._ensure_str(info.get("title"))
|
title = self._ensure_str(info.get("title"))
|
||||||
uploader = self._ensure_str(info.get("uploader"))
|
uploader = self._ensure_str(info.get("uploader"))
|
||||||
@ -386,6 +366,7 @@ class UploadPlugin:
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
raw_response = await resp.read()
|
raw_response = await resp.read()
|
||||||
|
# Decode the response safely even if non-UTF-8 bytes are present.
|
||||||
response_text = raw_response.decode('utf-8', errors='replace')
|
response_text = raw_response.decode('utf-8', errors='replace')
|
||||||
upload_url = self.extract_url_from_response(response_text) or "Unknown URL"
|
upload_url = self.extract_url_from_response(response_text) or "Unknown URL"
|
||||||
upload_url = self._ensure_str(upload_url)
|
upload_url = self._ensure_str(upload_url)
|
||||||
|
Loading…
Reference in New Issue
Block a user