mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 05:40:26 +02:00
Improved chapter filename generation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# v1.0.9 (pre-release)
|
||||
- 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.
|
||||
|
||||
# v1.0.8
|
||||
|
||||
+13
-6
@@ -652,12 +652,19 @@ class ConversionThread(QThread):
|
||||
and chapters_out_dir
|
||||
and chapter_audio_segments
|
||||
):
|
||||
# Sanitize chapter name for use in filenames
|
||||
sanitized_chapter_name = re.sub(r"[^\w\-\. ]", "_", chapter_name)
|
||||
sanitized_chapter_name = re.sub(
|
||||
r"_+", "_", sanitized_chapter_name
|
||||
) # Replace multiple underscores with one
|
||||
chapter_filename = f"{chapter_idx:02d}_{sanitized_chapter_name}"
|
||||
|
||||
# strip any non‐alphanumeric or space/dash
|
||||
sanitized = re.sub(r"[^\w\s\-]", "", chapter_name)
|
||||
# collapse spaces or dashes to single underscore
|
||||
sanitized = re.sub(r"[\s\-]+", "_", sanitized).strip("_")
|
||||
# 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
|
||||
separate_format = getattr(self, 'separate_chapters_format', 'wav')
|
||||
|
||||
Reference in New Issue
Block a user