mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-07 20:30:41 -05:00
Add fallback for thumbnails
Workaround for: https://github.com/ytdl-org/youtube-dl/issues/28023 Related: https://github.com/ytdl-org/youtube-dl/pull/28031 Also fixes https://www.reddit.com/r/youtubedl/comments/lfslw1/youtubedlp_with_aria2c_for_dash_support_is/gmolt0r?context=3
This commit is contained in:
parent
deaec5afc2
commit
6c4fd172de
1 changed files with 9 additions and 10 deletions
|
@ -2893,20 +2893,17 @@ def get_encoding(self):
|
||||||
return encoding
|
return encoding
|
||||||
|
|
||||||
def _write_thumbnails(self, info_dict, filename): # return the extensions
|
def _write_thumbnails(self, info_dict, filename): # return the extensions
|
||||||
if self.params.get('writethumbnail', False):
|
write_all = self.params.get('write_all_thumbnails', False)
|
||||||
thumbnails = info_dict.get('thumbnails')
|
thumbnails = []
|
||||||
if thumbnails:
|
if write_all or self.params.get('writethumbnail', False):
|
||||||
thumbnails = [thumbnails[-1]]
|
|
||||||
elif self.params.get('write_all_thumbnails', False):
|
|
||||||
thumbnails = info_dict.get('thumbnails') or []
|
thumbnails = info_dict.get('thumbnails') or []
|
||||||
else:
|
multiple = write_all and len(thumbnails) > 1
|
||||||
thumbnails = []
|
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for t in thumbnails:
|
for t in thumbnails[::1 if write_all else -1]:
|
||||||
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 multiple else ''
|
||||||
thumb_display_id = '%s ' % t['id'] if len(thumbnails) > 1 else ''
|
thumb_display_id = '%s ' % t['id'] if multiple else ''
|
||||||
t['filename'] = thumb_filename = replace_extension(filename, suffix + thumb_ext, info_dict.get('ext'))
|
t['filename'] = thumb_filename = replace_extension(filename, suffix + thumb_ext, info_dict.get('ext'))
|
||||||
|
|
||||||
if not self.params.get('overwrites', True) and os.path.exists(encodeFilename(thumb_filename)):
|
if not self.params.get('overwrites', True) and os.path.exists(encodeFilename(thumb_filename)):
|
||||||
|
@ -2926,4 +2923,6 @@ def _write_thumbnails(self, info_dict, filename): # return the extensions
|
||||||
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||||
self.report_warning('Unable to download thumbnail "%s": %s' %
|
self.report_warning('Unable to download thumbnail "%s": %s' %
|
||||||
(t['url'], error_to_compat_str(err)))
|
(t['url'], error_to_compat_str(err)))
|
||||||
|
if ret and not write_all:
|
||||||
|
break
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Reference in a new issue