refactor: word substitution in planner, add planner tests

This commit is contained in:
Artem Akymenko
2026-07-24 19:17:37 +03:00
parent 0ee5bb0496
commit a1241ee9ca
2 changed files with 76 additions and 5 deletions
+21 -4
View File
@@ -82,16 +82,33 @@ def _extract_source_text(request: ConversionRequest) -> Optional[str]:
from abogen.subtitle_utils import clean_text
if request.direct_text:
return clean_text(request.direct_text)
if request.source_path and request.source_path.exists():
text = clean_text(request.direct_text)
elif request.source_path and request.source_path.exists():
encoding = "utf-8"
try:
with open(request.source_path, "r", encoding=encoding, errors="replace") as f:
text = f.read()
except Exception:
return None
return clean_text(text)
return None
text = clean_text(text)
else:
return None
# Apply word substitutions if configured
if request.word_substitution:
from abogen.word_substitution import apply_word_substitutions
ws = request.word_substitution
text = apply_word_substitutions(
text,
ws.substitutions_list,
ws.case_sensitive,
ws.replace_caps,
ws.replace_numerals,
ws.fix_punctuation,
)
return text
def _extract_metadata(request: ConversionRequest) -> Dict[str, Any]: