Improve format selection for audio/video downloads

Refactored format selection logic to explicitly handle audio-only and progressive formats using new flags. Updated GUI to pass format metadata, ensuring correct yt-dlp command construction and more reliable downloads for different format types.
This commit is contained in:
oop7
2025-11-01 12:28:32 +02:00
parent 60a6eecc75
commit 73479a46bd
3 changed files with 25 additions and 17 deletions
+7 -1
View File
@@ -262,6 +262,8 @@ class FormatTableMixin:
# Column 0: Select Checkbox (Always shown)
checkbox = QCheckBox()
checkbox.format_id = str(f.get("format_id", "")) # type: ignore[reportAttributeAccessIssue]
checkbox.is_audio_only = bool((f.get("vcodec") or "none").lower() == "none") # type: ignore[attr-defined]
checkbox.has_audio = bool(f.get("acodec") and f.get("acodec") != "none") # type: ignore[attr-defined]
checkbox.clicked.connect(lambda checked, cb=checkbox: self.handle_checkbox_click(cb))
self.format_checkboxes.append(checkbox)
checkbox_widget = QWidget()
@@ -427,7 +429,11 @@ class FormatTableMixin:
for checkbox in self.format_checkboxes:
if checkbox.isChecked():
return checkbox.format_id
return {
"format_id": checkbox.format_id,
"is_audio_only": getattr(checkbox, "is_audio_only", False),
"has_audio": getattr(checkbox, "has_audio", False),
}
return None
def update_format_table(self, formats) -> None:
+7 -2
View File
@@ -802,10 +802,13 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
return
# Get selected format
format_id = self.get_selected_format()
if not format_id:
selected_format = self.get_selected_format()
if not selected_format:
self.status_label.setText(_('download.please_select_format'))
return
format_id = selected_format["format_id"]
is_audio_only = bool(selected_format.get("is_audio_only"))
format_has_audio = bool(selected_format.get("has_audio"))
# Show preparation message
self.status_label.setText(_('download.preparing'))
@@ -859,6 +862,8 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
url=url,
path=path,
format_id=format_id,
is_audio_only=is_audio_only,
format_has_audio=format_has_audio,
subtitle_langs=selected_subs, # Pass the list of selected subs
is_playlist=self.is_playlist, # Use the flag directly
merge_subs=self.merge_subs_checkbox.isChecked(),