New switch --force-write-download-archive instead of modifying the behavior of --download-archive.

This commit is contained in:
Henrik Hank 2018-05-16 07:03:52 +02:00
parent 56688abb4d
commit 6cbe83852f
4 changed files with 24 additions and 16 deletions

View File

@ -7,6 +7,7 @@
"forcethumbnail": false, "forcethumbnail": false,
"forcetitle": false, "forcetitle": false,
"forceurl": false, "forceurl": false,
"force_write_download_archive": false,
"format": "best", "format": "best",
"ignoreerrors": false, "ignoreerrors": false,
"listformats": null, "listformats": null,

View File

@ -162,6 +162,8 @@ class YoutubeDL(object):
forcejson: Force printing info_dict as JSON. forcejson: Force printing info_dict as JSON.
dump_single_json: Force printing the info_dict of the whole playlist dump_single_json: Force printing the info_dict of the whole playlist
(or video) as a single JSON line. (or video) as a single JSON line.
force_write_download_archive: Force writing download archive regardless of
'skip_download' or 'simulate'.
simulate: Do not download the video files. simulate: Do not download the video files.
format: Video format code. See options.py for more information. format: Video format code. See options.py for more information.
outtmpl: Template for output names. outtmpl: Template for output names.
@ -214,9 +216,7 @@ class YoutubeDL(object):
downloaded. None for no limit. downloaded. None for no limit.
download_archive: File name of a file where all downloads are recorded. download_archive: File name of a file where all downloads are recorded.
Videos already present in the file are not downloaded Videos already present in the file are not downloaded
again. When 'writelink' (or similar) and again.
'skip_download' are also present, the videos will be
recorded, too.
cookiefile: File name where cookies should be read from and dumped to. cookiefile: File name where cookies should be read from and dumped to.
nocheckcertificate:Do not verify SSL certificates nocheckcertificate:Do not verify SSL certificates
prefer_insecure: Use HTTP instead of HTTPS to retrieve information. prefer_insecure: Use HTTP instead of HTTPS to retrieve information.
@ -1419,8 +1419,6 @@ class YoutubeDL(object):
raise ExtractorError('Missing "id" field in extractor result') raise ExtractorError('Missing "id" field in extractor result')
if 'title' not in info_dict: if 'title' not in info_dict:
raise ExtractorError('Missing "title" field in extractor result') raise ExtractorError('Missing "title" field in extractor result')
if 'webpage_url' not in info_dict:
raise ExtractorError('Missing "webpage_url" field in extractor result. Should have been augmented with it.')
def report_force_conversion(field, field_not, conversion): def report_force_conversion(field, field_not, conversion):
self.report_warning( self.report_warning(
@ -1751,8 +1749,11 @@ class YoutubeDL(object):
if self.params.get('forcejson', False): if self.params.get('forcejson', False):
self.to_stdout(json.dumps(info_dict)) self.to_stdout(json.dumps(info_dict))
# Do nothing else if in simulate mode
if self.params.get('simulate', False): if self.params.get('simulate', False):
if self.params.get('force_write_download_archive', False):
self.record_download_archive(info_dict)
# Do nothing else if in simulate mode
return return
if filename is None: if filename is None:
@ -1867,6 +1868,9 @@ class YoutubeDL(object):
desktop_link = True desktop_link = True
if url_link or webloc_link or desktop_link: if url_link or webloc_link or desktop_link:
if 'webpage_url' not in info_dict:
self.report_error('Cannot write internet shortcut file because the "webpage_url" field is missing in the media information')
return
ascii_url = iri_to_uri(info_dict['webpage_url']) ascii_url = iri_to_uri(info_dict['webpage_url'])
def _write_link_file(extension, template, newline, embed_filename): def _write_link_file(extension, template, newline, embed_filename):
@ -1896,13 +1900,9 @@ class YoutubeDL(object):
if not _write_link_file('desktop', DESKTOP_LINK_TEMPLATE, '\n', embed_filename=True): if not _write_link_file('desktop', DESKTOP_LINK_TEMPLATE, '\n', embed_filename=True):
return return
if self.params.get('skip_download', False):
# Regarding the download archive, consider internet shortcut creation in conjunction with the `--skip-download` switch as everything the user wants. (See also help for the`--download-archive` switch.)
if url_link or webloc_link or desktop_link:
self.record_download_archive(info_dict)
# Download # Download
else: # No `--skip-download` must_record_download_archive = False
if not self.params.get('skip_download', False):
try: try:
def dl(name, info): def dl(name, info):
fd = get_suitable_downloader(info, self.params)(self, self.params) fd = get_suitable_downloader(info, self.params)(self, self.params)
@ -2049,6 +2049,9 @@ class YoutubeDL(object):
except (PostProcessingError) as err: except (PostProcessingError) as err:
self.report_error('postprocessing: %s' % str(err)) self.report_error('postprocessing: %s' % str(err))
return return
must_record_download_archive = True
if must_record_download_archive or self.params.get('force_write_download_archive', False):
self.record_download_archive(info_dict) self.record_download_archive(info_dict)
def download(self, url_list): def download(self, url_list):

View File

@ -333,6 +333,7 @@ def _real_main(argv=None):
'forceformat': opts.getformat, 'forceformat': opts.getformat,
'forcejson': opts.dumpjson or opts.print_json, 'forcejson': opts.dumpjson or opts.print_json,
'dump_single_json': opts.dump_single_json, 'dump_single_json': opts.dump_single_json,
'force_write_download_archive': opts.force_write_download_archive,
'simulate': opts.simulate or any_getting, 'simulate': opts.simulate or any_getting,
'skip_download': opts.skip_download, 'skip_download': opts.skip_download,
'format': opts.format, 'format': opts.format,

View File

@ -343,7 +343,7 @@ def parseOpts(overrideArguments=None):
selection.add_option( selection.add_option(
'--download-archive', metavar='FILE', '--download-archive', metavar='FILE',
dest='download_archive', dest='download_archive',
help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it. When the switches --write-link (or similar) and --skip-download are used additionally, the IDs will also be recorded, even though nothing was actually downloaded.') help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
selection.add_option( selection.add_option(
'--include-ads', '--include-ads',
dest='include_ads', action='store_true', dest='include_ads', action='store_true',
@ -633,8 +633,11 @@ def parseOpts(overrideArguments=None):
verbosity.add_option( verbosity.add_option(
'--print-json', '--print-json',
action='store_true', dest='print_json', default=False, action='store_true', dest='print_json', default=False,
help='Be quiet and print the video information as JSON (video is still being downloaded).', help='Be quiet and print the video information as JSON (video is still being downloaded).')
) verbosity.add_option(
'--force-write-download-archive',
action='store_true', dest='force_write_download_archive', default=False,
help='Force download archive entries to be written as far as no errors occur, even though --skip-download or any simulation switch is used.')
verbosity.add_option( verbosity.add_option(
'--newline', '--newline',
action='store_true', dest='progress_with_newline', default=False, action='store_true', dest='progress_with_newline', default=False,