[pp/FFmpegThumbnailsConvertor] Correct the extension of all thumbnails

pull/13752/head
Joaquim Monteiro 1 month ago
parent c1ac543c81
commit 617d9fa80f
No known key found for this signature in database
GPG Key ID: D22C1EE6990BF1B3

@ -73,7 +73,7 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
# Correct extension for WebP file with wrong extension (see #25687, #25717) # Correct extension for WebP file with wrong extension (see #25687, #25717)
convertor = FFmpegThumbnailsConvertorPP(self._downloader) convertor = FFmpegThumbnailsConvertorPP(self._downloader)
convertor.fixup_webp(info, idx) convertor.fixup_thumbnail_ext(info, idx)
original_thumbnail = thumbnail_filename = info['thumbnails'][idx]['filepath'] original_thumbnail = thumbnail_filename = info['thumbnails'][idx]['filepath']

@ -1081,17 +1081,21 @@ class FFmpegThumbnailsConvertorPP(FFmpegPostProcessor):
deprecation_warning(f'{cls.__module__}.{cls.__name__}.is_webp is deprecated') deprecation_warning(f'{cls.__module__}.{cls.__name__}.is_webp is deprecated')
return imghdr.what(path) == 'webp' return imghdr.what(path) == 'webp'
def fixup_webp(self, info, idx=-1): def fixup_thumbnail_ext(self, info, idx=-1):
thumbnail_filename = info['thumbnails'][idx]['filepath'] thumbnail_filename = info['thumbnails'][idx]['filepath']
actual_format = imghdr.what(thumbnail_filename)
if not actual_format:
return
_, thumbnail_ext = os.path.splitext(thumbnail_filename) _, thumbnail_ext = os.path.splitext(thumbnail_filename)
if thumbnail_ext: thumbnail_ext = thumbnail_ext.removeprefix('.').lower()
if thumbnail_ext.lower() != '.webp' and imghdr.what(thumbnail_filename) == 'webp': if thumbnail_ext != actual_format and not (actual_format == 'jpeg' and thumbnail_ext == 'jpg'):
self.to_screen(f'Correcting thumbnail "{thumbnail_filename}" extension to webp') self.to_screen(f'Correcting thumbnail "{thumbnail_filename}" extension to {actual_format}')
webp_filename = replace_extension(thumbnail_filename, 'webp') correct_filename = replace_extension(thumbnail_filename, actual_format)
os.replace(thumbnail_filename, webp_filename) os.replace(thumbnail_filename, correct_filename)
info['thumbnails'][idx]['filepath'] = webp_filename info['thumbnails'][idx]['filepath'] = correct_filename
info['__files_to_move'][webp_filename] = replace_extension( info['__files_to_move'][correct_filename] = replace_extension(
info['__files_to_move'].pop(thumbnail_filename), 'webp') info['__files_to_move'].pop(thumbnail_filename), actual_format)
@staticmethod @staticmethod
def _options(target_ext): def _options(target_ext):
@ -1118,7 +1122,7 @@ class FFmpegThumbnailsConvertorPP(FFmpegPostProcessor):
if not original_thumbnail: if not original_thumbnail:
continue continue
has_thumbnail = True has_thumbnail = True
self.fixup_webp(info, idx) self.fixup_thumbnail_ext(info, idx)
original_thumbnail = thumbnail_dict['filepath'] # Path can change during fixup original_thumbnail = thumbnail_dict['filepath'] # Path can change during fixup
thumbnail_ext = os.path.splitext(original_thumbnail)[1][1:].lower() thumbnail_ext = os.path.splitext(original_thumbnail)[1][1:].lower()
if thumbnail_ext == 'jpeg': if thumbnail_ext == 'jpeg':

Loading…
Cancel
Save