Improved chapter filename generation

This commit is contained in:
Deniz Şafak
2025-05-28 01:12:38 +03:00
parent ee2999f2cd
commit 010274e703
2 changed files with 14 additions and 6 deletions
+1
View File
@@ -1,5 +1,6 @@
# v1.0.9 (pre-release) # v1.0.9 (pre-release)
- Added chunking/segmenting system that fixes memory outage issues when processing large audio files. - Added chunking/segmenting system that fixes memory outage issues when processing large audio files.
- Improved chapter filename generation with smart word-boundary truncation at 80 characters, preventing mid-word cuts in filenames.
- `Composer` and `Genre` metadata fields for M4B files are now editable from the text editor. - `Composer` and `Genre` metadata fields for M4B files are now editable from the text editor.
# v1.0.8 # v1.0.8
+13 -6
View File
@@ -652,12 +652,19 @@ class ConversionThread(QThread):
and chapters_out_dir and chapters_out_dir
and chapter_audio_segments and chapter_audio_segments
): ):
# Sanitize chapter name for use in filenames
sanitized_chapter_name = re.sub(r"[^\w\-\. ]", "_", chapter_name) # strip any nonalphanumeric or space/dash
sanitized_chapter_name = re.sub( sanitized = re.sub(r"[^\w\s\-]", "", chapter_name)
r"_+", "_", sanitized_chapter_name # collapse spaces or dashes to single underscore
) # Replace multiple underscores with one sanitized = re.sub(r"[\s\-]+", "_", sanitized).strip("_")
chapter_filename = f"{chapter_idx:02d}_{sanitized_chapter_name}" # enforce max length
MAX_LEN = 80
if len(sanitized) > MAX_LEN:
# Find last word boundary before limit
pos = sanitized[:MAX_LEN].rfind("_")
# Use word boundary if found, otherwise use hard limit
sanitized = sanitized[:pos if pos > 0 else MAX_LEN].rstrip("_")
chapter_filename = f"{chapter_idx:02d}_{sanitized}"
# Use separate_chapters_format # Use separate_chapters_format
separate_format = getattr(self, 'separate_chapters_format', 'wav') separate_format = getattr(self, 'separate_chapters_format', 'wav')