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