Preserve appended ID when shortening file names

This commit is contained in:
Serene-Arc
2021-03-26 21:38:04 +10:00
committed by Ali Parlakci
parent 1cb8240eb6
commit 3cb51e638b
2 changed files with 20 additions and 0 deletions

View File

@@ -65,6 +65,9 @@ class FileNameFormatter:
@staticmethod
def _limit_file_name_length(filename: str, ending: str) -> str:
possible_id = re.search(r'((?:_\w{6})?$)', filename).group(1)
ending = possible_id + ending
filename = filename.strip(possible_id)
max_length_chars = 255 - len(ending)
max_length_bytes = 255 - len(ending.encode('utf-8'))
while len(filename) > max_length_chars or len(filename.encode('utf-8')) > max_length_bytes: