Initial commit: InkFlow — EPUB vers livre audio local (MLX/Kokoro)
This commit is contained in:
22
backend/inkflow/util.py
Normal file
22
backend/inkflow/util.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Petits utilitaires partages (slug, noms de fichiers surs)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
_SLUG_STRIP = re.compile(r"[^a-z0-9]+")
|
||||
_FS_UNSAFE = re.compile(r'[<>:"/\\|?*\x00-\x1f]')
|
||||
|
||||
|
||||
def slugify(text: str) -> str:
|
||||
"""Slug ascii minuscule, utilise pour les identifiants de dossiers internes."""
|
||||
norm = unicodedata.normalize("NFKD", text)
|
||||
norm = norm.encode("ascii", "ignore").decode("ascii").lower()
|
||||
return _SLUG_STRIP.sub("-", norm).strip("-") or "livre"
|
||||
|
||||
|
||||
def safe_filename(name: str) -> str:
|
||||
"""Nettoie un nom de fichier en conservant les accents (sortie utilisateur)."""
|
||||
name = _FS_UNSAFE.sub("", name).strip()
|
||||
name = re.sub(r"\s+", " ", name)
|
||||
return name or "sans-titre"
|
||||
Reference in New Issue
Block a user