Capture yt-dlp errors and show better messages
Initialize an error buffer and collect yt-dlp "ERROR:" output lines during direct command runs. When the process exits non‑zero, emit a more informative error using the last two captured error lines (falling back to the generic return-code message if none were captured). Also ensure the buffer is present before appending and keep the existing delay/cleanup flow.
This commit is contained in:
@@ -385,7 +385,9 @@ class DownloadThread(QThread):
|
|||||||
def _run_direct_command(self) -> None:
|
def _run_direct_command(self) -> None:
|
||||||
"""Run yt-dlp as a direct command line process instead of using Python API."""
|
"""Run yt-dlp as a direct command line process instead of using Python API."""
|
||||||
try:
|
try:
|
||||||
|
self.error_lines = [] # Initialize error capture list
|
||||||
cmd: List[str] = self._build_yt_dlp_command()
|
cmd: List[str] = self._build_yt_dlp_command()
|
||||||
|
|
||||||
cmd_str: str = " ".join(shlex.quote(str(arg)) for arg in cmd)
|
cmd_str: str = " ".join(shlex.quote(str(arg)) for arg in cmd)
|
||||||
logger.debug(f"Executing command: {cmd_str}")
|
logger.debug(f"Executing command: {cmd_str}")
|
||||||
|
|
||||||
@@ -508,12 +510,15 @@ class DownloadThread(QThread):
|
|||||||
if self.cancelled:
|
if self.cancelled:
|
||||||
self.status_signal.emit(_("download.cancelled"))
|
self.status_signal.emit(_("download.cancelled"))
|
||||||
else:
|
else:
|
||||||
# Provide more descriptive error message for possible yt-dlp conflicts
|
# Provide informative error message based on captured output
|
||||||
if return_code == 1:
|
if self.error_lines:
|
||||||
|
# Use the captured error lines (last 2 for context)
|
||||||
|
error_msg = "\n".join(self.error_lines[-2:])
|
||||||
self.error_signal.emit(
|
self.error_signal.emit(
|
||||||
_("errors.download_failed_return_code_conflict", return_code=return_code)
|
_("errors.ytdlp_failed", error=error_msg)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Fallback to generic return code error
|
||||||
self.error_signal.emit(
|
self.error_signal.emit(
|
||||||
_("errors.download_failed_return_code", return_code=return_code)
|
_("errors.download_failed_return_code", return_code=return_code)
|
||||||
)
|
)
|
||||||
@@ -534,6 +539,11 @@ class DownloadThread(QThread):
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
# logger.info(f"yt-dlp: {line}") # Log all output - OPTIONALLY UNCOMMENT FOR VERBOSE DEBUG
|
# logger.info(f"yt-dlp: {line}") # Log all output - OPTIONALLY UNCOMMENT FOR VERBOSE DEBUG
|
||||||
|
|
||||||
|
# Capture error lines
|
||||||
|
if "ERROR:" in line:
|
||||||
|
if hasattr(self, 'error_lines'):
|
||||||
|
self.error_lines.append(line)
|
||||||
|
|
||||||
# Extract filename when the destination line appears
|
# Extract filename when the destination line appears
|
||||||
# Use a slightly more robust regex looking for the start of the line
|
# Use a slightly more robust regex looking for the start of the line
|
||||||
dest_match = re.search(r"^\[download\] Destination:\s*(.*)", line)
|
dest_match = re.search(r"^\[download\] Destination:\s*(.*)", line)
|
||||||
|
|||||||
Reference in New Issue
Block a user