diff --git a/picard/util/__init__.py b/picard/util/__init__.py index 3188e17c9..c7419128e 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -203,12 +203,20 @@ _re_slashes = re.compile(r'[\\/]', re.UNICODE) def sanitize_filename(string, repl="_"): return _re_slashes.sub(repl, string) -def make_short_filename(prefix, filename, length=240, max_length=200, +def make_short_filename(prefix, filename, max_path_length=240, max_length=200, mid_length=32, min_length=2): + """ + Attempts to shorten the file name to the maximum allowed length. + + max_path_length: The maximum length of the complete path. + max_length: The maximum length of a single file or directory name. + mid_length: The medium preferred length of a single file or directory. + min_length: The minimum allowed length of a single file or directory. + """ parts = [part.strip() for part in _re_slashes.split(filename)] parts.reverse() filename = os.path.join(*parts) - left = len(prefix) + len(filename) + 1 - length + left = len(prefix) + len(filename) + 1 - max_path_length for i in range(len(parts)): left -= max(0, len(parts[i]) - max_length)