2812695465
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
20 lines
580 B
Python
20 lines
580 B
Python
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}"
|