Added --skip-empty-annotations to be used with write annotations. Will not save annotation if none exist in video

This commit is contained in:
Edward 2018-12-22 21:12:07 -05:00
parent e1a0628797
commit 992c3b862a
3 changed files with 10 additions and 1 deletions

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
@ -314,7 +315,8 @@ class YoutubeDL(object):
The following options are used by the Youtube extractor:
youtube_include_dash_manifest: If True (default), DASH manifests and related
data will be downloaded and processed by extractor.
You can reduce network I/O by disabling it if you don't
You can reduce network I/O by disabling it if you don't
care about DASH.
"""
@ -1777,6 +1779,8 @@ class YoutubeDL(object):
annofn = replace_extension(filename, 'annotations.xml', info_dict.get('ext'))
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(annofn)):
self.to_screen('[info] Video annotations are already present')
elif not '<annotation id=' in info_dict['annotations'] and self.params.get('writefullannotations', False):
self.to_screen('[info] Annotation file is empty. Skipping')
else:
try:
self.to_screen('[info] Writing video annotations to: ' + annofn)

View File

@ -365,6 +365,7 @@ def _real_main(argv=None):
'nopart': opts.nopart,
'updatetime': opts.updatetime,
'writedescription': opts.writedescription,
'writefullannotations': opts.writefullannotations,
'writeannotations': opts.writeannotations,
'writeinfojson': opts.writeinfojson,
'writethumbnail': opts.writethumbnail,

View File

@ -741,6 +741,10 @@ def parseOpts(overrideArguments=None):
'--write-info-json',
action='store_true', dest='writeinfojson', default=False,
help='Write video metadata to a .info.json file')
filesystem.add_option(
'--skip-empty-annotations',
action='store_true', dest='writefullannotations', default=False,
help='Used with --write-annotations. Will not save annotation file if there are no annotations')
filesystem.add_option(
'--write-annotations',
action='store_true', dest='writeannotations', default=False,