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.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user