From 0ae70770861709a9fa33f9263cfdbdbc7f785510 Mon Sep 17 00:00:00 2001 From: Marvin D Date: Mon, 15 Oct 2018 02:09:44 +0200 Subject: [PATCH] added parameter stopatfirst to stop downloading of further videos when video is not in daterange --- README.md | 2 ++ youtube_dl/YoutubeDL.py | 12 +++++++++++- youtube_dl/__init__.py | 1 + youtube_dl/options.py | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fdd115c9b..75651dcd5 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,8 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo this date (i.e. inclusive) --dateafter DATE Download only videos uploaded on or after this date (i.e. inclusive) + --stopatfirst Stop downloading of further videos when the + first video is not in daterange --min-views COUNT Do not download any videos with less than COUNT views --max-views COUNT Do not download any videos with more than diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 38ba43a97..5be107065 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -334,6 +334,7 @@ class YoutubeDL(object): _download_retcode = None _num_downloads = None _screen_file = None + _stopAtFirst = None def __init__(self, params=None, auto_init=True): """Create a FileDownloader object with the given options.""" @@ -346,6 +347,7 @@ class YoutubeDL(object): self._download_retcode = 0 self._num_downloads = 0 self._screen_file = [sys.stdout, sys.stderr][params.get('logtostderr', False)] + self._stopAtFirst = False self._err_file = sys.stderr self.params = { # Default parameters @@ -733,7 +735,10 @@ class YoutubeDL(object): date = info_dict.get('upload_date') if date is not None: dateRange = self.params.get('daterange', DateRange()) + stopAtFirst = self.params.get('stopatfirst') if date not in dateRange: + if stopAtFirst: + self._stopAtFirst = True return '%s upload date is not in range %s' % (date_from_str(date).isoformat(), dateRange) view_count = info_dict.get('view_count') if view_count is not None: @@ -972,7 +977,12 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') + self._stopAtFirst = False + for i, entry in enumerate(entries, 1): + if self._stopAtFirst: + self.to_screen('[download] Stopped downloading because video was not in daterange') + break self.to_screen('[download] Downloading video %s of %s' % (i, n_entries)) # This __x_forwarded_for_ip thing is a bit ugly but requires # minimal changes @@ -1707,7 +1717,7 @@ class YoutubeDL(object): if reason is not None: self.to_screen('[download] ' + reason) return - + self._num_downloads += 1 info_dict['_filename'] = filename = self.prepare_filename(info_dict) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index ba435ea42..da7164ebe 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -389,6 +389,7 @@ def _real_main(argv=None): 'min_views': opts.min_views, 'max_views': opts.max_views, 'daterange': date, + 'stopatfirst': opts.stopatfirst, 'cachedir': opts.cachedir, 'youtube_print_sig_code': opts.youtube_print_sig_code, 'age_limit': opts.age_limit, diff --git a/youtube_dl/options.py b/youtube_dl/options.py index e7d8e8910..931bb1ec7 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -299,6 +299,10 @@ def parseOpts(overrideArguments=None): '--dateafter', metavar='DATE', dest='dateafter', default=None, help='Download only videos uploaded on or after this date (i.e. inclusive)') + selection.add_option( + '--stopatfirst', + action='store_true', dest='stopatfirst', default=False, + help='Stop downloading of further videos when the first video is not in daterange') selection.add_option( '--min-views', metavar='COUNT', dest='min_views', default=None, type=int,