From b3ed18acaf21068ed0c2f7291f3ff8d455585f8d Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Mon, 24 Mar 2025 08:22:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Fixed:=20Skip=20file=20?= =?UTF-8?q?is=20not=20ignored=20anymore.=20Filenames=20will=20not=20be=20u?= =?UTF-8?q?niquified=20by=20default.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/helper/path.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py index 700cb68..f138208 100644 --- a/tidal_dl_ng/helper/path.py +++ b/tidal_dl_ng/helper/path.py @@ -204,7 +204,7 @@ def get_format_template( return result -def path_file_sanitize(path_file: pathlib.Path, adapt: bool = False, uniquify: bool = True) -> pathlib.Path: +def path_file_sanitize(path_file: pathlib.Path, adapt: bool = False, uniquify: bool = False) -> pathlib.Path: # Get each directory name separately (first value in tuple; second value is for the file suffix). to_sanitize: [[str, str]] = path_split_parts_suffix(path_file) sanitized_path_file: pathlib.Path = pathlib.Path(to_sanitize.pop(0)[0]) @@ -257,21 +257,34 @@ def path_file_sanitize(path_file: pathlib.Path, adapt: bool = False, uniquify: b # Uniquify if uniquify: - unique_suffix: str = file_unique_suffix(sanitized_path_file) - - if unique_suffix: - file_suffix = unique_suffix + sanitized_path_file.suffix - # For most OS filename has a character limit of 255. - sanitized_path_file = ( - sanitized_path_file.parent / (str(sanitized_path_file.stem)[: -len(file_suffix)] + file_suffix) - if len(str(sanitized_path_file.parent / (sanitized_path_file.stem + unique_suffix))) - > FILENAME_LENGTH_MAX - else sanitized_path_file.parent / (sanitized_path_file.stem + unique_suffix) - ) + sanitized_path_file = path_file_uniquify(sanitized_path_file) return sanitized_path_file +def path_file_uniquify(path_file: pathlib.Path) -> pathlib.Path: + """Checks whether the file exists, if so it tries to return an unique name suffix. + + :param path_file: Path to file name which shall be unique. + :type path_file: pathlib.Path + :return: Unique file name with path for given input. + :rtype: pathlib.Path + """ + unique_suffix: str = file_unique_suffix(path_file) + + if unique_suffix: + file_suffix = unique_suffix + path_file.suffix + # For most OS filename has a character limit of 255. + path_file = ( + path_file.parent / (str(path_file.stem)[: -len(file_suffix)] + file_suffix) + if len(str(path_file.parent / (path_file.stem + unique_suffix))) + > FILENAME_LENGTH_MAX + else path_file.parent / (path_file.stem + unique_suffix) + ) + + return path_file + + def file_unique_suffix(path_file: pathlib.Path, seperator: str = "_") -> str: threshold_zfill: int = len(str(UNIQUIFY_THRESHOLD)) count: int = 0