refactor(download): remove ProviderCore/download.py, move sanitize_filename to SYS.utils, replace callers to use API.HTTP.HTTPClient
This commit is contained in:
18
SYS/utils.py
18
SYS/utils.py
@@ -66,6 +66,24 @@ def sanitize_metadata_value(value: Any) -> str | None:
|
||||
return value
|
||||
|
||||
|
||||
def sanitize_filename(name: str, *, max_len: int = 150) -> str:
|
||||
"""Return a filesystem-safe filename derived from *name*.
|
||||
|
||||
Replaces characters that are invalid on Windows with underscores and
|
||||
collapses whitespace. Trims trailing periods and enforces a max length.
|
||||
"""
|
||||
text = str(name or "").strip()
|
||||
if not text:
|
||||
return "download"
|
||||
|
||||
forbidden = set('<>:"/\\|?*')
|
||||
cleaned = "".join("_" if c in forbidden else c for c in text)
|
||||
cleaned = " ".join(cleaned.split()).strip().strip(".")
|
||||
if not cleaned:
|
||||
cleaned = "download"
|
||||
return cleaned[:max_len]
|
||||
|
||||
|
||||
def unique_preserve_order(values: Iterable[str]) -> list[str]:
|
||||
seen: set[str] = set()
|
||||
ordered: list[str] = []
|
||||
|
||||
Reference in New Issue
Block a user