mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-01-03 16:26:19 +00:00
Trying to add a thumbnail-format feature
This commit is contained in:
parent
4fb25ff5a3
commit
e3d1f76f0e
@ -182,6 +182,7 @@ class YoutubeDL(object):
|
|||||||
writeannotations: Write the video annotations to a .annotations.xml file
|
writeannotations: Write the video annotations to a .annotations.xml file
|
||||||
writethumbnail: Write the thumbnail image to a file
|
writethumbnail: Write the thumbnail image to a file
|
||||||
write_all_thumbnails: Write all thumbnail formats to files
|
write_all_thumbnails: Write all thumbnail formats to files
|
||||||
|
thumbnailformat: Thumbnail format ID
|
||||||
writesubtitles: Write the video subtitles to a file
|
writesubtitles: Write the video subtitles to a file
|
||||||
writeautomaticsub: Write the automatically generated subtitles to a file
|
writeautomaticsub: Write the automatically generated subtitles to a file
|
||||||
allsubtitles: Downloads all the subtitles of the video
|
allsubtitles: Downloads all the subtitles of the video
|
||||||
@ -2425,8 +2426,24 @@ class YoutubeDL(object):
|
|||||||
|
|
||||||
def _write_thumbnails(self, info_dict, filename):
|
def _write_thumbnails(self, info_dict, filename):
|
||||||
if self.params.get('writethumbnail', False):
|
if self.params.get('writethumbnail', False):
|
||||||
|
def try_and_return_int(s):
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return int(s)
|
||||||
|
except ValueError:
|
||||||
|
return -1
|
||||||
thumbnails = info_dict.get('thumbnails')
|
thumbnails = info_dict.get('thumbnails')
|
||||||
if thumbnails:
|
thumbnailformat = try_and_return_int(self.params.get('thumbnailformat', False))
|
||||||
|
if thumbnailformat:
|
||||||
|
if thumbnailformat in range(len(thumbnails)):
|
||||||
|
thumbnails = [thumbnails[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]]
|
thumbnails = [thumbnails[-1]]
|
||||||
elif self.params.get('write_all_thumbnails', False):
|
elif self.params.get('write_all_thumbnails', False):
|
||||||
thumbnails = info_dict.get('thumbnails')
|
thumbnails = info_dict.get('thumbnails')
|
||||||
|
@ -371,6 +371,7 @@ def _real_main(argv=None):
|
|||||||
'writeannotations': opts.writeannotations,
|
'writeannotations': opts.writeannotations,
|
||||||
'writeinfojson': opts.writeinfojson,
|
'writeinfojson': opts.writeinfojson,
|
||||||
'writethumbnail': opts.writethumbnail,
|
'writethumbnail': opts.writethumbnail,
|
||||||
|
'thumbnailformat': opts.thumbnailformat,
|
||||||
'write_all_thumbnails': opts.write_all_thumbnails,
|
'write_all_thumbnails': opts.write_all_thumbnails,
|
||||||
'writesubtitles': opts.writesubtitles,
|
'writesubtitles': opts.writesubtitles,
|
||||||
'writeautomaticsub': opts.writeautomaticsub,
|
'writeautomaticsub': opts.writeautomaticsub,
|
||||||
|
@ -773,6 +773,10 @@ def parseOpts(overrideArguments=None):
|
|||||||
'--write-thumbnail',
|
'--write-thumbnail',
|
||||||
action='store_true', dest='writethumbnail', default=False,
|
action='store_true', dest='writethumbnail', default=False,
|
||||||
help='Write thumbnail image to disk')
|
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(
|
thumbnail.add_option(
|
||||||
'--write-all-thumbnails',
|
'--write-all-thumbnails',
|
||||||
action='store_true', dest='write_all_thumbnails', default=False,
|
action='store_true', dest='write_all_thumbnails', default=False,
|
||||||
|
Loading…
Reference in New Issue
Block a user