import re from unidecode import unidecode def extract_video_id(url: str) -> str: match = re.search(r"(?:v=|youtu\.be/)([A-Za-z0-9_-]{11})", url) if not match: raise ValueError("URL inválida do YouTube") return match.group(1) def sanitize_title(s: str) -> str: s = unidecode(s or "video") s = re.sub(r"[^\w\s-]", "", s).strip() return re.sub(r"_+", "_", re.sub(r"\s+", "_", s)) or "video"