Fix path too long (#713)

This commit is contained in:
Ion Babin 2024-07-07 23:36:16 +03:00 committed by GitHub
parent 006605ccb3
commit 4c98dbd44e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -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)

View file

@ -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: