Use values instad of plain text in subtitle formats

This commit is contained in:
Deniz Şafak
2025-07-04 20:44:58 +03:00
parent bc4ae106c1
commit f6c813602c
2 changed files with 38 additions and 15 deletions
+6 -6
View File
@@ -693,8 +693,8 @@ class ConversionThread(QThread):
if 'ass' in subtitle_format: if 'ass' in subtitle_format:
# Generate ASS subtitle # Generate ASS subtitle
is_centered = 'centered' in subtitle_format is_centered = subtitle_format in ("ass_centered_wide", "ass_centered_narrow")
is_narrow = 'narrow' in subtitle_format is_narrow = subtitle_format in ("ass_narrow", "ass_centered_narrow")
self._write_ass_subtitle(chapter_subtitle_path, chapter_subtitle_entries, is_centered, is_narrow) self._write_ass_subtitle(chapter_subtitle_path, chapter_subtitle_entries, is_centered, is_narrow)
else: else:
# Generate SRT subtitle (default) # Generate SRT subtitle (default)
@@ -772,10 +772,10 @@ class ConversionThread(QThread):
subtitle_path = os.path.splitext(final_out_path)[0] + f".{file_extension}" subtitle_path = os.path.splitext(final_out_path)[0] + f".{file_extension}"
if 'ass' in subtitle_format: if 'ass' in subtitle_format:
# Generate ASS subtitle with optional centering and margin # Generate ASS subtitle
is_centered = 'centered' in subtitle_format is_centered = subtitle_format in ("ass_centered_wide", "ass_centered_narrow")
is_narrow = 'narrow' in subtitle_format is_narrow = subtitle_format in ("ass_narrow", "ass_centered_narrow")
self._write_ass_subtitle(subtitle_path, subtitle_entries, is_centered, is_narrow) self._write_ass_subtitle(chapter_subtitle_path, chapter_subtitle_entries, is_centered, is_narrow)
else: else:
# Generate SRT subtitle (default) # Generate SRT subtitle (default)
with open(subtitle_path, "w", encoding="utf-8", errors="replace") as srt_file: with open(subtitle_path, "w", encoding="utf-8", errors="replace") as srt_file:
+29 -6
View File
@@ -503,11 +503,25 @@ class TextboxDialog(QDialog):
self.update_char_count() self.update_char_count()
self.text_edit.setFocus() self.text_edit.setFocus()
def migrate_subtitle_format(config):
"""Convert old subtitle_format values to new internal keys."""
old_to_new = {
"srt": "srt",
"ass (wide)": "ass_wide",
"ass (narrow)": "ass_narrow",
"ass (centered wide)": "ass_centered_wide",
"ass (centered narrow)": "ass_centered_narrow",
}
val = config.get("subtitle_format")
if val in old_to_new:
config["subtitle_format"] = old_to_new[val]
save_config(config)
class abogen(QWidget): class abogen(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.config = load_config() self.config = load_config()
migrate_subtitle_format(self.config)
self.check_updates = self.config.get("check_updates", True) self.check_updates = self.config.get("check_updates", True)
self.save_option = self.config.get("save_option", "Save next to input file") self.save_option = self.config.get("save_option", "Save next to input file")
self.selected_output_folder = self.config.get("selected_output_folder", None) self.selected_output_folder = self.config.get("selected_output_folder", None)
@@ -1336,7 +1350,7 @@ class abogen(QWidget):
# Pass separate_chapters_format setting # Pass separate_chapters_format setting
self.conversion_thread.separate_chapters_format = self.separate_chapters_format self.conversion_thread.separate_chapters_format = self.separate_chapters_format
# Pass subtitle format setting # Pass subtitle format setting
self.conversion_thread.subtitle_format = self.config.get("subtitle_format", "srt") self.conversion_thread.subtitle_format = self.config.get("subtitle_format", "ass_centered_narrow")
# Pass chapter count for EPUB or PDF files # Pass chapter count for EPUB or PDF files
if self.selected_file_type in ["epub", "pdf"] and hasattr( if self.selected_file_type in ["epub", "pdf"] and hasattr(
self, "selected_chapters" self, "selected_chapters"
@@ -1940,12 +1954,21 @@ class abogen(QWidget):
subtitle_format_group = QActionGroup(self) subtitle_format_group = QActionGroup(self)
subtitle_format_group.setExclusive(True) subtitle_format_group.setExclusive(True)
subtitle_format = self.config.get("subtitle_format", "srt") # Define mapping: (internal_value, display_text)
for format_option in ["srt", "ass (wide)", "ass (narrow)", "ass (centered wide)", "ass (centered narrow)"]: subtitle_formats = [
format_action = QAction(f"{format_option}", self) ("srt", "SRT (standard)"),
("ass_wide", "ASS (wide)"),
("ass_narrow", "ASS (narrow)"),
("ass_centered_wide", "ASS (centered wide)"),
("ass_centered_narrow", "ASS (centered narrow)"),
]
subtitle_format = self.config.get("subtitle_format", "ass_centered_narrow")
for value, text in subtitle_formats:
format_action = QAction(text, self)
format_action.setCheckable(True) format_action.setCheckable(True)
format_action.setChecked(subtitle_format == format_option) format_action.setChecked(subtitle_format == value)
format_action.triggered.connect(lambda checked, fmt=format_option: self.set_subtitle_format(fmt)) format_action.triggered.connect(lambda checked, fmt=value: self.set_subtitle_format(fmt))
subtitle_format_group.addAction(format_action) subtitle_format_group.addAction(format_action)
subtitle_format_menu.addAction(format_action) subtitle_format_menu.addAction(format_action)