summaryrefslogtreecommitdiff
path: root/server/szurubooru/func/net.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/szurubooru/func/net.py')
-rw-r--r--server/szurubooru/func/net.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py
index 9dff3c4..d6aa95e 100644
--- a/server/szurubooru/func/net.py
+++ b/server/szurubooru/func/net.py
@@ -39,13 +39,20 @@ def download(url: str, use_video_downloader: bool = False) -> bytes:
length_tally = 0
try:
with urllib.request.urlopen(request) as handle:
- while (chunk := handle.read(_dl_chunk_size)) :
+ while chunk := handle.read(_dl_chunk_size):
length_tally += len(chunk)
if length_tally > config.config["max_dl_filesize"]:
- raise DownloadTooLargeError(url)
+ raise DownloadTooLargeError(
+ "Download target exceeds maximum. (%d)"
+ % (config.config["max_dl_filesize"]),
+ extra_fields={"URL": url},
+ )
content_buffer += chunk
except urllib.error.HTTPError as ex:
- raise DownloadError(url) from ex
+ raise DownloadError(
+ "Download target returned HTTP %d. (%s)" % (ex.code, ex.reason),
+ extra_fields={"URL": url},
+ ) from ex
if (
youtube_dl_error
@@ -57,7 +64,7 @@ def download(url: str, use_video_downloader: bool = False) -> bytes:
def _get_youtube_dl_content_url(url: str) -> str:
- cmd = ["youtube-dl", "--format", "best", "--no-playlist"]
+ cmd = ["yt-dlp", "--format", "best", "--no-playlist"]
if config.config["user_agent"]:
cmd.extend(["--user-agent", config.config["user_agent"]])
cmd.extend(["--get-url", url])
@@ -69,7 +76,8 @@ def _get_youtube_dl_content_url(url: str) -> str:
)
except subprocess.CalledProcessError:
raise errors.ThirdPartyError(
- "Could not extract content location from %s" % (url)
+ "Could not extract content location from URL.",
+ extra_fields={"URL": url},
) from None