Allow --trim-filenames=0 and update tests

This commit is contained in:
7x11x13 2025-01-07 14:50:44 -05:00
parent fa6e2f83aa
commit 1e82fe3bfe
2 changed files with 10 additions and 4 deletions

View File

@ -717,7 +717,7 @@ class TestYoutubeDL(unittest.TestCase):
ydl._num_downloads = 1
self.assertEqual(ydl.validate_outtmpl(tmpl), None)
out = ydl.evaluate_outtmpl(tmpl, info or self.outtmpl_info)
out = ydl.evaluate_outtmpl_for_filename(tmpl, info or self.outtmpl_info)
fname = ydl.prepare_filename(info or self.outtmpl_info)
if not isinstance(expected, (list, tuple)):
@ -791,7 +791,7 @@ class TestYoutubeDL(unittest.TestCase):
self.assertEqual(got_dict.get(info_field), expected, info_field)
return True
test('%()j', (expect_same_infodict, None))
test('%()j', (expect_same_infodict, None), trim_file_name=0)
# NA placeholder
NA_TEST_OUTTMPL = '%(uploader_date)s-%(width)d-%(x|def)s-%(id)s.%(ext)s'

View File

@ -1458,10 +1458,16 @@ class YoutubeDL:
else:
raise ValueError("--trim-filenames must end with 'b' or 'c'")
max_file_name = self.params.get('trim_file_name') or DEFAULT_MAX_FILE_NAME
max_file_name = self.params.get('trim_file_name')
if max_file_name is None:
max_file_name = DEFAULT_MAX_FILE_NAME
mode, max_file_name = parse_max_file_name(max_file_name)
if max_file_name < 1:
if max_file_name < 0:
raise ValueError('Invalid --trim-filenames specified')
if max_file_name == 0:
# no maximum
return filename + suffix
encoding = self.params.get('filesystem_encoding') or sys.getfilesystemencoding()
def trim_filename(name: str, length: int):