From acc0d6a411aba58f008e547eb81b4e9e3398d284 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 6 Dec 2021 23:26:34 +0530 Subject: [PATCH] Allow `--no-write-thumbnail` to override `--write-all-thumbnail` Closes #1900 --- yt_dlp/__init__.py | 9 ++++----- yt_dlp/options.py | 7 +++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.py index 91a01c38f..5d20ad8c3 100644 --- a/yt_dlp/__init__.py +++ b/yt_dlp/__init__.py @@ -559,13 +559,12 @@ def _real_main(argv=None): '_from_cli': True, }) if opts.embedthumbnail: - already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails postprocessors.append({ 'key': 'EmbedThumbnail', # already_have_thumbnail = True prevents the file from being deleted after embedding - 'already_have_thumbnail': already_have_thumbnail + 'already_have_thumbnail': opts.writethumbnail }) - if not already_have_thumbnail: + if not opts.writethumbnail: opts.writethumbnail = True opts.outtmpl['pl_thumbnail'] = '' if opts.split_chapters: @@ -695,8 +694,8 @@ def _real_main(argv=None): 'allow_playlist_files': opts.allow_playlist_files, 'clean_infojson': opts.clean_infojson, 'getcomments': opts.getcomments, - 'writethumbnail': opts.writethumbnail, - 'write_all_thumbnails': opts.write_all_thumbnails, + 'writethumbnail': opts.writethumbnail is True, + 'write_all_thumbnails': opts.writethumbnail == 'all', 'writelink': opts.writelink, 'writeurllink': opts.writeurllink, 'writewebloclink': opts.writewebloclink, diff --git a/yt_dlp/options.py b/yt_dlp/options.py index d20f65e99..bb421e0f8 100644 --- a/yt_dlp/options.py +++ b/yt_dlp/options.py @@ -1187,7 +1187,10 @@ def parseOpts(overrideArguments=None): thumbnail = optparse.OptionGroup(parser, 'Thumbnail Options') thumbnail.add_option( '--write-thumbnail', - action='store_true', dest='writethumbnail', default=False, + action='callback', dest='writethumbnail', default=False, + # Should override --no-write-thumbnail, but not --write-all-thumbnail + callback=lambda option, _, __, parser: setattr( + parser.values, option.dest, getattr(parser.values, option.dest) or True), help='Write thumbnail image to disk') thumbnail.add_option( '--no-write-thumbnail', @@ -1195,7 +1198,7 @@ def parseOpts(overrideArguments=None): help='Do not write thumbnail image to disk (default)') thumbnail.add_option( '--write-all-thumbnails', - action='store_true', dest='write_all_thumbnails', default=False, + action='store_const', dest='writethumbnail', const='all', help='Write all thumbnail image formats to disk') thumbnail.add_option( '--list-thumbnails',