refactor: replace executor _slugify with domain sanitize_filename_for_chapter

- Use existing domain function instead of duplicated local implementation
- Domain version includes OS-specific sanitization
This commit is contained in:
Artem Akymenko
2026-07-22 11:06:14 +03:00
parent df5705779e
commit 5f169a4921
+2 -11
View File
@@ -33,6 +33,7 @@ from abogen.domain.conversion_engine import (
synthesize_text,
)
from abogen.domain.normalization import TTSContext
from abogen.domain.output_paths import sanitize_filename_for_chapter
from abogen.infrastructure.subtitle_writer import make_subtitle_writer
@@ -183,7 +184,7 @@ def execute_conversion(
chapter_sink: Optional[AudioSink] = None
chapter_path = None
if chapter_dir:
chapter_filename = _slugify(chapter.title, chapter_idx)
chapter_filename = sanitize_filename_for_chapter(chapter.title, chapter_idx)
chapter_path = chapter_dir / f"{chapter_filename}.{request.separate_chapters_format}"
chapter_sink = stack.enter_context(
open_audio_sink(
@@ -425,16 +426,6 @@ def _base_name(request: Any) -> str:
return "output"
def _slugify(title: str, index: int) -> str:
"""Create a safe filename slug from chapter title."""
import re
slug = re.sub(r'[^\w\s-]', '', title.lower())
slug = re.sub(r'[\s_]+', '_', slug).strip('_')
if not slug:
slug = f"chapter_{index}"
return f"{index:02d}_{slug}"
def _format_heading(title: str, index: int, request: Any) -> str:
"""Format chapter heading for TTS."""
from abogen.domain.chapter_titles import format_spoken_chapter_title