Improve displaying the actual error message on the frontend when yt-dlp fails to download a video.
Browse files- src/download.py +15 -12
src/download.py
CHANGED
@@ -49,22 +49,25 @@ def _perform_download(url: str, maxDuration: int = None, outputTemplate: str = N
|
|
49 |
|
50 |
filename_collector = FilenameCollectorPP()
|
51 |
with redirect_stderr(errStrIO):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
|
67 |
-
|
68 |
|
69 |
errMsg = errStrIO.getvalue()
|
70 |
errMsg = [text for text in errMsg.split("\n") if text.startswith("ERROR")] if errMsg else ""
|
|
|
49 |
|
50 |
filename_collector = FilenameCollectorPP()
|
51 |
with redirect_stderr(errStrIO):
|
52 |
+
for _ in (True,):
|
53 |
+
with YoutubeDL(ydl_opts) as ydl:
|
54 |
+
if maxDuration and maxDuration > 0:
|
55 |
+
info = ydl.extract_info(url, download=False)
|
56 |
+
if not info: break
|
57 |
+
|
58 |
+
entries = "entries" in info and info["entries"] or [info]
|
59 |
|
60 |
+
total_duration = 0
|
61 |
|
62 |
+
# Compute total duration
|
63 |
+
for entry in entries:
|
64 |
+
if entry: total_duration += float(entry["duration"])
|
65 |
|
66 |
+
if total_duration >= maxDuration:
|
67 |
+
raise ExceededMaximumDuration(videoDuration=total_duration, maxDuration=maxDuration, message="Video is too long")
|
68 |
|
69 |
+
ydl.add_post_processor(filename_collector)
|
70 |
+
ydl.download([url])
|
71 |
|
72 |
errMsg = errStrIO.getvalue()
|
73 |
errMsg = [text for text in errMsg.split("\n") if text.startswith("ERROR")] if errMsg else ""
|