mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-26 21:59:08 +01:00
Don't change sort function
This commit is contained in:
parent
afe35b43fa
commit
1bfc5b5927
2 changed files with 21 additions and 10 deletions
|
@ -2606,7 +2606,6 @@ class YoutubeDL:
|
|||
|
||||
def _sort_thumbnails(self, thumbnails):
|
||||
thumbnails.sort(key=lambda t: (
|
||||
t.get('id') == self.params.get('thumbnail_format') if t.get('id') is not None else False,
|
||||
t.get('preference') if t.get('preference') is not None else -1,
|
||||
t.get('width') if t.get('width') is not None else -1,
|
||||
t.get('height') if t.get('height') is not None else -1,
|
||||
|
@ -2632,12 +2631,6 @@ class YoutubeDL:
|
|||
continue
|
||||
yield t
|
||||
|
||||
thumbnail_id = self.params.get('thumbnail_format')
|
||||
if thumbnail_id and thumbnail_id not in [t.get('id') for t in thumbnails]:
|
||||
self.raise_no_formats(info_dict, msg=(
|
||||
'Invalid thumbnail ID specified. '
|
||||
'Use --list-thumbnails to see available IDs'))
|
||||
|
||||
self._sort_thumbnails(thumbnails)
|
||||
for i, t in enumerate(thumbnails):
|
||||
if t.get('id') is None:
|
||||
|
@ -4371,9 +4364,24 @@ class YoutubeDL:
|
|||
def _write_thumbnails(self, label, info_dict, filename, thumb_filename_base=None):
|
||||
""" Write thumbnails to file and return list of (thumb_filename, final_thumb_filename); or None if error """
|
||||
write_all = self.params.get('write_all_thumbnails', False)
|
||||
write_any = write_all or self.params.get('writethumbnail', False)
|
||||
thumbnails, ret = [], []
|
||||
if write_all or self.params.get('writethumbnail', False):
|
||||
thumbnails = info_dict.get('thumbnails') or []
|
||||
|
||||
if write_any:
|
||||
all_thumbnails = info_dict.get('thumbnails') or []
|
||||
thumbnail_id = self.params.get('thumbnail_format')
|
||||
if thumbnail_id and not write_all:
|
||||
for t in all_thumbnails:
|
||||
if t.get('id') == thumbnail_id:
|
||||
thumbnails.append(t)
|
||||
break
|
||||
else:
|
||||
self.raise_no_formats(
|
||||
info_dict, msg=('Invalid thumbnail ID specified. Use --list-thumbnails to see available IDs'),
|
||||
)
|
||||
else:
|
||||
thumbnails = all_thumbnails
|
||||
|
||||
if not thumbnails:
|
||||
self.to_screen(f'[info] There are no {label} thumbnails to download')
|
||||
return ret
|
||||
|
|
|
@ -62,6 +62,9 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||
self.to_screen('There aren\'t any thumbnails to embed')
|
||||
return [], info
|
||||
|
||||
if self._downloader and (fmt := self._downloader.params.get('thumbnail_format')):
|
||||
idx = next((i for i, t in enumerate(info['thumbnails']) if t.get('id') == fmt and t.get('filepath')), None)
|
||||
else:
|
||||
idx = next((-i for i, t in enumerate(info['thumbnails'][::-1], 1) if t.get('filepath')), None)
|
||||
if idx is None:
|
||||
self.to_screen('There are no thumbnails on disk')
|
||||
|
|
Loading…
Reference in a new issue