mirror of
https://github.com/nathom/streamrip.git
synced 2024-09-18 18:58:46 -04:00
Fix path too long (#713)
This commit is contained in:
parent
006605ccb3
commit
4c98dbd44e
2 changed files with 10 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue