1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-13 03:37:23 +08:00

added parameter stopatfirst to stop downloading of further videos when video is not in daterange

This commit is contained in:
Marvin D 2018-10-15 02:09:44 +02:00
parent 5d90a8a5f3
commit 0ae7077086
4 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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,