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