import re from lyra_worker.types import MBTarget _ILLEGAL = re.compile(r'[<>:"/\\|?*\x00-\x1f]') def safe_name(s: str) -> str: """A filesystem-safe path component (single segment, no separators).""" cleaned = _ILLEGAL.sub("_", s).strip().strip(".").strip() return cleaned or "Unknown" def album_dir(dest_root: str, target: MBTarget) -> str: """`{dest_root}/{safe artist}/{safe album}[ (year)]`.""" album = safe_name(target.album) if target.year: album = f"{album} ({target.year})" return f"{dest_root}/{safe_name(target.artist)}/{album}"