1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-06-27 08:58:30 +00:00
This commit is contained in:
alexandre-piedade-ramos 2025-06-27 00:28:50 +01:00 committed by GitHub
commit 1a2bac358f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 3 deletions

View File

@ -315,6 +315,7 @@ def test_prepend_extension(self):
self.assertEqual(prepend_extension('abc', 'temp'), 'abc.temp')
self.assertEqual(prepend_extension('.abc', 'temp'), '.abc.temp')
self.assertEqual(prepend_extension('.abc.ext', 'temp'), '.abc.temp.ext')
self.assertEqual(prepend_extension('..ext', 'temp', 'temp', True), '..ext.temp.temp')
# Test uncommon extensions
self.assertEqual(prepend_extension('abc.ext', 'bin'), 'abc.bin.ext')

View File

@ -3406,7 +3406,8 @@ def existing_video_file(*filepaths):
file = self.existing_file(itertools.chain(*zip(map(converted, filepaths), filepaths)),
default_overwrite=False)
if file:
info_dict['ext'] = os.path.splitext(file)[1][1:]
real_ext = os.path.splitext(file)[1][1:]
info_dict['ext'] = real_ext if real_ext else info_dict['ext']
return file
fd, success = None, True

View File

@ -706,7 +706,7 @@ def run(self, info):
self.to_screen('There isn\'t any metadata to add')
return [], info
temp_filename = prepend_extension(filename, 'temp')
temp_filename = prepend_extension(filename, 'temp', info['ext'], True)
self.to_screen(f'Adding metadata to "{filename}"')
self.run_ffmpeg_multiple_files(
(filename, metadata_filename), temp_filename,

View File

@ -2122,7 +2122,7 @@ def parse_duration(s):
(days, 86400), (hours, 3600), (mins, 60), (secs, 1), (ms, 1)))
def _change_extension(prepend, filename, ext, expected_real_ext=None):
def _change_extension(prepend, filename, ext, expected_real_ext=None, must_have_ext=False):
name, real_ext = os.path.splitext(filename)
if not expected_real_ext or real_ext[1:] == expected_real_ext:
@ -2131,6 +2131,11 @@ def _change_extension(prepend, filename, ext, expected_real_ext=None):
_UnsafeExtensionError.sanitize_extension(ext, prepend=True)
return f'{filename}.{ext}{real_ext}'
if not real_ext and must_have_ext and expected_real_ext and prepend:
_UnsafeExtensionError.sanitize_extension(ext, prepend=True)
_UnsafeExtensionError.sanitize_extension(expected_real_ext)
return f'{filename}.{ext}.{expected_real_ext}'
return f'{filename}.{_UnsafeExtensionError.sanitize_extension(ext)}'