Add support for minimum and maximum duration

This commit is contained in:
Amish 2018-07-27 13:27:26 +05:30
parent 0c7b4f49eb
commit eefbbcd785
4 changed files with 33 additions and 0 deletions

View File

@ -135,6 +135,10 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo
--reject-title REGEX Skip download for matching titles (regex or --reject-title REGEX Skip download for matching titles (regex or
caseless sub-string) caseless sub-string)
--max-downloads NUMBER Abort after downloading NUMBER files --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 --min-filesize SIZE Do not download any videos smaller than
SIZE (e.g. 50k or 44.6m) SIZE (e.g. 50k or 44.6m)
--max-filesize SIZE Do not download any videos larger than SIZE --max-filesize SIZE Do not download any videos larger than SIZE

View File

@ -749,6 +749,19 @@ class YoutubeDL(object):
return '%s has already been recorded in archive' % video_title return '%s has already been recorded in archive' % video_title
if not incomplete: 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') match_filter = self.params.get('match_filter')
if match_filter is not None: if match_filter is not None:
ret = match_filter(info_dict) ret = match_filter(info_dict)

View File

@ -150,6 +150,12 @@ def _real_main(argv=None):
if numeric_limit is None: if numeric_limit is None:
parser.error('invalid rate limit specified') parser.error('invalid rate limit specified')
opts.ratelimit = numeric_limit 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: if opts.min_filesize is not None:
numeric_limit = FileDownloader.parse_bytes(opts.min_filesize) numeric_limit = FileDownloader.parse_bytes(opts.min_filesize)
if numeric_limit is None: if numeric_limit is None:
@ -384,6 +390,8 @@ def _real_main(argv=None):
'write_pages': opts.write_pages, 'write_pages': opts.write_pages,
'test': opts.test, 'test': opts.test,
'keepvideo': opts.keepvideo, 'keepvideo': opts.keepvideo,
'min_duration': opts.min_duration,
'max_duration': opts.max_duration,
'min_filesize': opts.min_filesize, 'min_filesize': opts.min_filesize,
'max_filesize': opts.max_filesize, 'max_filesize': opts.max_filesize,
'min_views': opts.min_views, 'min_views': opts.min_views,

View File

@ -279,6 +279,14 @@ def parseOpts(overrideArguments=None):
'--max-downloads', '--max-downloads',
dest='max_downloads', metavar='NUMBER', type=int, default=None, dest='max_downloads', metavar='NUMBER', type=int, default=None,
help='Abort after downloading NUMBER files') 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( selection.add_option(
'--min-filesize', '--min-filesize',
metavar='SIZE', dest='min_filesize', default=None, metavar='SIZE', dest='min_filesize', default=None,