diff --git a/streamrip/filepath_utils.py b/streamrip/filepath_utils.py index 0613e76..2018954 100644 --- a/streamrip/filepath_utils.py +++ b/streamrip/filepath_utils.py @@ -5,8 +5,15 @@ from pathvalidate import sanitize_filename, sanitize_filepath # type: ignore ALLOWED_CHARS = set(printable) +# TODO: remove this when new pathvalidate release arrives with https://github.com/thombashi/pathvalidate/pull/48 +def truncate_str(text: str) -> str: + str_bytes = text.encode() + str_bytes = str_bytes[:255] + return str_bytes.decode(errors="ignore") + + def clean_filename(fn: str, restrict: bool = False) -> str: - path = str(sanitize_filename(fn)) + path = truncate_str(str(sanitize_filename(fn))) if restrict: path = "".join(c for c in path if c in ALLOWED_CHARS) diff --git a/streamrip/metadata/album.py b/streamrip/metadata/album.py index aa0fb95..6264939 100644 --- a/streamrip/metadata/album.py +++ b/streamrip/metadata/album.py @@ -77,8 +77,8 @@ class AlbumMetadata: "year": self.year, "container": self.info.container, } - - return formatter.format(**info) + + return clean_filename(formatter.format(**info)) @classmethod def from_qobuz(cls, resp: dict) -> AlbumMetadata: