diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-05-29 01:38:02 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-05-29 02:31:14 +0530 |
commit | 885cc0b75c3ef3ef46fa476746bd34381fd9446d (patch) | |
tree | 11f3e560051049433502ec8de04627a242816619 | |
parent | 46953e7e6e2cf6da008d9747d7459b60931d0651 (diff) | |
download | hypervideo-pre-885cc0b75c3ef3ef46fa476746bd34381fd9446d.tar.lz hypervideo-pre-885cc0b75c3ef3ef46fa476746bd34381fd9446d.tar.xz hypervideo-pre-885cc0b75c3ef3ef46fa476746bd34381fd9446d.zip |
[embedthumbnail] Embed if any thumbnail was downloaded, not just the best
-rw-r--r-- | yt_dlp/YoutubeDL.py | 3 | ||||
-rw-r--r-- | yt_dlp/postprocessor/common.py | 2 | ||||
-rw-r--r-- | yt_dlp/postprocessor/embedthumbnail.py | 12 |
3 files changed, 11 insertions, 6 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index aa0a77d15..b67da9f08 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -3232,7 +3232,7 @@ class YoutubeDL(object): thumb_ext = determine_ext(t['url'], 'jpg') suffix = '%s.' % t['id'] if multiple else '' thumb_display_id = '%s ' % t['id'] if multiple else '' - t['filepath'] = thumb_filename = replace_extension(filename, suffix + thumb_ext, info_dict.get('ext')) + 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)): ret.append(suffix + thumb_ext) @@ -3248,6 +3248,7 @@ class YoutubeDL(object): ret.append(suffix + thumb_ext) self.to_screen('[%s] %s: Writing thumbnail %sto: %s' % (info_dict['extractor'], info_dict['id'], thumb_display_id, thumb_filename)) + t['filepath'] = thumb_filename except network_exceptions as err: self.report_warning('Unable to download thumbnail "%s": %s' % (t['url'], error_to_compat_str(err))) diff --git a/yt_dlp/postprocessor/common.py b/yt_dlp/postprocessor/common.py index b01ba5ee0..b6d06f33f 100644 --- a/yt_dlp/postprocessor/common.py +++ b/yt_dlp/postprocessor/common.py @@ -100,7 +100,7 @@ class PostProcessor(object): else: use_compat = False return cli_configuration_args( - self._downloader.params.get('postprocessor_args'), + self.get_param('postprocessor_args'), keys, default, use_compat) diff --git a/yt_dlp/postprocessor/embedthumbnail.py b/yt_dlp/postprocessor/embedthumbnail.py index 2d736a31a..f3eb7d96d 100644 --- a/yt_dlp/postprocessor/embedthumbnail.py +++ b/yt_dlp/postprocessor/embedthumbnail.py @@ -70,16 +70,20 @@ class EmbedThumbnailPP(FFmpegPostProcessor): self.to_screen('There aren\'t any thumbnails to embed') return [], info - thumbnail_filename = info['thumbnails'][-1]['filepath'] + idx = next((-(i+1) for i, t in enumerate(info['thumbnails'][::-1]) if t.get('filepath')), None) + if idx is None: + self.to_screen('There are no thumbnails on disk') + return [], info + thumbnail_filename = info['thumbnails'][idx]['filepath'] if not os.path.exists(encodeFilename(thumbnail_filename)): self.report_warning('Skipping embedding the thumbnail because the file is missing.') return [], info # Correct extension for WebP file with wrong extension (see #25687, #25717) convertor = FFmpegThumbnailsConvertorPP(self._downloader) - convertor.fixup_webp(info, -1) + convertor.fixup_webp(info, idx) - original_thumbnail = thumbnail_filename = info['thumbnails'][-1]['filepath'] + original_thumbnail = thumbnail_filename = info['thumbnails'][idx]['filepath'] # Convert unsupported thumbnail formats to PNG (see #25687, #25717) # Original behavior was to convert to JPG, but since JPG is a lossy @@ -199,7 +203,7 @@ class EmbedThumbnailPP(FFmpegPostProcessor): with open(thumbnail_filename, 'rb') as thumbfile: pic.data = thumbfile.read() pic.type = 3 # front cover - res = self._get_thumbnail_resolution(thumbnail_filename, info['thumbnails'][-1]) + res = self._get_thumbnail_resolution(thumbnail_filename, info['thumbnails'][idx]) if res is not None: pic.width, pic.height = res |