1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-19 18:45:35 +08:00

completed conversion of selection options to docopt

This commit is contained in:
SavinaRoja 2013-10-06 00:21:56 -04:00
parent cb1d0c4dc2
commit 096f816c6c

View File

@ -57,7 +57,8 @@ Options:
Video Selection: Video Selection:
--playlist-start NUMBER playlist video to start at [default: 1] --playlist-start NUMBER playlist video to start at [default: 1]
--playlist-end NUMBER playlist video to end at (default is last) --playlist-end NUMBER playlist video to end at (defaults to last)
[default: -1]
--match-title REGEX download only matching titles (regex or caseless --match-title REGEX download only matching titles (regex or caseless
sub-string) sub-string)
--reject-title REGEX skip download for matching titles (regex or --reject-title REGEX skip download for matching titles (regex or
@ -352,18 +353,18 @@ def parseOpts(overrideArguments=None):
#general.add_option('--no-check-certificate', action='store_true', dest='no_check_certificate', default=False, help='Suppress HTTPS certificate validation.') #general.add_option('--no-check-certificate', action='store_true', dest='no_check_certificate', default=False, help='Suppress HTTPS certificate validation.')
selection.add_option('--playlist-start', #selection.add_option('--playlist-start',
dest='playliststart', metavar='NUMBER', help='playlist video to start at (default is %default)', default=1) # dest='playliststart', metavar='NUMBER', help='playlist video to start at (default is %default)', default=1)
selection.add_option('--playlist-end', #selection.add_option('--playlist-end',
dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1) # dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1)
selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)') #selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)')
selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)') #selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)')
selection.add_option('--max-downloads', metavar='NUMBER', dest='max_downloads', help='Abort after downloading NUMBER files', default=None) #selection.add_option('--max-downloads', metavar='NUMBER', dest='max_downloads', help='Abort after downloading NUMBER files', default=None)
selection.add_option('--min-filesize', metavar='SIZE', dest='min_filesize', help="Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)", default=None) #selection.add_option('--min-filesize', metavar='SIZE', dest='min_filesize', help="Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)", default=None)
selection.add_option('--max-filesize', metavar='SIZE', dest='max_filesize', help="Do not download any videos larger than SIZE (e.g. 50k or 44.6m)", default=None) #selection.add_option('--max-filesize', metavar='SIZE', dest='max_filesize', help="Do not download any videos larger than SIZE (e.g. 50k or 44.6m)", default=None)
selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None) #selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None)
selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None) #selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None)
selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None) #selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None)
#authentication.add_option('-u', '--username', #authentication.add_option('-u', '--username',
@ -372,8 +373,8 @@ def parseOpts(overrideArguments=None):
# dest='password', metavar='PASSWORD', help='account password') # dest='password', metavar='PASSWORD', help='account password')
#authentication.add_option('-n', '--netrc', #authentication.add_option('-n', '--netrc',
# action='store_true', dest='usenetrc', help='use .netrc authentication data', default=False) # action='store_true', dest='usenetrc', help='use .netrc authentication data', default=False)
authentication.add_option('--video-password', #authentication.add_option('--video-password',
dest='videopassword', metavar='PASSWORD', help='video password (vimeo only)') # dest='videopassword', metavar='PASSWORD', help='video password (vimeo only)')
video_format.add_option('-f', '--format', video_format.add_option('-f', '--format',
@ -682,11 +683,11 @@ def _real_main(argv=None):
if numeric_limit is None: if numeric_limit is None:
parser.error(u'invalid min_filesize specified') parser.error(u'invalid min_filesize specified')
opts['--min-filesize'] = numeric_limit opts['--min-filesize'] = numeric_limit
if opts.max_filesize is not None: if opts['--max-filesize']:
numeric_limit = FileDownloader.parse_bytes(opts.max_filesize) numeric_limit = FileDownloader.parse_bytes(opts['--max-filesize'])
if numeric_limit is None: if numeric_limit is None:
parser.error(u'invalid max_filesize specified') parser.error(u'invalid max_filesize specified')
opts.max_filesize = numeric_limit opts['--max-filesize'] = numeric_limit
if opts.retries is not None: if opts.retries is not None:
try: try:
opts.retries = int(opts.retries) opts.retries = int(opts.retries)
@ -698,14 +699,14 @@ def _real_main(argv=None):
parser.error(u'invalid buffer size specified') parser.error(u'invalid buffer size specified')
opts.buffersize = numeric_buffersize opts.buffersize = numeric_buffersize
try: try:
opts.playliststart = int(opts.playliststart) opts['--playlist-start'] = int(opts['--playlist-start'])
if opts.playliststart <= 0: if opts['--playlist-start'] <= 0:
raise ValueError(u'Playlist start must be positive') raise ValueError(u'Playlist start must be positive')
except (TypeError, ValueError) as err: except (TypeError, ValueError) as err:
parser.error(u'invalid playlist start number specified') parser.error(u'invalid playlist start number specified')
try: try:
opts.playlistend = int(opts.playlistend) opts['--playlist-end'] = int(opts['--playlist-end'])
if opts.playlistend != -1 and (opts.playlistend <= 0 or opts.playlistend < opts.playliststart): if opts['--playlist-end'] != -1 and (opts['--playlist-end'] <= 0 or opts['--playlist-end'] < opts['--playlist-start']):
raise ValueError(u'Playlist end must be greater than playlist start') raise ValueError(u'Playlist end must be greater than playlist start')
except (TypeError, ValueError) as err: except (TypeError, ValueError) as err:
parser.error(u'invalid playlist end number specified') parser.error(u'invalid playlist end number specified')
@ -719,10 +720,10 @@ def _real_main(argv=None):
if opts.recodevideo is not None: if opts.recodevideo is not None:
if opts.recodevideo not in ['mp4', 'flv', 'webm', 'ogg']: if opts.recodevideo not in ['mp4', 'flv', 'webm', 'ogg']:
parser.error(u'invalid video recode format specified') parser.error(u'invalid video recode format specified')
if opts.date is not None: if opts['--date']:
date = DateRange.day(opts.date) date = DateRange.day(opts['--date'])
else: else:
date = DateRange(opts.dateafter, opts.datebefore) date = DateRange(opts['--dateafter'], opts['--datebefore'])
if sys.version_info < (3,): if sys.version_info < (3,):
# In Python 2, sys.argv is a bytestring (also note http://bugs.python.org/issue2128 for Windows systems) # In Python 2, sys.argv is a bytestring (also note http://bugs.python.org/issue2128 for Windows systems)
@ -768,8 +769,8 @@ def _real_main(argv=None):
'continuedl': opts.continue_dl, 'continuedl': opts.continue_dl,
'noprogress': opts['--no-progress'], 'noprogress': opts['--no-progress'],
'progress_with_newline': opts['--newline'], 'progress_with_newline': opts['--newline'],
'playliststart': opts.playliststart, 'playliststart': opts['--playlist-start'],
'playlistend': opts.playlistend, 'playlistend': opts['--playlist-end'],
'logtostderr': opts['--output'] == '-', 'logtostderr': opts['--output'] == '-',
'consoletitle': opts['--console-title'], 'consoletitle': opts['--console-title'],
'nopart': opts.nopart, 'nopart': opts.nopart,
@ -783,16 +784,16 @@ def _real_main(argv=None):
'listsubtitles': opts.listsubtitles, 'listsubtitles': opts.listsubtitles,
'subtitlesformat': opts.subtitlesformat, 'subtitlesformat': opts.subtitlesformat,
'subtitleslangs': opts.subtitleslangs, 'subtitleslangs': opts.subtitleslangs,
'matchtitle': decodeOption(opts.matchtitle), 'matchtitle': decodeOption(opts['--match-title']),
'rejecttitle': decodeOption(opts.rejecttitle), 'rejecttitle': decodeOption(opts['--reject-title']),
'max_downloads': opts.max_downloads, 'max_downloads': opts['--max-downloads'],
'prefer_free_formats': opts.prefer_free_formats, 'prefer_free_formats': opts.prefer_free_formats,
'verbose': opts['--verbose'], 'verbose': opts['--verbose'],
'dump_intermediate_pages': opts['--dump-intermediate-pages'], 'dump_intermediate_pages': opts['--dump-intermediate-pages'],
'test': opts.test, 'test': opts.test,
'keepvideo': opts.keepvideo, 'keepvideo': opts.keepvideo,
'min_filesize': opts['--min-filesize'], 'min_filesize': opts['--min-filesize'],
'max_filesize': opts.max_filesize, 'max_filesize': opts['--max-filesize'],
'daterange': date, 'daterange': date,
}) })