diff options
| author | Robert Honz <exislow+github@gmail.com> | 2025-06-30 16:33:32 +0200 |
|---|---|---|
| committer | Robert Honz <exislow+github@gmail.com> | 2025-06-30 16:33:32 +0200 |
| commit | 70e29771b930fe1a862fdacf58b244f227e017f2 (patch) | |
| tree | f43cd0b021db36a71b53acd6247187fc6919b6fa /tidal_dl_ng/helper/path.py | |
| parent | 0eaeed533fbdc8790413f178cadb73b0ac6949aa (diff) | |
| download | tidal-dl-ng-70e29771b930fe1a862fdacf58b244f227e017f2.tar.gz | |
🛠️ Directory length limit is checked and adapted correctly now. Fixes #447 & #436
Diffstat (limited to 'tidal_dl_ng/helper/path.py')
| -rw-r--r-- | tidal_dl_ng/helper/path.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py index 5f8695a..db0a17c 100644 --- a/tidal_dl_ng/helper/path.py +++ b/tidal_dl_ng/helper/path.py @@ -13,7 +13,13 @@ from tidalapi import Album, Mix, Playlist, Track, UserPlaylist, Video from tidalapi.media import AudioExtensions from tidal_dl_ng import __name_display__ -from tidal_dl_ng.constants import FILENAME_LENGTH_MAX, FILENAME_SANITIZE_PLACEHOLDER, UNIQUIFY_THRESHOLD, MediaType +from tidal_dl_ng.constants import ( + FILENAME_LENGTH_MAX, + FILENAME_SANITIZE_PLACEHOLDER, + FORMAT_TEMPLATE_EXPLICIT, + UNIQUIFY_THRESHOLD, + MediaType, +) from tidal_dl_ng.helper.tidal import name_builder_album_artist, name_builder_artist, name_builder_title @@ -68,7 +74,11 @@ def format_path_media( result_fmt = format_str_media(match.group(1), media, album_track_num_pad_min, list_pos, list_total) if result_fmt != match.group(1): - value = sanitize_filename(result_fmt) + # Sanitize here, in case of the filename has slashes or something, which will be recognized later as a directory separator. + # Do not sanitize if value is the FORMAT_TEMPLATE_EXPLICIT placeholder, since it has a leading whitespace which otherwise gets removed. + value = ( + sanitize_filename(result_fmt) if result_fmt != FORMAT_TEMPLATE_EXPLICIT else FORMAT_TEMPLATE_EXPLICIT + ) result = result.replace(template_str, value) return result @@ -164,10 +174,10 @@ def format_str_media( result = ", ".join(tag for tag in media.media_metadata_tags) case "track_explicit": if isinstance(media, Track | Video): - result = " (Explicit)" if media.explicit else "" + result = FORMAT_TEMPLATE_EXPLICIT if media.explicit else "" case "album_explicit": if isinstance(media, Album): - result = " (Explicit)" if media.explicit else "" + result = FORMAT_TEMPLATE_EXPLICIT if media.explicit else "" case "album_num_volumes": if isinstance(media, Album): result = str(media.num_volumes) @@ -264,6 +274,19 @@ def path_file_sanitize(path_file: pathlib.Path, adapt: bool = False, uniquify: b raise # Sanitize the path. + # First sanitize sanitize each part of the path. Each part of the path is not allowed to be longer then 'PC_NAME_MAX'. + sanitized_parts = [] + + for part in sanitized_path.parts: + if part in sanitized_path.root: + sanitized_parts.append(part) + else: + sanitized_parts.append( + sanitize_filename(part, replacement_text="_", validate_after_sanitize=True, platform="auto") + ) + sanitized_path = pathlib.Path(*sanitized_parts) + + # Then sanitize the whole path itself. The whole path is not allowed to be longer than 'PC_NAME_MAX'. try: sanitized_path: pathlib.Path = sanitize_filepath( sanitized_path, replacement_text="_", validate_after_sanitize=True, platform="auto" |
