From afcab75b200ee01f17d4c1d5192f6fc58caa6ce7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 4 Sep 2025 17:48:36 +0300 Subject: [PATCH] Revert "Fix path handling and subtitle file tracking in downloader" This reverts commit 8198f7604f993ffb520c9a6d147ae5517dc48147. --- src/core/ytsage_downloader.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/core/ytsage_downloader.py b/src/core/ytsage_downloader.py index 6e09797..bc95abe 100644 --- a/src/core/ytsage_downloader.py +++ b/src/core/ytsage_downloader.py @@ -1,4 +1,3 @@ -import os import re import shlex # For safely parsing command arguments import subprocess # For direct CLI command execution @@ -142,7 +141,7 @@ class DownloadThread(QThread): "skip_download": True, "no_warnings": True, # <-- Suppress warnings during check "ignoreerrors": True, # Also ignore other potential errors during this check - "outtmpl": {"default": self.path.joinpath("%(title)s.%(ext)s")}, + "outtmpl": {"default": Path.joinpath(self.path, "%(title)s.%(ext)s")}, "format": (self.format_id if self.format_id else "best"), # Use selected format or best } if self.cookie_file: @@ -263,7 +262,7 @@ class DownloadThread(QThread): cmd.extend(["-S", f"res:{res_value}"]) # Output template with resolution in filename - output_template = self.path.joinpath("%(title)s_%(resolution)s.%(ext)s") + output_template = Path.joinpath(self.path, "%(title)s_%(resolution)s.%(ext)s") # Handle playlist directory creation if needed if self.is_playlist: @@ -527,32 +526,21 @@ class DownloadThread(QThread): # Detect subtitle file creation # Look for lines like "[info] Writing video subtitles to: filename.xx.vtt" subtitle_match = re.search( - r"(?:Writing|Downloading) (?:video )?subtitles.*?(?:to|:)\s*(.+\.(?:vtt|srt))(?:\s|$)", + r"(?:Writing|Downloading) (?:video )?subtitles.*?(?:to|:)\s*(.*\.(?:vtt|srt))", line, re.IGNORECASE, ) if subtitle_match: 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 self.status_signal.emit(f"⏬ Downloading subtitle...") # Store the subtitle file path for later deletion if merging is enabled if self.merge_subs: - subtitle_path = Path(subtitle_file) - if not subtitle_path.is_absolute(): + if not Path(subtitle_file).is_absolute(): # If it's a relative path, make it absolute based on current path - subtitle_path = self.path.joinpath(subtitle_file) - self.subtitle_files.append(str(subtitle_path)) - logger.debug(f"Tracking subtitle file for later cleanup: {subtitle_path}") + subtitle_file = Path.joinpath(self.path, subtitle_file) + self.subtitle_files.append(subtitle_file) + logger.debug(f"Tracking subtitle file for later cleanup: {subtitle_file}") return # Send status updates based on output line content