Skip to content

Commit

Permalink
pathvalidate library is currently not able to shorten filenames. …
Browse files Browse the repository at this point in the history
…Implemented a hacky workaround for now. Fixes #91
  • Loading branch information
exislow committed Apr 21, 2024
1 parent f9862e0 commit 6716686
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tidal_dl_ng/helper/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,17 @@ def path_file_sanitize(path_file: str, adapt: bool = False, uniquify: bool = Fal
filename_sanitized = filename_sanitized[: -len(file_suffix)] + file_suffix
except ValidationError as e:
# TODO: Implement proper exception handling and logging.
print(e)

raise
# print(e)
# Hacky stuff, since the sanitizing function does not shorten the filename somehow (bug?)
# Remove after pathvalidate update.
# If filename too long
if e.description.startswith("[PV1101]"):
byte_ct: int = len(filename.encode("utf-8")) - 255
filename_sanitized = (
filename[: -byte_ct - len(FILENAME_SANITIZE_PLACEHOLDER) - len(file_extension)]
+ FILENAME_SANITIZE_PLACEHOLDER
+ file_extension
)

# Join path and filename
result: str = os.path.join(pathname_sanitized, filename_sanitized)
Expand Down

0 comments on commit 6716686

Please sign in to comment.