]> jfr.im git - yt-dlp.git/blob - youtube_dlc/options.py
Added `--force-overwrites` option (https://github.com/ytdl-org/youtube-dl/pull/20405)
[yt-dlp.git] / youtube_dlc / options.py
1 from __future__ import unicode_literals
2
3 import os.path
4 import optparse
5 import re
6 import sys
7
8 from .downloader.external import list_external_downloaders
9 from .compat import (
10 compat_expanduser,
11 compat_get_terminal_size,
12 compat_getenv,
13 compat_kwargs,
14 compat_shlex_split,
15 )
16 from .utils import (
17 preferredencoding,
18 write_string,
19 )
20 from .version import __version__
21
22
23 def _hide_login_info(opts):
24 PRIVATE_OPTS = set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
25 eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')
26
27 def _scrub_eq(o):
28 m = eqre.match(o)
29 if m:
30 return m.group('key') + '=PRIVATE'
31 else:
32 return o
33
34 opts = list(map(_scrub_eq, opts))
35 for idx, opt in enumerate(opts):
36 if opt in PRIVATE_OPTS and idx + 1 < len(opts):
37 opts[idx + 1] = 'PRIVATE'
38 return opts
39
40
41 def parseOpts(overrideArguments=None):
42 def _readOptions(filename_bytes, default=[]):
43 try:
44 optionf = open(filename_bytes)
45 except IOError:
46 return default # silently skip if file is not present
47 try:
48 # FIXME: https://github.com/ytdl-org/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
49 contents = optionf.read()
50 if sys.version_info < (3,):
51 contents = contents.decode(preferredencoding())
52 res = compat_shlex_split(contents, comments=True)
53 finally:
54 optionf.close()
55 return res
56
57 def _readUserConf():
58 xdg_config_home = compat_getenv('XDG_CONFIG_HOME')
59 if xdg_config_home:
60 userConfFile = os.path.join(xdg_config_home, 'youtube-dlc', 'config')
61 if not os.path.isfile(userConfFile):
62 userConfFile = os.path.join(xdg_config_home, 'youtube-dlc.conf')
63 else:
64 userConfFile = os.path.join(compat_expanduser('~'), '.config', 'youtube-dlc', 'config')
65 if not os.path.isfile(userConfFile):
66 userConfFile = os.path.join(compat_expanduser('~'), '.config', 'youtube-dlc.conf')
67 userConf = _readOptions(userConfFile, None)
68
69 if userConf is None:
70 appdata_dir = compat_getenv('appdata')
71 if appdata_dir:
72 userConf = _readOptions(
73 os.path.join(appdata_dir, 'youtube-dlc', 'config'),
74 default=None)
75 if userConf is None:
76 userConf = _readOptions(
77 os.path.join(appdata_dir, 'youtube-dlc', 'config.txt'),
78 default=None)
79
80 if userConf is None:
81 userConf = _readOptions(
82 os.path.join(compat_expanduser('~'), 'youtube-dlc.conf'),
83 default=None)
84 if userConf is None:
85 userConf = _readOptions(
86 os.path.join(compat_expanduser('~'), 'youtube-dlc.conf.txt'),
87 default=None)
88
89 if userConf is None:
90 userConf = []
91
92 return userConf
93
94 def _format_option_string(option):
95 ''' ('-o', '--option') -> -o, --format METAVAR'''
96
97 opts = []
98
99 if option._short_opts:
100 opts.append(option._short_opts[0])
101 if option._long_opts:
102 opts.append(option._long_opts[0])
103 if len(opts) > 1:
104 opts.insert(1, ', ')
105
106 if option.takes_value():
107 opts.append(' %s' % option.metavar)
108
109 return ''.join(opts)
110
111 def _comma_separated_values_options_callback(option, opt_str, value, parser):
112 setattr(parser.values, option.dest, value.split(','))
113
114 # No need to wrap help messages if we're on a wide console
115 columns = compat_get_terminal_size().columns
116 max_width = columns if columns else 80
117 max_help_position = 80
118
119 fmt = optparse.IndentedHelpFormatter(width=max_width, max_help_position=max_help_position)
120 fmt.format_option_strings = _format_option_string
121
122 kw = {
123 'version': __version__,
124 'formatter': fmt,
125 'usage': '%prog [OPTIONS] URL [URL...]',
126 'conflict_handler': 'resolve',
127 }
128
129 parser = optparse.OptionParser(**compat_kwargs(kw))
130
131 general = optparse.OptionGroup(parser, 'General Options')
132 general.add_option(
133 '-h', '--help',
134 action='help',
135 help='Print this help text and exit')
136 general.add_option(
137 '--version',
138 action='version',
139 help='Print program version and exit')
140 general.add_option(
141 '-U', '--update',
142 action='store_true', dest='update_self',
143 help='[BROKEN] Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
144 general.add_option(
145 '-i', '--ignore-errors', '--no-abort-on-error',
146 action='store_true', dest='ignoreerrors', default=True,
147 help='Continue on download errors, for example to skip unavailable videos in a playlist (default)')
148 general.add_option(
149 '--abort-on-error', '--no-ignore-errors',
150 action='store_false', dest='ignoreerrors',
151 help='Abort downloading of further videos if an error occurs')
152 general.add_option(
153 '--dump-user-agent',
154 action='store_true', dest='dump_user_agent', default=False,
155 help='Display the current browser identification')
156 general.add_option(
157 '--list-extractors',
158 action='store_true', dest='list_extractors', default=False,
159 help='List all supported extractors')
160 general.add_option(
161 '--extractor-descriptions',
162 action='store_true', dest='list_extractor_descriptions', default=False,
163 help='Output descriptions of all supported extractors')
164 general.add_option(
165 '--force-generic-extractor',
166 action='store_true', dest='force_generic_extractor', default=False,
167 help='Force extraction to use the generic extractor')
168 general.add_option(
169 '--default-search',
170 dest='default_search', metavar='PREFIX',
171 help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube-dl "large apple". Use the value "auto" to let youtube-dl guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching.')
172 general.add_option(
173 '--ignore-config', '--no-config',
174 action='store_true',
175 help=(
176 'Do not read configuration files. '
177 'When given in the global configuration file /etc/youtube-dl.conf: '
178 'Do not read the user configuration in ~/.config/youtube-dl/config '
179 '(%APPDATA%/youtube-dl/config.txt on Windows)'))
180 general.add_option(
181 '--config-location',
182 dest='config_location', metavar='PATH',
183 help='Location of the configuration file; either the path to the config or its containing directory.')
184 general.add_option(
185 '--flat-playlist',
186 action='store_const', dest='extract_flat', const='in_playlist', default=False,
187 help='Do not extract the videos of a playlist, only list them.')
188 general.add_option(
189 '--flat-videos',
190 action='store_true', dest='extract_flat',
191 help='Do not resolve the video urls')
192 general.add_option(
193 '--no-flat-playlist',
194 action='store_false', dest='extract_flat',
195 help='Extract the videos of a playlist')
196 general.add_option(
197 '--mark-watched',
198 action='store_true', dest='mark_watched', default=False,
199 help='Mark videos watched (YouTube only)')
200 general.add_option(
201 '--no-mark-watched',
202 action='store_false', dest='mark_watched', default=False,
203 help='Do not mark videos watched')
204 general.add_option(
205 '--no-color', '--no-colors',
206 action='store_true', dest='no_color',
207 default=False,
208 help='Do not emit color codes in output')
209
210 network = optparse.OptionGroup(parser, 'Network Options')
211 network.add_option(
212 '--proxy', dest='proxy',
213 default=None, metavar='URL',
214 help=(
215 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
216 'SOCKS proxy, specify a proper scheme. For example '
217 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
218 'for direct connection'))
219 network.add_option(
220 '--socket-timeout',
221 dest='socket_timeout', type=float, default=None, metavar='SECONDS',
222 help='Time to wait before giving up, in seconds')
223 network.add_option(
224 '--source-address',
225 metavar='IP', dest='source_address', default=None,
226 help='Client-side IP address to bind to',
227 )
228 network.add_option(
229 '-4', '--force-ipv4',
230 action='store_const', const='0.0.0.0', dest='source_address',
231 help='Make all connections via IPv4',
232 )
233 network.add_option(
234 '-6', '--force-ipv6',
235 action='store_const', const='::', dest='source_address',
236 help='Make all connections via IPv6',
237 )
238
239 geo = optparse.OptionGroup(parser, 'Geo Restriction')
240 geo.add_option(
241 '--geo-verification-proxy',
242 dest='geo_verification_proxy', default=None, metavar='URL',
243 help=(
244 'Use this proxy to verify the IP address for some geo-restricted sites. '
245 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading.'))
246 geo.add_option(
247 '--cn-verification-proxy',
248 dest='cn_verification_proxy', default=None, metavar='URL',
249 help=optparse.SUPPRESS_HELP)
250 geo.add_option(
251 '--geo-bypass',
252 action='store_true', dest='geo_bypass', default=True,
253 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
254 geo.add_option(
255 '--no-geo-bypass',
256 action='store_false', dest='geo_bypass', default=True,
257 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
258 geo.add_option(
259 '--geo-bypass-country', metavar='CODE',
260 dest='geo_bypass_country', default=None,
261 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
262 geo.add_option(
263 '--geo-bypass-ip-block', metavar='IP_BLOCK',
264 dest='geo_bypass_ip_block', default=None,
265 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
266
267 selection = optparse.OptionGroup(parser, 'Video Selection')
268 selection.add_option(
269 '--playlist-start',
270 dest='playliststart', metavar='NUMBER', default=1, type=int,
271 help='Playlist video to start at (default is %default)')
272 selection.add_option(
273 '--playlist-end',
274 dest='playlistend', metavar='NUMBER', default=None, type=int,
275 help='Playlist video to end at (default is last)')
276 selection.add_option(
277 '--playlist-items',
278 dest='playlist_items', metavar='ITEM_SPEC', default=None,
279 help='Playlist video items to download. Specify indices of the videos in the playlist separated by commas like: "--playlist-items 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: "--playlist-items 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13.')
280 selection.add_option(
281 '--match-title',
282 dest='matchtitle', metavar='REGEX',
283 help='Download only matching titles (regex or caseless sub-string)')
284 selection.add_option(
285 '--reject-title',
286 dest='rejecttitle', metavar='REGEX',
287 help='Skip download for matching titles (regex or caseless sub-string)')
288 selection.add_option(
289 '--max-downloads',
290 dest='max_downloads', metavar='NUMBER', type=int, default=None,
291 help='Abort after downloading NUMBER files')
292 selection.add_option(
293 '--min-filesize',
294 metavar='SIZE', dest='min_filesize', default=None,
295 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
296 selection.add_option(
297 '--max-filesize',
298 metavar='SIZE', dest='max_filesize', default=None,
299 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
300 selection.add_option(
301 '--date',
302 metavar='DATE', dest='date', default=None,
303 help=(
304 'Download only videos uploaded in this date.'
305 'The date can be "YYYYMMDD" or in the format'
306 '"(now|today)[+-][0-9](day|week|month|year)(s)?"'))
307 selection.add_option(
308 '--datebefore',
309 metavar='DATE', dest='datebefore', default=None,
310 help=(
311 'Download only videos uploaded on or before this date. '
312 'The date formats accepted is the same as --date'))
313 selection.add_option(
314 '--dateafter',
315 metavar='DATE', dest='dateafter', default=None,
316 help=(
317 'Download only videos uploaded on or after this date. '
318 'The date formats accepted is the same as --date'))
319 selection.add_option(
320 '--min-views',
321 metavar='COUNT', dest='min_views', default=None, type=int,
322 help='Do not download any videos with less than COUNT views')
323 selection.add_option(
324 '--max-views',
325 metavar='COUNT', dest='max_views', default=None, type=int,
326 help='Do not download any videos with more than COUNT views')
327 selection.add_option(
328 '--match-filter',
329 metavar='FILTER', dest='match_filter', default=None,
330 help=(
331 'Generic video filter. '
332 'Specify any key (see the "OUTPUT TEMPLATE" for a list of available keys) to '
333 'match if the key is present, '
334 '!key to check if the key is not present, '
335 'key > NUMBER (like "comment_count > 12", also works with '
336 '>=, <, <=, !=, =) to compare against a number, '
337 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
338 'to match against a string literal '
339 'and & to require multiple matches. '
340 'Values which are not known are excluded unless you '
341 'put a question mark (?) after the operator. '
342 'For example, to only match videos that have been liked more than '
343 '100 times and disliked less than 50 times (or the dislike '
344 'functionality is not available at the given service), but who '
345 'also have a description, use --match-filter '
346 '"like_count > 100 & dislike_count <? 50 & description" .'))
347 selection.add_option(
348 '--no-match-filter',
349 metavar='FILTER', dest='match_filter', action='store_const', const=None,
350 help='Do not use generic video filter (default)')
351 selection.add_option(
352 '--no-playlist',
353 action='store_true', dest='noplaylist', default=False,
354 help='Download only the video, if the URL refers to a video and a playlist.')
355 selection.add_option(
356 '--yes-playlist',
357 action='store_false', dest='noplaylist', default=False,
358 help='Download the playlist, if the URL refers to a video and a playlist.')
359 selection.add_option(
360 '--age-limit',
361 metavar='YEARS', dest='age_limit', default=None, type=int,
362 help='Download only videos suitable for the given age')
363 selection.add_option(
364 '--download-archive', metavar='FILE',
365 dest='download_archive',
366 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
367 selection.add_option(
368 '--break-on-existing',
369 action='store_true', dest='break_on_existing', default=False,
370 help="Stop the download process after attempting to download a file that's in the archive.")
371 selection.add_option(
372 '--no-download-archive',
373 dest='download_archive', action="store_const", const=None,
374 help='Do not use archive file (default)')
375 selection.add_option(
376 '--include-ads',
377 dest='include_ads', action='store_true',
378 help='Download advertisements as well (experimental)')
379 selection.add_option(
380 '--no-include-ads',
381 dest='include_ads', action='store_false',
382 help='Do not download advertisements (default)')
383
384 authentication = optparse.OptionGroup(parser, 'Authentication Options')
385 authentication.add_option(
386 '-u', '--username',
387 dest='username', metavar='USERNAME',
388 help='Login with this account ID')
389 authentication.add_option(
390 '-p', '--password',
391 dest='password', metavar='PASSWORD',
392 help='Account password. If this option is left out, youtube-dlc will ask interactively.')
393 authentication.add_option(
394 '-2', '--twofactor',
395 dest='twofactor', metavar='TWOFACTOR',
396 help='Two-factor authentication code')
397 authentication.add_option(
398 '-n', '--netrc',
399 action='store_true', dest='usenetrc', default=False,
400 help='Use .netrc authentication data')
401 authentication.add_option(
402 '--video-password',
403 dest='videopassword', metavar='PASSWORD',
404 help='Video password (vimeo, youku)')
405
406 adobe_pass = optparse.OptionGroup(parser, 'Adobe Pass Options')
407 adobe_pass.add_option(
408 '--ap-mso',
409 dest='ap_mso', metavar='MSO',
410 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
411 adobe_pass.add_option(
412 '--ap-username',
413 dest='ap_username', metavar='USERNAME',
414 help='Multiple-system operator account login')
415 adobe_pass.add_option(
416 '--ap-password',
417 dest='ap_password', metavar='PASSWORD',
418 help='Multiple-system operator account password. If this option is left out, youtube-dlc will ask interactively.')
419 adobe_pass.add_option(
420 '--ap-list-mso',
421 action='store_true', dest='ap_list_mso', default=False,
422 help='List all supported multiple-system operators')
423
424 video_format = optparse.OptionGroup(parser, 'Video Format Options')
425 video_format.add_option(
426 '-f', '--format',
427 action='store', dest='format', metavar='FORMAT', default=None,
428 help='Video format code, see "FORMAT SELECTION" for more details')
429 video_format.add_option(
430 '-S', '--format-sort', metavar='SORTORDER',
431 dest='format_sort', default=[],
432 action='callback', callback=_comma_separated_values_options_callback, type='str',
433 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
434 video_format.add_option(
435 '--format-sort-force', '--S-force',
436 action='store_true', dest='format_sort_force', metavar='FORMAT', default=False,
437 help=(
438 'Force user specified sort order to have precedence over all fields, '
439 'see "Sorting Formats" for more details'))
440 video_format.add_option(
441 '--no-format-sort-force',
442 action='store_false', dest='format_sort_force', metavar='FORMAT', default=False,
443 help=(
444 'Some fields have precedence over the user specified sort order (default), '
445 'see "Sorting Formats" for more details'))
446 video_format.add_option(
447 '--video-multistreams',
448 action='store_true', dest='allow_multiple_video_streams', default=False,
449 help='Allow multiple video streams to be merged into a single file')
450 video_format.add_option(
451 '--no-video-multistreams',
452 action='store_false', dest='allow_multiple_video_streams',
453 help='Only one video stream is downloaded for each output file (default)')
454 video_format.add_option(
455 '--audio-multistreams',
456 action='store_true', dest='allow_multiple_audio_streams', default=False,
457 help='Allow multiple audio streams to be merged into a single file')
458 video_format.add_option(
459 '--no-audio-multistreams',
460 action='store_false', dest='allow_multiple_audio_streams',
461 help='Only one audio stream is downloaded for each output file (default)')
462 video_format.add_option(
463 '--all-formats',
464 action='store_const', dest='format', const='all',
465 help='Download all available video formats')
466 video_format.add_option(
467 '--prefer-free-formats',
468 action='store_true', dest='prefer_free_formats', default=False,
469 help='Prefer free video formats over non-free formats of same quality')
470 video_format.add_option(
471 '-F', '--list-formats',
472 action='store_true', dest='listformats',
473 help='List all available formats of requested videos')
474 video_format.add_option(
475 '--list-formats-as-table',
476 action='store_true', dest='listformats_table', default=True,
477 help='Present the output of -F in a more tabular form (default)')
478 video_format.add_option(
479 '--list-formats-old', '--no-list-formats-as-table',
480 action='store_false', dest='listformats_table',
481 help='Present the output of -F in the old form')
482 video_format.add_option(
483 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
484 action='store_true', dest='youtube_include_dash_manifest', default=True,
485 help='Download the DASH manifests and related data on YouTube videos (default)')
486 video_format.add_option(
487 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
488 action='store_false', dest='youtube_include_dash_manifest',
489 help='Do not download the DASH manifests and related data on YouTube videos')
490 video_format.add_option(
491 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
492 action='store_true', dest='youtube_include_hls_manifest', default=True,
493 help='Download the HLS manifests and related data on YouTube videos (default)')
494 video_format.add_option(
495 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
496 action='store_false', dest='youtube_include_hls_manifest',
497 help='Do not download the HLS manifests and related data on YouTube videos')
498 video_format.add_option(
499 '--merge-output-format',
500 action='store', dest='merge_output_format', metavar='FORMAT', default=None,
501 help=(
502 'If a merge is required (e.g. bestvideo+bestaudio), '
503 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
504 'Ignored if no merge is required'))
505
506 subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
507 subtitles.add_option(
508 '--write-subs', '--write-srt',
509 action='store_true', dest='writesubtitles', default=False,
510 help='Write subtitle file')
511 subtitles.add_option(
512 '--no-write-subs', '--no-write-srt',
513 action='store_false', dest='writesubtitles',
514 help='Do not write subtitle file (default)')
515 subtitles.add_option(
516 '--write-auto-subs', '--write-automatic-subs',
517 action='store_true', dest='writeautomaticsub', default=False,
518 help='Write automatically generated subtitle file (YouTube only)')
519 subtitles.add_option(
520 '--no-write-auto-subs', '--no-write-automatic-subs',
521 action='store_false', dest='writeautomaticsub', default=False,
522 help='Do not write automatically generated subtitle file (default)')
523 subtitles.add_option(
524 '--all-subs',
525 action='store_true', dest='allsubtitles', default=False,
526 help='Download all the available subtitles of the video')
527 subtitles.add_option(
528 '--list-subs',
529 action='store_true', dest='listsubtitles', default=False,
530 help='List all available subtitles for the video')
531 subtitles.add_option(
532 '--sub-format',
533 action='store', dest='subtitlesformat', metavar='FORMAT', default='best',
534 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
535 subtitles.add_option(
536 '--sub-lang', '--sub-langs', '--srt-lang',
537 action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
538 default=[], callback=_comma_separated_values_options_callback,
539 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
540
541 downloader = optparse.OptionGroup(parser, 'Download Options')
542 downloader.add_option(
543 '-r', '--limit-rate', '--rate-limit',
544 dest='ratelimit', metavar='RATE',
545 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
546 downloader.add_option(
547 '-R', '--retries',
548 dest='retries', metavar='RETRIES', default=10,
549 help='Number of retries (default is %default), or "infinite".')
550 downloader.add_option(
551 '--fragment-retries',
552 dest='fragment_retries', metavar='RETRIES', default=10,
553 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
554 downloader.add_option(
555 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment',
556 action='store_true', dest='skip_unavailable_fragments', default=True,
557 help='Skip unavailable fragments for DASH, hlsnative and ISM (default)')
558 downloader.add_option(
559 '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments',
560 action='store_false', dest='skip_unavailable_fragments',
561 help='Abort downloading when some fragment is unavailable')
562 downloader.add_option(
563 '--keep-fragments',
564 action='store_true', dest='keep_fragments', default=False,
565 help='Keep downloaded fragments on disk after downloading is finished')
566 downloader.add_option(
567 '--no-keep-fragments',
568 action='store_false', dest='keep_fragments',
569 help='Delete downloaded fragments after downloading is finished (default)')
570 downloader.add_option(
571 '--buffer-size',
572 dest='buffersize', metavar='SIZE', default='1024',
573 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
574 downloader.add_option(
575 '--resize-buffer',
576 action='store_false', dest='noresizebuffer',
577 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
578 downloader.add_option(
579 '--no-resize-buffer',
580 action='store_true', dest='noresizebuffer', default=False,
581 help='Do not automatically adjust the buffer size')
582 downloader.add_option(
583 '--http-chunk-size',
584 dest='http_chunk_size', metavar='SIZE', default=None,
585 help=(
586 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
587 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
588 downloader.add_option(
589 '--test',
590 action='store_true', dest='test', default=False,
591 help=optparse.SUPPRESS_HELP)
592 downloader.add_option(
593 '--playlist-reverse',
594 action='store_true',
595 help='Download playlist videos in reverse order')
596 downloader.add_option(
597 '--no-playlist-reverse',
598 action='store_false', dest='playlist_reverse',
599 help='Download playlist videos in default order (default)')
600 downloader.add_option(
601 '--playlist-random',
602 action='store_true',
603 help='Download playlist videos in random order')
604 downloader.add_option(
605 '--xattr-set-filesize',
606 dest='xattr_set_filesize', action='store_true',
607 help='Set file xattribute ytdl.filesize with expected file size')
608 downloader.add_option(
609 '--hls-prefer-native',
610 dest='hls_prefer_native', action='store_true', default=None,
611 help='Use the native HLS downloader instead of ffmpeg')
612 downloader.add_option(
613 '--hls-prefer-ffmpeg',
614 dest='hls_prefer_native', action='store_false', default=None,
615 help='Use ffmpeg instead of the native HLS downloader')
616 downloader.add_option(
617 '--hls-use-mpegts',
618 dest='hls_use_mpegts', action='store_true',
619 help=(
620 'Use the mpegts container for HLS videos, allowing to play the '
621 'video while downloading (some players may not be able to play it)'))
622 downloader.add_option(
623 '--external-downloader',
624 dest='external_downloader', metavar='COMMAND',
625 help=(
626 'Use the specified external downloader. '
627 'Currently supports %s' % ','.join(list_external_downloaders())))
628 downloader.add_option(
629 '--external-downloader-args',
630 dest='external_downloader_args', metavar='ARGS',
631 help='Give these arguments to the external downloader')
632
633 workarounds = optparse.OptionGroup(parser, 'Workarounds')
634 workarounds.add_option(
635 '--encoding',
636 dest='encoding', metavar='ENCODING',
637 help='Force the specified encoding (experimental)')
638 workarounds.add_option(
639 '--no-check-certificate',
640 action='store_true', dest='no_check_certificate', default=False,
641 help='Suppress HTTPS certificate validation')
642 workarounds.add_option(
643 '--prefer-insecure', '--prefer-unsecure',
644 action='store_true', dest='prefer_insecure',
645 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
646 workarounds.add_option(
647 '--user-agent',
648 metavar='UA', dest='user_agent',
649 help='Specify a custom user agent')
650 workarounds.add_option(
651 '--referer',
652 metavar='URL', dest='referer', default=None,
653 help='Specify a custom referer, use if the video access is restricted to one domain',
654 )
655 workarounds.add_option(
656 '--add-header',
657 metavar='FIELD:VALUE', dest='headers', action='append',
658 help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
659 )
660 workarounds.add_option(
661 '--bidi-workaround',
662 dest='bidi_workaround', action='store_true',
663 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
664 workarounds.add_option(
665 '--sleep-interval', '--min-sleep-interval', metavar='SECONDS',
666 dest='sleep_interval', type=float,
667 help=(
668 'Number of seconds to sleep before each download when used alone '
669 'or a lower bound of a range for randomized sleep before each download '
670 '(minimum possible number of seconds to sleep) when used along with '
671 '--max-sleep-interval.'))
672 workarounds.add_option(
673 '--max-sleep-interval', metavar='SECONDS',
674 dest='max_sleep_interval', type=float,
675 help=(
676 'Upper bound of a range for randomized sleep before each download '
677 '(maximum possible number of seconds to sleep). Must only be used '
678 'along with --min-sleep-interval.'))
679 workarounds.add_option(
680 '--sleep-subtitles', metavar='SECONDS',
681 dest='sleep_interval_subtitles', default=0, type=int,
682 help='Enforce sleep interval on subtitles as well')
683
684 verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
685 verbosity.add_option(
686 '-q', '--quiet',
687 action='store_true', dest='quiet', default=False,
688 help='Activate quiet mode')
689 verbosity.add_option(
690 '--no-warnings',
691 dest='no_warnings', action='store_true', default=False,
692 help='Ignore warnings')
693 verbosity.add_option(
694 '-s', '--simulate',
695 action='store_true', dest='simulate', default=False,
696 help='Do not download the video and do not write anything to disk')
697 verbosity.add_option(
698 '--skip-download', '--no-download',
699 action='store_true', dest='skip_download', default=False,
700 help='Do not download the video')
701 verbosity.add_option(
702 '-g', '--get-url',
703 action='store_true', dest='geturl', default=False,
704 help='Simulate, quiet but print URL')
705 verbosity.add_option(
706 '-e', '--get-title',
707 action='store_true', dest='gettitle', default=False,
708 help='Simulate, quiet but print title')
709 verbosity.add_option(
710 '--get-id',
711 action='store_true', dest='getid', default=False,
712 help='Simulate, quiet but print id')
713 verbosity.add_option(
714 '--get-thumbnail',
715 action='store_true', dest='getthumbnail', default=False,
716 help='Simulate, quiet but print thumbnail URL')
717 verbosity.add_option(
718 '--get-description',
719 action='store_true', dest='getdescription', default=False,
720 help='Simulate, quiet but print video description')
721 verbosity.add_option(
722 '--get-duration',
723 action='store_true', dest='getduration', default=False,
724 help='Simulate, quiet but print video length')
725 verbosity.add_option(
726 '--get-filename',
727 action='store_true', dest='getfilename', default=False,
728 help='Simulate, quiet but print output filename')
729 verbosity.add_option(
730 '--get-format',
731 action='store_true', dest='getformat', default=False,
732 help='Simulate, quiet but print output format')
733 verbosity.add_option(
734 '-j', '--dump-json',
735 action='store_true', dest='dumpjson', default=False,
736 help='Simulate, quiet but print JSON information. See the "OUTPUT TEMPLATE" for a description of available keys.')
737 verbosity.add_option(
738 '-J', '--dump-single-json',
739 action='store_true', dest='dump_single_json', default=False,
740 help=(
741 'Simulate, quiet but print JSON information for each command-line argument. '
742 'If the URL refers to a playlist, dump the whole playlist information in a single line.'))
743 verbosity.add_option(
744 '--print-json',
745 action='store_true', dest='print_json', default=False,
746 help='Be quiet and print the video information as JSON (video is still being downloaded).')
747 verbosity.add_option(
748 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
749 action='store_true', dest='force_write_download_archive', default=False,
750 help=(
751 'Force download archive entries to be written as far as no errors occur,'
752 'even if -s or another simulation switch is used.'))
753 verbosity.add_option(
754 '--newline',
755 action='store_true', dest='progress_with_newline', default=False,
756 help='Output progress bar as new lines')
757 verbosity.add_option(
758 '--no-progress',
759 action='store_true', dest='noprogress', default=False,
760 help='Do not print progress bar')
761 verbosity.add_option(
762 '--console-title',
763 action='store_true', dest='consoletitle', default=False,
764 help='Display progress in console titlebar')
765 verbosity.add_option(
766 '-v', '--verbose',
767 action='store_true', dest='verbose', default=False,
768 help='Print various debugging information')
769 verbosity.add_option(
770 '--dump-pages', '--dump-intermediate-pages',
771 action='store_true', dest='dump_intermediate_pages', default=False,
772 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
773 verbosity.add_option(
774 '--write-pages',
775 action='store_true', dest='write_pages', default=False,
776 help='Write downloaded intermediary pages to files in the current directory to debug problems')
777 verbosity.add_option(
778 '--youtube-print-sig-code',
779 action='store_true', dest='youtube_print_sig_code', default=False,
780 help=optparse.SUPPRESS_HELP)
781 verbosity.add_option(
782 '--print-traffic', '--dump-headers',
783 dest='debug_printtraffic', action='store_true', default=False,
784 help='Display sent and read HTTP traffic')
785 verbosity.add_option(
786 '-C', '--call-home',
787 dest='call_home', action='store_true', default=False,
788 help='[Broken] Contact the youtube-dlc server for debugging')
789 verbosity.add_option(
790 '--no-call-home',
791 dest='call_home', action='store_false',
792 help='Do not contact the youtube-dlc server for debugging (default)')
793
794 filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
795 filesystem.add_option(
796 '-a', '--batch-file',
797 dest='batchfile', metavar='FILE',
798 help="File containing URLs to download ('-' for stdin), one URL per line. "
799 "Lines starting with '#', ';' or ']' are considered as comments and ignored.")
800 filesystem.add_option(
801 '--id', default=False,
802 action='store_true', dest='useid', help=optparse.SUPPRESS_HELP)
803 filesystem.add_option(
804 '-o', '--output',
805 dest='outtmpl', metavar='TEMPLATE',
806 help='Output filename template, see the "OUTPUT TEMPLATE" for details')
807 filesystem.add_option(
808 '--autonumber-size',
809 dest='autonumber_size', metavar='NUMBER', type=int,
810 help=optparse.SUPPRESS_HELP)
811 filesystem.add_option(
812 '--autonumber-start',
813 dest='autonumber_start', metavar='NUMBER', default=1, type=int,
814 help='Specify the start value for %(autonumber)s (default is %default)')
815 filesystem.add_option(
816 '--restrict-filenames',
817 action='store_true', dest='restrictfilenames', default=False,
818 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
819 filesystem.add_option(
820 '--no-restrict-filenames',
821 action='store_false', dest='restrictfilenames', default=False,
822 help='Allow Unicode characters, "&" and spaces in filenames (default)')
823 filesystem.add_option(
824 '-A', '--auto-number',
825 action='store_true', dest='autonumber', default=False,
826 help=optparse.SUPPRESS_HELP)
827 filesystem.add_option(
828 '-t', '--title',
829 action='store_true', dest='usetitle', default=False,
830 help=optparse.SUPPRESS_HELP)
831 filesystem.add_option(
832 '-l', '--literal', default=False,
833 action='store_true', dest='usetitle',
834 help=optparse.SUPPRESS_HELP)
835 filesystem.add_option(
836 '-w', '--no-overwrites',
837 action='store_false', dest='overwrites', default=None,
838 help='Do not overwrite any files')
839 filesystem.add_option(
840 '--force-overwrites', '--yes-overwrites',
841 action='store_true', dest='overwrites',
842 help='Overwrite all video and metadata files. This option includes --no-continue')
843 filesystem.add_option(
844 '--no-force-overwrites',
845 action='store_const', dest='overwrites', const=None,
846 help='Do not overwrite the video, but overwrite related files (default)')
847 filesystem.add_option(
848 '-c', '--continue',
849 action='store_true', dest='continue_dl', default=True,
850 help='Resume partially downloaded files (default)')
851 filesystem.add_option(
852 '--no-continue',
853 action='store_false', dest='continue_dl',
854 help='Restart download of partially downloaded files from beginning')
855 filesystem.add_option(
856 '--part',
857 action='store_false', dest='nopart', default=False,
858 help='Use .part files instead of writing directly into output file (default)')
859 filesystem.add_option(
860 '--no-part',
861 action='store_true', dest='nopart',
862 help='Do not use .part files - write directly into output file')
863 filesystem.add_option(
864 '--mtime',
865 action='store_true', dest='updatetime', default=True,
866 help='Use the Last-modified header to set the file modification time (default)')
867 filesystem.add_option(
868 '--no-mtime',
869 action='store_false', dest='updatetime',
870 help='Do not use the Last-modified header to set the file modification time')
871 filesystem.add_option(
872 '--write-description',
873 action='store_true', dest='writedescription', default=False,
874 help='Write video description to a .description file')
875 filesystem.add_option(
876 '--no-write-description',
877 action='store_false', dest='writedescription',
878 help='Do not write video description (default)')
879 filesystem.add_option(
880 '--write-info-json',
881 action='store_true', dest='writeinfojson', default=False,
882 help='Write video metadata to a .info.json file')
883 filesystem.add_option(
884 '--no-write-info-json',
885 action='store_false', dest='writeinfojson',
886 help='Do not write video metadata (default)')
887 filesystem.add_option(
888 '--write-annotations',
889 action='store_true', dest='writeannotations', default=False,
890 help='Write video annotations to a .annotations.xml file')
891 filesystem.add_option(
892 '--no-write-annotations',
893 action='store_false', dest='writeannotations',
894 help='Do not write video annotations (default)')
895 filesystem.add_option(
896 '--load-info-json', '--load-info',
897 dest='load_info_filename', metavar='FILE',
898 help='JSON file containing the video information (created with the "--write-info-json" option)')
899 filesystem.add_option(
900 '--cookies',
901 dest='cookiefile', metavar='FILE',
902 help='File to read cookies from and dump cookie jar in')
903 filesystem.add_option(
904 '--no-cookies',
905 action='store_const', const=None, dest='cookiefile', metavar='FILE',
906 help='Do not read/dump cookies (default)')
907 filesystem.add_option(
908 '--cache-dir', dest='cachedir', default=None, metavar='DIR',
909 help='Location in the filesystem where youtube-dl can store some downloaded information permanently. By default $XDG_CACHE_HOME/youtube-dl or ~/.cache/youtube-dl . At the moment, only YouTube player files (for videos with obfuscated signatures) are cached, but that may change.')
910 filesystem.add_option(
911 '--no-cache-dir', action='store_false', dest='cachedir',
912 help='Disable filesystem caching')
913 filesystem.add_option(
914 '--rm-cache-dir',
915 action='store_true', dest='rm_cachedir',
916 help='Delete all filesystem cache files')
917 filesystem.add_option(
918 '--trim-file-name', metavar='LENGTH',
919 dest='trim_file_name', default=0, type=int,
920 help='Limit the filename length (extension excluded)')
921
922 thumbnail = optparse.OptionGroup(parser, 'Thumbnail Images')
923 thumbnail.add_option(
924 '--write-thumbnail',
925 action='store_true', dest='writethumbnail', default=False,
926 help='Write thumbnail image to disk')
927 thumbnail.add_option(
928 '--no-write-thumbnail',
929 action='store_false', dest='writethumbnail',
930 help='Do not write thumbnail image to disk (default)')
931 thumbnail.add_option(
932 '--write-all-thumbnails',
933 action='store_true', dest='write_all_thumbnails', default=False,
934 help='Write all thumbnail image formats to disk')
935 thumbnail.add_option(
936 '--list-thumbnails',
937 action='store_true', dest='list_thumbnails', default=False,
938 help='Simulate and list all available thumbnail formats')
939
940 link = optparse.OptionGroup(parser, 'Internet Shortcut Options')
941 link.add_option(
942 '--write-link',
943 action='store_true', dest='writelink', default=False,
944 help='Write an internet shortcut file, depending on the current platform (.url/.webloc/.desktop). The URL may be cached by the OS.')
945 link.add_option(
946 '--write-url-link',
947 action='store_true', dest='writeurllink', default=False,
948 help='Write a Windows internet shortcut file (.url). Note that the OS caches the URL based on the file path.')
949 link.add_option(
950 '--write-webloc-link',
951 action='store_true', dest='writewebloclink', default=False,
952 help='Write a macOS internet shortcut file (.webloc)')
953 link.add_option(
954 '--write-desktop-link',
955 action='store_true', dest='writedesktoplink', default=False,
956 help='Write a Linux internet shortcut file (.desktop)')
957
958 postproc = optparse.OptionGroup(parser, 'Post-Processing Options')
959 postproc.add_option(
960 '-x', '--extract-audio',
961 action='store_true', dest='extractaudio', default=False,
962 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
963 postproc.add_option(
964 '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
965 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
966 postproc.add_option(
967 '--audio-quality', metavar='QUALITY',
968 dest='audioquality', default='5',
969 help='Specify ffmpeg/avconv audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)')
970 postproc.add_option(
971 '--remux-video',
972 metavar='FORMAT', dest='remuxvideo', default=None,
973 help=(
974 'Remux the video into another container if necessary (currently supported: mp4|mkv). '
975 'If target container does not support the video/audio codec, remuxing will fail'))
976 postproc.add_option(
977 '--recode-video',
978 metavar='FORMAT', dest='recodevideo', default=None,
979 help='Re-encode the video into another format if re-encoding is necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
980 postproc.add_option(
981 '--postprocessor-args', metavar='NAME:ARGS',
982 dest='postprocessor_args', action='append',
983 help=(
984 'Give these arguments to the postprocessors. '
985 "Specify the postprocessor name and the arguments separated by a colon ':' "
986 'to give the argument to only the specified postprocessor. Supported names are '
987 'ExtractAudio, VideoRemuxer, VideoConvertor, EmbedSubtitle, Metadata, Merger, FixupStretched, FixupM4a, FixupM3u8, SubtitlesConvertor, SponSkrub and Default'
988 '. You can use this option multiple times to give different arguments to different postprocessors'))
989 postproc.add_option(
990 '-k', '--keep-video',
991 action='store_true', dest='keepvideo', default=False,
992 help='Keep the intermediate video file on disk after post-processing')
993 postproc.add_option(
994 '--no-keep-video',
995 action='store_false', dest='keepvideo',
996 help='Delete the intermediate video file after post-processing (default)')
997 postproc.add_option(
998 '--post-overwrites',
999 action='store_false', dest='nopostoverwrites',
1000 help='Overwrite post-processed files (default)')
1001 postproc.add_option(
1002 '--no-post-overwrites',
1003 action='store_true', dest='nopostoverwrites', default=False,
1004 help='Do not overwrite post-processed files')
1005 postproc.add_option(
1006 '--embed-subs',
1007 action='store_true', dest='embedsubtitles', default=False,
1008 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
1009 postproc.add_option(
1010 '--no-embed-subs',
1011 action='store_false', dest='embedsubtitles',
1012 help='Do not embed subtitles (default)')
1013 postproc.add_option(
1014 '--embed-thumbnail',
1015 action='store_true', dest='embedthumbnail', default=False,
1016 help='Embed thumbnail in the audio as cover art')
1017 postproc.add_option(
1018 '--no-embed-thumbnail',
1019 action='store_false', dest='embedthumbnail',
1020 help='Do not embed thumbnail (default)')
1021 postproc.add_option(
1022 '--add-metadata',
1023 action='store_true', dest='addmetadata', default=False,
1024 help='Write metadata to the video file')
1025 postproc.add_option(
1026 '--no-add-metadata',
1027 action='store_false', dest='addmetadata',
1028 help='Do not write metadata (default)')
1029 postproc.add_option(
1030 '--metadata-from-title',
1031 metavar='FORMAT', dest='metafromtitle',
1032 help=(
1033 'Parse additional metadata like song title / artist from the video title. '
1034 'The format syntax is the same as --output. Regular expression with '
1035 'named capture groups may also be used. '
1036 'The parsed parameters replace existing values. '
1037 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
1038 '"Coldplay - Paradise". '
1039 'Example (regex): --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"'))
1040 postproc.add_option(
1041 '--xattrs',
1042 action='store_true', dest='xattrs', default=False,
1043 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
1044 postproc.add_option(
1045 '--fixup',
1046 metavar='POLICY', dest='fixup', default='detect_or_warn',
1047 help=(
1048 'Automatically correct known faults of the file. '
1049 'One of never (do nothing), warn (only emit a warning), '
1050 'detect_or_warn (the default; fix file if we can, warn otherwise)'))
1051 postproc.add_option(
1052 '--prefer-avconv', '--no-prefer-ffmpeg',
1053 action='store_false', dest='prefer_ffmpeg',
1054 help='Prefer avconv over ffmpeg for running the postprocessors')
1055 postproc.add_option(
1056 '--prefer-ffmpeg', '--no-prefer-avconv',
1057 action='store_true', dest='prefer_ffmpeg',
1058 help='Prefer ffmpeg over avconv for running the postprocessors (default)')
1059 postproc.add_option(
1060 '--ffmpeg-location', '--avconv-location', metavar='PATH',
1061 dest='ffmpeg_location',
1062 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
1063 postproc.add_option(
1064 '--exec',
1065 metavar='CMD', dest='exec_cmd',
1066 help='Execute a command on the file after downloading and post-processing, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
1067 postproc.add_option(
1068 '--convert-subs', '--convert-subtitles',
1069 metavar='FORMAT', dest='convertsubtitles', default=None,
1070 help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)')
1071
1072 sponskrub = optparse.OptionGroup(parser, 'SponSkrub Options (SponsorBlock)')
1073 sponskrub.add_option(
1074 '--sponskrub',
1075 action='store_true', dest='sponskrub', default=None,
1076 help=(
1077 'Use sponskrub to mark sponsored sections with the data available in SponsorBlock API. '
1078 'This is enabled by default if the sponskrub binary exists (Youtube only)'))
1079 sponskrub.add_option(
1080 '--no-sponskrub',
1081 action='store_false', dest='sponskrub',
1082 help='Do not use sponskrub')
1083 sponskrub.add_option(
1084 '--sponskrub-cut', default=False,
1085 action='store_true', dest='sponskrub_cut',
1086 help='Cut out the sponsor sections instead of simply marking them')
1087 sponskrub.add_option(
1088 '--no-sponskrub-cut',
1089 action='store_false', dest='sponskrub_cut',
1090 help='Simply mark the sponsor sections, not cut them out (default)')
1091 sponskrub.add_option(
1092 '--sponskrub-force', default=False,
1093 action='store_true', dest='sponskrub_force',
1094 help='Run sponskrub even if the video was already downloaded')
1095 sponskrub.add_option(
1096 '--no-sponskrub-force',
1097 action='store_true', dest='sponskrub_force',
1098 help='Do not cut out the sponsor sections if the video was already downloaded (default)')
1099 sponskrub.add_option(
1100 '--sponskrub-location', metavar='PATH',
1101 dest='sponskrub_path', default='',
1102 help='Location of the sponskrub binary; either the path to the binary or its containing directory.')
1103 sponskrub.add_option(
1104 '--sponskrub-args', dest='sponskrub_args', metavar='ARGS',
1105 help=optparse.SUPPRESS_HELP)
1106
1107 extractor = optparse.OptionGroup(parser, 'Extractor Options')
1108 extractor.add_option(
1109 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
1110 action='store_true', dest='dynamic_mpd', default=True,
1111 help='Process dynamic DASH manifests (default)')
1112 extractor.add_option(
1113 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
1114 action='store_false', dest='dynamic_mpd',
1115 help='Do not process dynamic DASH manifests')
1116
1117 parser.add_option_group(general)
1118 parser.add_option_group(network)
1119 parser.add_option_group(geo)
1120 parser.add_option_group(selection)
1121 parser.add_option_group(downloader)
1122 parser.add_option_group(filesystem)
1123 parser.add_option_group(thumbnail)
1124 parser.add_option_group(link)
1125 parser.add_option_group(verbosity)
1126 parser.add_option_group(workarounds)
1127 parser.add_option_group(video_format)
1128 parser.add_option_group(subtitles)
1129 parser.add_option_group(authentication)
1130 parser.add_option_group(adobe_pass)
1131 parser.add_option_group(postproc)
1132 parser.add_option_group(sponskrub)
1133 parser.add_option_group(extractor)
1134
1135 if overrideArguments is not None:
1136 opts, args = parser.parse_args(overrideArguments)
1137 if opts.verbose:
1138 write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
1139 else:
1140 def compat_conf(conf):
1141 if sys.version_info < (3,):
1142 return [a.decode(preferredencoding(), 'replace') for a in conf]
1143 return conf
1144
1145 command_line_conf = compat_conf(sys.argv[1:])
1146 opts, args = parser.parse_args(command_line_conf)
1147
1148 system_conf = user_conf = custom_conf = []
1149
1150 if '--config-location' in command_line_conf:
1151 location = compat_expanduser(opts.config_location)
1152 if os.path.isdir(location):
1153 location = os.path.join(location, 'youtube-dlc.conf')
1154 if not os.path.exists(location):
1155 parser.error('config-location %s does not exist.' % location)
1156 custom_conf = _readOptions(location)
1157 elif '--ignore-config' in command_line_conf:
1158 pass
1159 else:
1160 system_conf = _readOptions('/etc/youtube-dlc.conf')
1161 if '--ignore-config' not in system_conf:
1162 user_conf = _readUserConf()
1163
1164 argv = system_conf + user_conf + custom_conf + command_line_conf
1165 opts, args = parser.parse_args(argv)
1166 if opts.verbose:
1167 for conf_label, conf in (
1168 ('System config', system_conf),
1169 ('User config', user_conf),
1170 ('Custom config', custom_conf),
1171 ('Command-line args', command_line_conf)):
1172 write_string('[debug] %s: %s\n' % (conf_label, repr(_hide_login_info(conf))))
1173
1174 return parser, opts, args