fix(downloader): restore real-time progress bar and console output during download

This commit is contained in:
LilDosto 2026-10-28 02:43:45 +03:00
parent d0f857867a
commit f915998d34
4 changed files with 72 additions and 6 deletions

View file

@ -81,6 +81,7 @@ class DownloadEngine:
try:
env = os.environ.copy()
env["PYTHONIOENCODING"] = "utf-8"
env["PYTHONUNBUFFERED"] = "1"
from core.config import get_bin_dir
b_dir = get_bin_dir()
if b_dir and b_dir not in env.get("PATH", ""):
@ -119,6 +120,26 @@ class DownloadEngine:
last_destination = dest
self._current_file = dest
# Durum / Aşama güncellemesi
if line.startswith("[ExtractAudio]"):
if cb.get("on_status"):
cb["on_status"]("Ses dönüştürülüyor...")
elif line.startswith("[Merger]"):
if cb.get("on_status"):
cb["on_status"]("Formatlar birleştiriliyor...")
elif line.startswith(("[EmbedThumbnail]", "[ThumbnailsConvertor]")):
if cb.get("on_status"):
cb["on_status"]("Kapak resmi ekleniyor...")
elif line.startswith("[Metadata]"):
if cb.get("on_status"):
cb["on_status"]("Üstveri ekleniyor...")
elif line.startswith("[SponsorBlock]"):
if cb.get("on_status"):
cb["on_status"]("Sponsorlu bölümler kesiliyor...")
elif line.startswith("[download] Destination:"):
if cb.get("on_status"):
cb["on_status"]("İndiriliyor...")
# 2. İlerleme ayrıştırma
parsed = self._parse_progress(line, cb.get("on_progress"))
@ -138,7 +159,8 @@ class DownloadEngine:
elif "[download] 100%" in line or "100% of" in line:
tag = "success"
if cb.get("on_log") and not line.startswith("[PROGRESS]"):
is_progress_line = line.startswith("[PROGRESS]") or (parsed and bool(self._DL_RE.search(line)))
if cb.get("on_log") and not is_progress_line:
cb["on_log"](line, tag)
self._proc.wait()
@ -173,7 +195,7 @@ class DownloadEngine:
speed = "—" if not speed or any(x in speed.lower() for x in ["unknown", "na", "—"]) else speed
total = "—" if not total or any(x in total.lower() for x in ["unknown", "na", "—"]) else total
eta = "—" if not eta or any(x in eta.lower() for x in ["unknown", "na", "—"]) else eta
eta = "—" if not eta or any(x in eta.lower() for x in ["unknown", "na", "—"]) or "" in eta else eta
on_progress(pct, speed, total, eta)
return True
@ -334,11 +356,15 @@ def build_command(url, output_dir, options):
cmd += ["-o", os.path.join(output_dir, "%(title)s.%(ext)s")]
# Kararlı ilerleme şablonu ve nihai dosya yolu çıktısı
# NOT: yt-dlp'de --print bayrağı varsayılan olarak --quiet ve --no-progress modunu tetikler.
# Bu yüzden --progress ve --no-quiet açıkça eklenmelidir ki konsol ve ilerleme çubuğu çalışsın.
cmd += [
"--progress-template",
"download:[PROGRESS] %(progress._percent_str)s | %(progress._speed_str)s | %(progress._total_bytes_str)s | %(progress._eta_str)s",
"--print",
"after_move:[FINAL_PATH] %(filepath)s"
"after_move:[FINAL_PATH] %(filepath)s",
"--progress",
"--no-quiet",
"--progress-template",
"download:[PROGRESS] %(progress._percent_str)s | %(progress._speed_str)s | %(progress._total_bytes_str)s | %(progress._eta_str)s"
]
cmd.append(url)

View file

@ -129,6 +129,26 @@ class BuildCommandTests(unittest.TestCase):
self.assertIn("--download-sections", cmd)
self.assertIn("*01:20-03:45", cmd)
def test_progress_and_no_quiet_flags_present(self):
cmd = build_command(
"https://example.com/video",
"C:\\Downloads",
{"mode": "single"}
)
self.assertIn("--progress", cmd)
self.assertIn("--no-quiet", cmd)
self.assertIn("--progress-template", cmd)
self.assertIn("--print", cmd)
# Verify yt-dlp option parser preserves quiet=False and noprogress=False
try:
import yt_dlp
parsed = yt_dlp.parse_options(cmd[1:])
self.assertFalse(parsed.ydl_opts.get("quiet", False))
self.assertFalse(parsed.ydl_opts.get("noprogress", False))
except ImportError:
pass
def test_clip_section_range_validation(self):
self.assertIsNone(clip_section_range("", ""))
self.assertEqual(clip_section_range("01:20", "03:45"), "*01:20-03:45")

View file

@ -604,6 +604,9 @@ class LDownloaderApp(tk.Tk):
def _on_log(line, tag):
self.after(0, lambda: self.drawer.log_line(line, tag))
def _on_status(msg):
self.after(0, lambda: self.drawer.set_phase(msg))
def _on_complete(success, output_path, err, cancelled):
self.current_download_file = output_path
self.after(0, lambda: self.drawer.on_complete_status(success, output_path, err, cancelled))
@ -615,6 +618,7 @@ class LDownloaderApp(tk.Tk):
callbacks = {
"on_progress": _on_progress,
"on_log": _on_log,
"on_status": _on_status,
"on_complete": _on_complete
}
engine.start_download(cmd, callbacks)
@ -626,6 +630,9 @@ class LDownloaderApp(tk.Tk):
def _on_log(line, tag):
self.after(0, lambda: self.drawer.log_line(line, tag))
def _on_status(msg):
self.after(0, lambda: self.drawer.set_phase(msg))
def _on_complete(success, output_path, err, cancelled):
if done_callback:
done_callback(success, output_path, err, cancelled)
@ -633,6 +640,7 @@ class LDownloaderApp(tk.Tk):
callbacks = {
"on_progress": _on_progress,
"on_log": _on_log,
"on_status": _on_status,
"on_complete": _on_complete
}
return engine.start_download(cmd, callbacks)

View file

@ -606,6 +606,7 @@ class ContextualDownloadDrawer(tk.Frame):
self.log_text.tag_config("accent", foreground=ACCENT_LIGHT)
def show(self, title="İndirme", clear_logs=True):
self._base_title = title
self.lbl_title.config(text=f"⏳ {title}")
self.pbar["value"] = 0
self.pct_var.set("0%")
@ -619,8 +620,19 @@ class ContextualDownloadDrawer(tk.Frame):
self.btn_open.pack_forget()
self.btn_close.pack_forget()
self.btn_cancel.pack(side="left", padx=(0, 6), before=self.btn_console_toggle)
parent_container = getattr(self.master, "content_container", None)
if parent_container and parent_container.winfo_ismapped():
self.pack(fill="x", side="bottom", before=parent_container)
else:
self.pack(fill="x", side="bottom")
def set_phase(self, phase_text):
base = getattr(self, "_base_title", None)
if base:
self.lbl_title.config(text=f"⏳ {base} · {phase_text}")
else:
self.lbl_title.config(text=f"⏳ {phase_text}")
def hide(self):
self.pack_forget()
if self.console_open: