From fdceeb43ced3c5f6ff58dae2cadbb30f031f42ce Mon Sep 17 00:00:00 2001 From: Yoav Shai Date: Thu, 18 Oct 2018 17:12:37 +0300 Subject: [PATCH 1/2] Add break on existing option --- README.md | 2 ++ youtube_dl/YoutubeDL.py | 8 +++++++- youtube_dl/options.py | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fdd115c9b..a49067cfd 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,8 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo --download-archive FILE Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it. + --break-on-existing Stop the download process after attempting + to download a file that's in the archive. --include-ads Download advertisements as well (experimental) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 38ba43a97..68279e0fd 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -205,6 +205,8 @@ class YoutubeDL(object): download_archive: File name of a file where all downloads are recorded. Videos already present in the file are not downloaded again. + break_on_existing: Stop the download process after attempting to download a file that's + in the archive. cookiefile: File name where cookies should be read from and dumped to. nocheckcertificate:Do not verify SSL certificates prefer_insecure: Use HTTP instead of HTTPS to retrieve information. @@ -993,7 +995,11 @@ class YoutubeDL(object): } reason = self._match_entry(entry, incomplete=True) - if reason is not None: + if reason.endswith('has already been recorded in archive') and self.params.get('break_on_existing'): + self.to_screen('[download] stopping downloading because ' + reason) + break + + elif reason is not None: self.to_screen('[download] ' + reason) continue diff --git a/youtube_dl/options.py b/youtube_dl/options.py index e7d8e8910..5e382755f 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -344,6 +344,10 @@ def parseOpts(overrideArguments=None): '--download-archive', metavar='FILE', dest='download_archive', help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.') + selection.add_option( + '--break-on-existing', + action='store_true', dest='break_on_existing', default=False, + help="Stop the download process after attempting to download a file that's in the archive.") selection.add_option( '--include-ads', dest='include_ads', action='store_true', From 674e7d46dbf428ba85ed12c74f0db0755086a861 Mon Sep 17 00:00:00 2001 From: Yoav Shai Date: Fri, 26 Oct 2018 02:31:52 +0300 Subject: [PATCH 2/2] Bind break_on_existing, improve its logic --- youtube_dl/YoutubeDL.py | 14 +++++++------- youtube_dl/__init__.py | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 68279e0fd..08917b5d6 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -995,13 +995,13 @@ class YoutubeDL(object): } reason = self._match_entry(entry, incomplete=True) - if reason.endswith('has already been recorded in archive') and self.params.get('break_on_existing'): - self.to_screen('[download] stopping downloading because ' + reason) - break - - elif reason is not None: - self.to_screen('[download] ' + reason) - continue + if reason is not None: + if reason.endswith('has already been recorded in the archive') and self.params.get('break_on_existing'): + print('[download] tried downloading a file that\'s already in the archive, stopping since --break-on-existing is set.') + break + else: + self.to_screen('[download] ' + reason) + continue entry_result = self.process_ie_result(entry, download=download, diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index ba435ea42..87fbe1667 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -393,6 +393,7 @@ def _real_main(argv=None): 'youtube_print_sig_code': opts.youtube_print_sig_code, 'age_limit': opts.age_limit, 'download_archive': download_archive_fn, + 'break_on_existing': opts.break_on_existing, 'cookiefile': opts.cookiefile, 'nocheckcertificate': opts.no_check_certificate, 'prefer_insecure': opts.prefer_insecure,