1
1
mirror of https://github.com/ytdl-org/youtube-dl synced 2024-11-09 05:37:09 +01:00
This commit is contained in:
Deleted user 2024-07-28 01:28:14 +09:00 committed by GitHub
commit 6326864d7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2692,11 +2692,18 @@ class YoutubeDL(object):
# No thumbnails present, so return immediately # No thumbnails present, so return immediately
return return
def make_thumb_filename(filename, suffix, thumb_ext, file_ext):
thumb_filename = replace_extension(filename, thumb_ext, file_ext)
if suffix:
name, ext = os.path.splitext(thumb_filename)
thumb_filename = name + suffix + ext
return thumb_filename
for t in thumbnails: for t in thumbnails:
thumb_ext = determine_ext(t['url'], 'jpg') thumb_ext = determine_ext(t['url'], 'jpg')
suffix = '_%s' % t['id'] if len(thumbnails) > 1 else '' suffix = '_%s' % t['id'] if len(thumbnails) > 1 else ''
thumb_display_id = '%s ' % t['id'] if len(thumbnails) > 1 else '' thumb_display_id = '%s ' % t['id'] if len(thumbnails) > 1 else ''
t['filename'] = thumb_filename = replace_extension(filename + suffix, thumb_ext, info_dict.get('ext')) t['filename'] = thumb_filename = make_thumb_filename(filename, suffix, thumb_ext, info_dict.get('ext'))
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(thumb_filename)): if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(thumb_filename)):
self.to_screen('[%s] %s: Thumbnail %sis already present' % self.to_screen('[%s] %s: Thumbnail %sis already present' %
@ -2706,6 +2713,15 @@ class YoutubeDL(object):
(info_dict['extractor'], info_dict['id'], thumb_display_id)) (info_dict['extractor'], info_dict['id'], thumb_display_id))
try: try:
uf = self.urlopen(t['url']) uf = self.urlopen(t['url'])
if uf.headers.get('Content-Type', '').startswith('image/webp') and thumb_ext.lower() != 'webp':
self.to_screen('[%s] %s: Set thumbnail %sextension to "webp" according to "Content-Type" header' %
(info_dict['extractor'], info_dict['id'], thumb_display_id))
t['filename'] = thumb_filename = make_thumb_filename(
filename, suffix, 'webp', info_dict.get('ext'))
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(thumb_filename)):
self.to_screen('[%s] %s: Thumbnail %sis already present' %
(info_dict['extractor'], info_dict['id'], thumb_display_id))
continue
with open(encodeFilename(thumb_filename), 'wb') as thumbf: with open(encodeFilename(thumb_filename), 'wb') as thumbf:
shutil.copyfileobj(uf, thumbf) shutil.copyfileobj(uf, thumbf)
self.to_screen('[%s] %s: Writing thumbnail %sto: %s' % self.to_screen('[%s] %s: Writing thumbnail %sto: %s' %