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