Improved automatic filename suffixing

This commit is contained in:
Deniz Şafak
2025-07-16 16:47:18 +03:00
parent f1903eb6ac
commit 6f09efd018
3 changed files with 33 additions and 18 deletions
+2
View File
@@ -2,6 +2,8 @@
- Changed the temporary directory path to user's cache directory, which is more appropriate for storing cache files and avoids issues with unintended cleanup. - Changed the temporary directory path to user's cache directory, which is more appropriate for storing cache files and avoids issues with unintended cleanup.
- Fixed the isssue where extra metadata information was not being saved to M4B files when they have no chapters, ensuring that all metadata is correctly written to the output file. - Fixed the isssue where extra metadata information was not being saved to M4B files when they have no chapters, ensuring that all metadata is correctly written to the output file.
- Fixed sleep prevention process not ending if program exited using Ctrl+C or kill. - Fixed sleep prevention process not ending if program exited using Ctrl+C or kill.
- Improved automatic filename suffixing to better prevent overwriting files with the same name, even if they have different extensions.
- Improvements in code and documentation.
# 1.1.4 # 1.1.4
- Fixed extra metadata information not being saved to M4B files, ensuring that all metadata is correctly written to the output file. - Fixed extra metadata information not being saved to M4B files, ensuring that all metadata is correctly written to the output file.
+22
View File
@@ -31,6 +31,28 @@ LANGUAGE_DESCRIPTIONS = {
"z": "Mandarin Chinese", "z": "Mandarin Chinese",
} }
# Supported sound formats
SUPPORTED_SOUND_FORMATS = [
"wav",
"mp3",
"opus",
"m4b",
"flac",
]
# Supported subtitle formats
SUPPORTED_SUBTITLE_FORMATS = [
"srt",
"ass",
]
# Supported input formats
SUPPORTED_INPUT_FORMATS = [
"epub",
"pdf",
"txt",
]
# Supported languages for subtitle generation # Supported languages for subtitle generation
# Currently, only 'a (American English)' and 'b (British English)' are supported for subtitle generation. # Currently, only 'a (American English)' and 'b (British English)' are supported for subtitle generation.
# This is because tokens that contain timestamps are not generated for other languages in the Kokoro pipeline. # This is because tokens that contain timestamps are not generated for other languages in the Kokoro pipeline.
+9 -18
View File
@@ -10,12 +10,13 @@ from PyQt5.QtWidgets import QCheckBox, QVBoxLayout, QDialog, QLabel, QDialogButt
import soundfile as sf import soundfile as sf
from abogen.utils import clean_text, create_process, get_user_cache_path from abogen.utils import clean_text, create_process, get_user_cache_path
from abogen.constants import ( from abogen.constants import (
PROGRAM_NAME,
LANGUAGE_DESCRIPTIONS, LANGUAGE_DESCRIPTIONS,
SAMPLE_VOICE_TEXTS, SAMPLE_VOICE_TEXTS,
COLORS, COLORS,
CHAPTER_OPTIONS_COUNTDOWN, CHAPTER_OPTIONS_COUNTDOWN,
SUBTITLE_FORMATS, SUBTITLE_FORMATS,
SUPPORTED_SOUND_FORMATS,
SUPPORTED_SUBTITLE_FORMATS,
) )
from abogen.voice_formulas import get_new_voice from abogen.voice_formulas import get_new_voice
import abogen.hf_tracker as hf_tracker import abogen.hf_tracker as hf_tracker
@@ -425,29 +426,19 @@ class ConversionThread(QThread):
) )
# Find a unique suffix for both folder and merged file, always # Find a unique suffix for both folder and merged file, always
counter = 1 counter = 1
allowed_exts = set(SUPPORTED_SOUND_FORMATS + SUPPORTED_SUBTITLE_FORMATS)
while True: while True:
suffix = f"_{counter}" if counter > 1 else "" suffix = f"_{counter}" if counter > 1 else ""
chapters_out_dir_candidate = os.path.join( chapters_out_dir_candidate = os.path.join(
parent_dir, f"{base_name}{suffix}_chapters" parent_dir, f"{base_name}{suffix}_chapters"
) )
merged_file_candidate = os.path.join( # Only check for files with allowed extensions (extension without dot, case-insensitive)
parent_dir, f"{base_name}{suffix}.{self.output_format}" clash = any(
os.path.splitext(fname)[0] == f"{base_name}{suffix}" and
os.path.splitext(fname)[1][1:].lower() in allowed_exts
for fname in os.listdir(parent_dir)
) )
merged_srt_candidate = ( if not os.path.exists(chapters_out_dir_candidate) and not clash:
os.path.splitext(merged_file_candidate)[0] + ".srt"
)
if (
not os.path.exists(chapters_out_dir_candidate)
and (
not merge_chapters_at_end
or not os.path.exists(merged_file_candidate)
)
and (
self.subtitle_mode == "Disabled"
or not merge_chapters_at_end
or not os.path.exists(merged_srt_candidate)
)
):
break break
counter += 1 counter += 1
if save_chapters_separately and total_chapters > 1: if save_chapters_separately and total_chapters > 1: