Add support for minimum and maximum duration
This commit is contained in:
parent
0c7b4f49eb
commit
eefbbcd785
@ -135,6 +135,10 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo
|
||||
--reject-title REGEX Skip download for matching titles (regex or
|
||||
caseless sub-string)
|
||||
--max-downloads NUMBER Abort after downloading NUMBER files
|
||||
--min-duration SECONDS Do not download any videos smaller than
|
||||
duration, in seconds
|
||||
--max-duration SECONDS Do not download any videos larger than
|
||||
duration, in seconds
|
||||
--min-filesize SIZE Do not download any videos smaller than
|
||||
SIZE (e.g. 50k or 44.6m)
|
||||
--max-filesize SIZE Do not download any videos larger than SIZE
|
||||
|
@ -749,6 +749,19 @@ class YoutubeDL(object):
|
||||
return '%s has already been recorded in archive' % video_title
|
||||
|
||||
if not incomplete:
|
||||
duration = info_dict.get('duration')
|
||||
min_duration = self.params.get('min_duration')
|
||||
if min_duration is not None:
|
||||
if duration is None:
|
||||
return 'Skipping %s, because its duration is unknown and min_duration is specified' % (video_title)
|
||||
if duration < min_duration:
|
||||
return 'Skipping %s, because its duration (%ds) is less than %ds' % (video_title, duration, min_duration)
|
||||
max_duration = self.params.get('max_duration')
|
||||
if max_duration is not None:
|
||||
if duration is None:
|
||||
return 'Skipping %s, because its duration is unknown and max_duration is specified' % (video_title)
|
||||
if duration > max_duration:
|
||||
return 'Skipping %s, because its duration (%ds) is more than %ds' % (video_title, duration, max_duration)
|
||||
match_filter = self.params.get('match_filter')
|
||||
if match_filter is not None:
|
||||
ret = match_filter(info_dict)
|
||||
|
@ -150,6 +150,12 @@ def _real_main(argv=None):
|
||||
if numeric_limit is None:
|
||||
parser.error('invalid rate limit specified')
|
||||
opts.ratelimit = numeric_limit
|
||||
if opts.min_duration is not None:
|
||||
if opts.min_duration <= 0:
|
||||
parser.error('invalid min_duration specified')
|
||||
if opts.max_duration is not None:
|
||||
if opts.max_duration <= 0:
|
||||
parser.error('invalid max_duration specified')
|
||||
if opts.min_filesize is not None:
|
||||
numeric_limit = FileDownloader.parse_bytes(opts.min_filesize)
|
||||
if numeric_limit is None:
|
||||
@ -384,6 +390,8 @@ def _real_main(argv=None):
|
||||
'write_pages': opts.write_pages,
|
||||
'test': opts.test,
|
||||
'keepvideo': opts.keepvideo,
|
||||
'min_duration': opts.min_duration,
|
||||
'max_duration': opts.max_duration,
|
||||
'min_filesize': opts.min_filesize,
|
||||
'max_filesize': opts.max_filesize,
|
||||
'min_views': opts.min_views,
|
||||
|
@ -279,6 +279,14 @@ def parseOpts(overrideArguments=None):
|
||||
'--max-downloads',
|
||||
dest='max_downloads', metavar='NUMBER', type=int, default=None,
|
||||
help='Abort after downloading NUMBER files')
|
||||
selection.add_option(
|
||||
'--min-duration',
|
||||
metavar='SECONDS', dest='min_duration', type=int, default=None,
|
||||
help='Do not download any videos smaller than duration, in seconds')
|
||||
selection.add_option(
|
||||
'--max-duration',
|
||||
metavar='SECONDS', dest='max_duration', type=int, default=None,
|
||||
help='Do not download any videos larger than duration, in seconds')
|
||||
selection.add_option(
|
||||
'--min-filesize',
|
||||
metavar='SIZE', dest='min_filesize', default=None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user