mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 11:40:57 +02:00
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:
@@ -33,6 +33,7 @@ from abogen.domain.conversion_engine import (
|
|||||||
synthesize_text,
|
synthesize_text,
|
||||||
)
|
)
|
||||||
from abogen.domain.normalization import TTSContext
|
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
|
from abogen.infrastructure.subtitle_writer import make_subtitle_writer
|
||||||
|
|
||||||
|
|
||||||
@@ -183,7 +184,7 @@ def execute_conversion(
|
|||||||
chapter_sink: Optional[AudioSink] = None
|
chapter_sink: Optional[AudioSink] = None
|
||||||
chapter_path = None
|
chapter_path = None
|
||||||
if chapter_dir:
|
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_path = chapter_dir / f"{chapter_filename}.{request.separate_chapters_format}"
|
||||||
chapter_sink = stack.enter_context(
|
chapter_sink = stack.enter_context(
|
||||||
open_audio_sink(
|
open_audio_sink(
|
||||||
@@ -425,16 +426,6 @@ def _base_name(request: Any) -> str:
|
|||||||
return "output"
|
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:
|
def _format_heading(title: str, index: int, request: Any) -> str:
|
||||||
"""Format chapter heading for TTS."""
|
"""Format chapter heading for TTS."""
|
||||||
from abogen.domain.chapter_titles import format_spoken_chapter_title
|
from abogen.domain.chapter_titles import format_spoken_chapter_title
|
||||||
|
|||||||
Reference in New Issue
Block a user