Skip to content

Commit

Permalink
Fix path too long (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
owhyy authored Jul 7, 2024
1 parent 006605c commit 4c98dbd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion streamrip/filepath_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
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)

Expand Down
4 changes: 2 additions & 2 deletions streamrip/metadata/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def format_folder_path(self, formatter: str) -> str:
"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:
Expand Down

0 comments on commit 4c98dbd

Please sign in to comment.