diff options
| author | Robert Honz <exislow+github@gmail.com> | 2024-04-21 17:35:22 +0200 |
|---|---|---|
| committer | Robert Honz <exislow+github@gmail.com> | 2024-04-21 17:35:22 +0200 |
| commit | 67166861e954e8f899374e4b223ffa11926142e2 (patch) | |
| tree | 62c88e4980d95dfe070206dc67b7b3294c9196ce /tidal_dl_ng/helper | |
| parent | f9862e0646032628923dc696afb0fe04884eddfb (diff) | |
| download | tidal-dl-ng-67166861e954e8f899374e4b223ffa11926142e2.tar.gz | |
✨ `pathvalidate` library is currently not able to shorten filenames. Implemented a hacky workaround for now. Fixes #91
Diffstat (limited to 'tidal_dl_ng/helper')
| -rw-r--r-- | tidal_dl_ng/helper/path.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py index e857801..b79d08e 100644 --- a/tidal_dl_ng/helper/path.py +++ b/tidal_dl_ng/helper/path.py @@ -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) |
