mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-04 06:02:50 +08:00
Dryied bytes option parsing.
This commit is contained in:
parent
58355a3bf1
commit
fe935ab7ec
@ -140,21 +140,6 @@ def _real_main(argv=None):
|
||||
opts.password = compat_getpass('Type account password and press [Return]: ')
|
||||
if opts.ap_username is not None and opts.ap_password is None:
|
||||
opts.ap_password = compat_getpass('Type TV provider account password and press [Return]: ')
|
||||
if opts.ratelimit is not None:
|
||||
numeric_limit = FileDownloader.parse_bytes(opts.ratelimit)
|
||||
if numeric_limit is None:
|
||||
parser.error('invalid rate limit specified')
|
||||
opts.ratelimit = numeric_limit
|
||||
if opts.min_filesize is not None:
|
||||
numeric_limit = FileDownloader.parse_bytes(opts.min_filesize)
|
||||
if numeric_limit is None:
|
||||
parser.error('invalid min_filesize specified')
|
||||
opts.min_filesize = numeric_limit
|
||||
if opts.max_filesize is not None:
|
||||
numeric_limit = FileDownloader.parse_bytes(opts.max_filesize)
|
||||
if numeric_limit is None:
|
||||
parser.error('invalid max_filesize specified')
|
||||
opts.max_filesize = numeric_limit
|
||||
if opts.sleep_interval is not None:
|
||||
if opts.sleep_interval < 0:
|
||||
parser.error('sleep interval must be positive or 0')
|
||||
@ -181,11 +166,6 @@ def _real_main(argv=None):
|
||||
opts.retries = parse_retries(opts.retries)
|
||||
if opts.fragment_retries is not None:
|
||||
opts.fragment_retries = parse_retries(opts.fragment_retries)
|
||||
if opts.buffersize is not None:
|
||||
numeric_buffersize = FileDownloader.parse_bytes(opts.buffersize)
|
||||
if numeric_buffersize is None:
|
||||
parser.error('invalid buffer size specified')
|
||||
opts.buffersize = numeric_buffersize
|
||||
if opts.playliststart <= 0:
|
||||
raise ValueError('Playlist start must be positive')
|
||||
if opts.playlistend not in (-1, None) and opts.playlistend < opts.playliststart:
|
||||
@ -231,7 +211,16 @@ def _real_main(argv=None):
|
||||
' file! Use "{0}.%(ext)s" instead of "{0}" as the output'
|
||||
' template'.format(outtmpl))
|
||||
|
||||
any_getting = opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson or opts.dump_single_json
|
||||
any_getting = any((getattr(opts, attr, None) for attr in ('geturl',
|
||||
'gettitle',
|
||||
'getid',
|
||||
'getthumbnail',
|
||||
'getdescription',
|
||||
'getfilename',
|
||||
'getformat',
|
||||
'getduration',
|
||||
'dumpjson',
|
||||
'dump_single_json')))
|
||||
any_printing = opts.print_json
|
||||
download_archive_fn = compat_expanduser(opts.download_archive) if opts.download_archive is not None else opts.download_archive
|
||||
|
||||
|
@ -17,6 +17,9 @@ from .utils import (
|
||||
preferredencoding,
|
||||
write_string,
|
||||
)
|
||||
from .downloader import (
|
||||
FileDownloader,
|
||||
)
|
||||
from .version import __version__
|
||||
|
||||
|
||||
@ -93,6 +96,12 @@ def parseOpts(overrideArguments=None):
|
||||
def _comma_separated_values_options_callback(option, opt_str, value, parser):
|
||||
setattr(parser.values, option.dest, value.split(','))
|
||||
|
||||
def _bytes_option_callback(option, opt_str, value, parser):
|
||||
_bytes = FileDownloader.parse_bytes(value)
|
||||
if _bytes is None:
|
||||
raise OptionValueError('invalid %s specified' % option.dest)
|
||||
setattr(parser.values, option.dest, _bytes)
|
||||
|
||||
def _hide_login_info(opts):
|
||||
PRIVATE_OPTS = ['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username']
|
||||
eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')
|
||||
@ -264,10 +273,12 @@ def parseOpts(overrideArguments=None):
|
||||
selection.add_option(
|
||||
'--min-filesize',
|
||||
metavar='SIZE', dest='min_filesize', default=None,
|
||||
action='callback', callback=_bytes_option_callback,
|
||||
help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
|
||||
selection.add_option(
|
||||
'--max-filesize',
|
||||
metavar='SIZE', dest='max_filesize', default=None,
|
||||
action='callback', callback=_bytes_option_callback,
|
||||
help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
|
||||
selection.add_option(
|
||||
'--date',
|
||||
@ -433,6 +444,7 @@ def parseOpts(overrideArguments=None):
|
||||
downloader.add_option(
|
||||
'-r', '--limit-rate', '--rate-limit',
|
||||
dest='ratelimit', metavar='RATE',
|
||||
action='callback', callback=_bytes_option_callback,
|
||||
help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
|
||||
downloader.add_option(
|
||||
'-R', '--retries',
|
||||
@ -453,6 +465,7 @@ def parseOpts(overrideArguments=None):
|
||||
downloader.add_option(
|
||||
'--buffer-size',
|
||||
dest='buffersize', metavar='SIZE', default='1024',
|
||||
action='callback', callback=_bytes_option_callback,
|
||||
help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
|
||||
downloader.add_option(
|
||||
'--no-resize-buffer',
|
||||
|
Loading…
Reference in New Issue
Block a user