Reapply "Fix path handling and subtitle file tracking in downloader"

This reverts commit afcab75b20.
This commit is contained in:
Your Name
2025-09-04 17:50:03 +03:00
parent afcab75b20
commit 9e89228c6d
+19 -7
View File
@@ -1,3 +1,4 @@
import os
import re import re
import shlex # For safely parsing command arguments import shlex # For safely parsing command arguments
import subprocess # For direct CLI command execution import subprocess # For direct CLI command execution
@@ -141,7 +142,7 @@ class DownloadThread(QThread):
"skip_download": True, "skip_download": True,
"no_warnings": True, # <-- Suppress warnings during check "no_warnings": True, # <-- Suppress warnings during check
"ignoreerrors": True, # Also ignore other potential errors during this check "ignoreerrors": True, # Also ignore other potential errors during this check
"outtmpl": {"default": Path.joinpath(self.path, "%(title)s.%(ext)s")}, "outtmpl": {"default": self.path.joinpath("%(title)s.%(ext)s")},
"format": (self.format_id if self.format_id else "best"), # Use selected format or best "format": (self.format_id if self.format_id else "best"), # Use selected format or best
} }
if self.cookie_file: if self.cookie_file:
@@ -262,7 +263,7 @@ class DownloadThread(QThread):
cmd.extend(["-S", f"res:{res_value}"]) cmd.extend(["-S", f"res:{res_value}"])
# Output template with resolution in filename # Output template with resolution in filename
output_template = Path.joinpath(self.path, "%(title)s_%(resolution)s.%(ext)s") output_template = self.path.joinpath("%(title)s_%(resolution)s.%(ext)s")
# Handle playlist directory creation if needed # Handle playlist directory creation if needed
if self.is_playlist: if self.is_playlist:
@@ -526,21 +527,32 @@ class DownloadThread(QThread):
# Detect subtitle file creation # Detect subtitle file creation
# Look for lines like "[info] Writing video subtitles to: filename.xx.vtt" # Look for lines like "[info] Writing video subtitles to: filename.xx.vtt"
subtitle_match = re.search( subtitle_match = re.search(
r"(?:Writing|Downloading) (?:video )?subtitles.*?(?:to|:)\s*(.*\.(?:vtt|srt))", r"(?:Writing|Downloading) (?:video )?subtitles.*?(?:to|:)\s*(.+\.(?:vtt|srt))(?:\s|$)",
line, line,
re.IGNORECASE, re.IGNORECASE,
) )
if subtitle_match: if subtitle_match:
subtitle_file = subtitle_match.group(1).strip() subtitle_file = subtitle_match.group(1).strip()
# Clean up the path - remove any duplicated directory paths
# Sometimes yt-dlp output contains malformed paths like "dir: dir/file"
if ":" in subtitle_file and os.name == 'nt': # Windows paths
# Look for pattern like "C:\path: C:\path\file" and extract the latter
colon_parts = subtitle_file.split(": ")
if len(colon_parts) > 1:
# Take the last part which should be the actual file path
subtitle_file = colon_parts[-1].strip()
# Show subtitle download message # Show subtitle download message
self.status_signal.emit(f"⏬ Downloading subtitle...") self.status_signal.emit(f"⏬ Downloading subtitle...")
# Store the subtitle file path for later deletion if merging is enabled # Store the subtitle file path for later deletion if merging is enabled
if self.merge_subs: if self.merge_subs:
if not Path(subtitle_file).is_absolute(): subtitle_path = Path(subtitle_file)
if not subtitle_path.is_absolute():
# If it's a relative path, make it absolute based on current path # If it's a relative path, make it absolute based on current path
subtitle_file = Path.joinpath(self.path, subtitle_file) subtitle_path = self.path.joinpath(subtitle_file)
self.subtitle_files.append(subtitle_file) self.subtitle_files.append(str(subtitle_path))
logger.debug(f"Tracking subtitle file for later cleanup: {subtitle_file}") logger.debug(f"Tracking subtitle file for later cleanup: {subtitle_path}")
return return
# Send status updates based on output line content # Send status updates based on output line content