Add configurable output filename format
Introduce a new filename_format setting and UI to control yt-dlp output templates. ConfigManager now includes a default filename_format (%(title)s_%(resolution)s.%(ext)s). The DownloadSettingsDialog exposes a text input and help text for the format and saves the value to ConfigManager. DownloadThread now accepts a filename_format argument and uses it when building output templates for single videos and playlists. YTSageApp reads the config and passes the filename format into the download thread. Added corresponding English language strings.
This commit is contained in:
@@ -280,6 +280,25 @@ class DownloadSettingsDialog(QDialog):
|
||||
audio_format_group_box.setLayout(audio_format_layout)
|
||||
layout.addWidget(audio_format_group_box)
|
||||
|
||||
# --- Filename Format Section ---
|
||||
filename_format_group_box = QGroupBox(_("settings.filename_format"))
|
||||
filename_layout = QVBoxLayout()
|
||||
|
||||
# Load current filename format from ConfigManager
|
||||
self.filename_format_value = ConfigManager.get("filename_format") or "%(title)s_%(resolution)s.%(ext)s"
|
||||
|
||||
self.filename_format_input = QLineEdit(self.filename_format_value)
|
||||
self.filename_format_input.setPlaceholderText("%(title)s_%(resolution)s.%(ext)s")
|
||||
filename_layout.addWidget(self.filename_format_input)
|
||||
|
||||
filename_help_label = QLabel(_("settings.filename_format_help"))
|
||||
filename_help_label.setWordWrap(True)
|
||||
filename_help_label.setStyleSheet("color: #cccccc; margin: 5px; font-size: 10px;")
|
||||
filename_layout.addWidget(filename_help_label)
|
||||
|
||||
filename_format_group_box.setLayout(filename_layout)
|
||||
layout.addWidget(filename_format_group_box)
|
||||
|
||||
# Dialog buttons (OK/Cancel)
|
||||
button_box = QDialogButtonBox()
|
||||
ok_button = button_box.addButton(_("buttons.ok"), QDialogButtonBox.ButtonRole.AcceptRole)
|
||||
@@ -332,6 +351,10 @@ class DownloadSettingsDialog(QDialog):
|
||||
audio_format_map = {0: "best", 1: "aac", 2: "mp3", 3: "flac", 4: "wav", 5: "opus", 6: "m4a", 7: "vorbis"}
|
||||
return audio_format_map.get(self.audio_format_combo.currentIndex(), "best")
|
||||
|
||||
def get_filename_format(self) -> str:
|
||||
"""Returns the filename format string."""
|
||||
return self.filename_format_input.text().strip()
|
||||
|
||||
def _create_styled_message_box(self, icon, title, text) -> QMessageBox:
|
||||
"""Create a styled QMessageBox that matches the app theme."""
|
||||
msg_box = QMessageBox(self)
|
||||
@@ -382,6 +405,11 @@ class DownloadSettingsDialog(QDialog):
|
||||
ConfigManager.set("force_audio_format", force_audio_format)
|
||||
ConfigManager.set("preferred_audio_format", preferred_audio_format)
|
||||
|
||||
# Save filename format
|
||||
filename_format = self.get_filename_format()
|
||||
if filename_format:
|
||||
ConfigManager.set("filename_format", filename_format)
|
||||
|
||||
QMessageBox.information(
|
||||
self,
|
||||
_("settings.settings_saved_title"),
|
||||
|
||||
@@ -678,6 +678,9 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
|
||||
logger.warning(f"Thumbnail download failed: {e}", exc_info=True)
|
||||
# Optionally inform the user, but don't stop the main download
|
||||
|
||||
# Get filename format from config
|
||||
filename_format = ConfigManager.get("filename_format")
|
||||
|
||||
# Create download thread with resolution in output template
|
||||
self.download_thread = DownloadThread(
|
||||
url=url,
|
||||
@@ -705,6 +708,7 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
|
||||
preferred_output_format=self.preferred_output_format, # Pass preferred format
|
||||
force_audio_format=self.force_audio_format, # Pass force audio format setting
|
||||
preferred_audio_format=self.preferred_audio_format, # Pass preferred audio format
|
||||
filename_format=filename_format, # Pass the filename format
|
||||
)
|
||||
|
||||
# Connect signals
|
||||
|
||||
Reference in New Issue
Block a user