diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 9e5620eef..3510554d7 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -214,6 +214,7 @@ class YoutubeDL(object): writeannotations: Write the video annotations to a .annotations.xml file writethumbnail: Write the thumbnail image to a file write_all_thumbnails: Write all thumbnail formats to files + thumbnailformat: Thumbnail format ID writesubtitles: Write the video subtitles to a file writeautomaticsub: Write the automatically generated subtitles to a file allsubtitles: Downloads all the subtitles of the video @@ -2681,8 +2682,18 @@ class YoutubeDL(object): def _write_thumbnails(self, info_dict, filename): if self.params.get('writethumbnail', False): thumbnails = info_dict.get('thumbnails') + thumbnailformat = self.params.get('thumbnailformat', False) if thumbnails: - thumbnails = [thumbnails[-1]] + if thumbnailformat: + if thumbnailformat in [i.get('id') for i in thumbnails]: + thumbnails = [i for i in thumbnails if i.get('id') == thumbnailformat] + else: + self.report_warning('Thumbnail ID unavailable, falling back to default.' + ' Check available thumbnail formats with the option --list-thumbnails' + ) + thumbnails = [thumbnails[-1]] + else: + thumbnails = [thumbnails[-1]] elif self.params.get('write_all_thumbnails', False): thumbnails = info_dict.get('thumbnails') else: diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 06bdfb689..2b9596248 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -373,6 +373,7 @@ def _real_main(argv=None): 'writeannotations': opts.writeannotations, 'writeinfojson': opts.writeinfojson, 'writethumbnail': opts.writethumbnail, + 'thumbnailformat': opts.thumbnailformat, 'write_all_thumbnails': opts.write_all_thumbnails, 'writesubtitles': opts.writesubtitles, 'writeautomaticsub': opts.writeautomaticsub, diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 61705d1f0..c3ed069a1 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -781,6 +781,10 @@ def parseOpts(overrideArguments=None): '--write-thumbnail', action='store_true', dest='writethumbnail', default=False, help='Write thumbnail image to disk') + thumbnail.add_option( + '--thumbnail-format', + action='store', dest='thumbnailformat', metavar='ID', default=None, + help='Thumbnail format ID') thumbnail.add_option( '--write-all-thumbnails', action='store_true', dest='write_all_thumbnails', default=False,