From fb209351f2df439f2a028d329bc3fb5ad82e7bd5 Mon Sep 17 00:00:00 2001 From: oop7 <110548351+oop7@users.noreply.github.com> Date: Sat, 25 Apr 2026 10:32:49 +0300 Subject: [PATCH] Auto-select default video quality in formats After populating the format table, read default_video_quality from ConfigManager and attempt to auto-select a matching video format (by resolution/height). If a matching video format is found it is checked and handle_checkbox_click is invoked to trigger selection side-effects; if not, the first (highest-quality) format is selected as a fallback. Existing visibility filtering via filter_formats is still applied afterward. --- ytsage/gui/ytsage_gui_format_table.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ytsage/gui/ytsage_gui_format_table.py b/ytsage/gui/ytsage_gui_format_table.py index e87c685..5b2dea0 100644 --- a/ytsage/gui/ytsage_gui_format_table.py +++ b/ytsage/gui/ytsage_gui_format_table.py @@ -238,6 +238,30 @@ class FormatTableMixin: self._populate_format_table(all_filtered) self._table_built = True + from ..utils.ytsage_config_manager import ConfigManager + default_video_quality = ConfigManager.get("default_video_quality") + + # Auto-select the default or best format + if self.format_checkboxes: + found_default = False + if default_video_quality: + # Try to find a video format with the requested height (e.g. '1080') + target_height = str(default_video_quality) + # the formats are sorted by quality, so the first match is typically the best one for that height + for idx, (f, fmt_type) in enumerate(all_filtered): + if fmt_type == "video": + res = str(f.get("resolution", "")) + if res.endswith(f"x{target_height}") or target_height in res: + self.format_checkboxes[idx].setChecked(True) + self.handle_checkbox_click(self.format_checkboxes[idx]) + found_default = True + break + + if not found_default: + # Fallback to the first available format (which is the best quality since it's sorted) + self.format_checkboxes[0].setChecked(True) + self.handle_checkbox_click(self.format_checkboxes[0]) + # Apply initial visibility based on current button states self.filter_formats()