]>
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 | ||
8c25f81b | 8 | from .compat import ( |
4644ac55 | 9 | compat_expanduser, |
003c69a8 | 10 | compat_get_terminal_size, |
4644ac55 | 11 | compat_getenv, |
c7b0add8 | 12 | compat_kwargs, |
cab792ab | 13 | compat_shlex_split, |
8c25f81b PH |
14 | ) |
15 | from .utils import ( | |
0202b52a | 16 | expand_path, |
f74980cb | 17 | get_executable_path, |
de6000d9 | 18 | OUTTMPL_TYPES, |
1e43a6f7 | 19 | POSTPROCESS_WHEN, |
ff556f5c | 20 | preferredencoding, |
3ae5e797 | 21 | remove_end, |
34a741a8 PH |
22 | write_string, |
23 | ) | |
f59f5ef8 | 24 | from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS |
34a741a8 PH |
25 | from .version import __version__ |
26 | ||
81a23040 | 27 | from .downloader.external import list_external_downloaders |
ad3dc496 | 28 | from .postprocessor import ( |
81a23040 | 29 | FFmpegExtractAudioPP, |
30 | FFmpegSubtitlesConvertorPP, | |
31 | FFmpegThumbnailsConvertorPP, | |
32 | FFmpegVideoRemuxerPP, | |
7a340e0d | 33 | SponsorBlockPP, |
81a23040 | 34 | ) |
7a340e0d | 35 | from .postprocessor.modify_chapters import DEFAULT_SPONSORBLOCK_CHAPTER_TITLE |
81a23040 | 36 | |
34a741a8 | 37 | |
905d18a7 YCH |
38 | def _hide_login_info(opts): |
39 | PRIVATE_OPTS = set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username']) | |
40 | eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$') | |
41 | ||
42 | def _scrub_eq(o): | |
43 | m = eqre.match(o) | |
44 | if m: | |
45 | return m.group('key') + '=PRIVATE' | |
46 | else: | |
47 | return o | |
48 | ||
49 | opts = list(map(_scrub_eq, opts)) | |
50 | for idx, opt in enumerate(opts): | |
51 | if opt in PRIVATE_OPTS and idx + 1 < len(opts): | |
52 | opts[idx + 1] = 'PRIVATE' | |
53 | return opts | |
54 | ||
55 | ||
34a741a8 PH |
56 | def parseOpts(overrideArguments=None): |
57 | def _readOptions(filename_bytes, default=[]): | |
58 | try: | |
59 | optionf = open(filename_bytes) | |
60 | except IOError: | |
61 | return default # silently skip if file is not present | |
62 | try: | |
067aa17e | 63 | # FIXME: https://github.com/ytdl-org/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56 |
1251565e S |
64 | contents = optionf.read() |
65 | if sys.version_info < (3,): | |
66 | contents = contents.decode(preferredencoding()) | |
67 | res = compat_shlex_split(contents, comments=True) | |
34a741a8 PH |
68 | finally: |
69 | optionf.close() | |
70 | return res | |
71 | ||
e2e43aea | 72 | def _readUserConf(package_name, default=[]): |
73 | # .config | |
74 | xdg_config_home = compat_getenv('XDG_CONFIG_HOME') or compat_expanduser('~/.config') | |
75 | userConfFile = os.path.join(xdg_config_home, package_name, 'config') | |
76 | if not os.path.isfile(userConfFile): | |
77 | userConfFile = os.path.join(xdg_config_home, '%s.conf' % package_name) | |
78 | userConf = _readOptions(userConfFile, default=None) | |
79 | if userConf is not None: | |
0202b52a | 80 | return userConf, userConfFile |
34a741a8 | 81 | |
e2e43aea | 82 | # appdata |
83 | appdata_dir = compat_getenv('appdata') | |
84 | if appdata_dir: | |
85 | userConfFile = os.path.join(appdata_dir, package_name, 'config') | |
86 | userConf = _readOptions(userConfFile, default=None) | |
87 | if userConf is None: | |
0202b52a | 88 | userConfFile += '.txt' |
89 | userConf = _readOptions(userConfFile, default=None) | |
e2e43aea | 90 | if userConf is not None: |
0202b52a | 91 | return userConf, userConfFile |
34a741a8 | 92 | |
e2e43aea | 93 | # home |
94 | userConfFile = os.path.join(compat_expanduser('~'), '%s.conf' % package_name) | |
95 | userConf = _readOptions(userConfFile, default=None) | |
34a741a8 | 96 | if userConf is None: |
0202b52a | 97 | userConfFile += '.txt' |
98 | userConf = _readOptions(userConfFile, default=None) | |
e2e43aea | 99 | if userConf is not None: |
0202b52a | 100 | return userConf, userConfFile |
34a741a8 | 101 | |
0202b52a | 102 | return default, None |
34a741a8 PH |
103 | |
104 | def _format_option_string(option): | |
105 | ''' ('-o', '--option') -> -o, --format METAVAR''' | |
106 | ||
107 | opts = [] | |
108 | ||
109 | if option._short_opts: | |
110 | opts.append(option._short_opts[0]) | |
111 | if option._long_opts: | |
112 | opts.append(option._long_opts[0]) | |
113 | if len(opts) > 1: | |
114 | opts.insert(1, ', ') | |
115 | ||
8450c15c PH |
116 | if option.takes_value(): |
117 | opts.append(' %s' % option.metavar) | |
34a741a8 | 118 | |
611c1dd9 | 119 | return ''.join(opts) |
34a741a8 | 120 | |
d21bba78 | 121 | def _list_from_options_callback(option, opt_str, value, parser, append=True, delim=',', process=str.strip): |
e632bce2 | 122 | # append can be True, False or -1 (prepend) |
123 | current = getattr(parser.values, option.dest) if append else [] | |
1f8471e2 | 124 | value = list(filter(None, [process(value)] if delim is None else map(process, value.split(delim)))) |
d818eb74 | 125 | setattr( |
126 | parser.values, option.dest, | |
e632bce2 | 127 | current + value if append is True else value + current) |
34a741a8 | 128 | |
31654882 | 129 | def _set_from_options_callback( |
d21bba78 | 130 | option, opt_str, value, parser, delim=',', allowed_values=None, aliases={}, |
131 | process=lambda x: x.lower().strip()): | |
31654882 | 132 | current = getattr(parser.values, option.dest) |
d21bba78 | 133 | values = [process(value)] if delim is None else list(map(process, value.split(delim)[::-1])) |
31654882 | 134 | while values: |
135 | actual_val = val = values.pop() | |
136 | if val == 'all': | |
137 | current.update(allowed_values) | |
138 | elif val == '-all': | |
139 | current = set() | |
140 | elif val in aliases: | |
141 | values.extend(aliases[val]) | |
142 | else: | |
143 | if val[0] == '-': | |
144 | val = val[1:] | |
145 | current.discard(val) | |
146 | else: | |
147 | current.update([val]) | |
148 | if allowed_values is not None and val not in allowed_values: | |
149 | raise optparse.OptionValueError(f'wrong {option.metavar} for {opt_str}: {actual_val}') | |
150 | ||
151 | setattr(parser.values, option.dest, current) | |
152 | ||
e632bce2 | 153 | def _dict_from_options_callback( |
d818eb74 | 154 | option, opt_str, value, parser, |
44bcb8d1 | 155 | allowed_keys=r'[\w-]+', delimiter=':', default_key=None, process=None, multiple_keys=True, |
ca30f449 | 156 | process_key=str.lower, append=False): |
45016689 | 157 | |
ca30f449 | 158 | out_dict = dict(getattr(parser.values, option.dest)) |
d818eb74 | 159 | if multiple_keys: |
160 | allowed_keys = r'(%s)(,(%s))*' % (allowed_keys, allowed_keys) | |
161 | mobj = re.match(r'(?i)(?P<keys>%s)%s(?P<val>.*)$' % (allowed_keys, delimiter), value) | |
45016689 | 162 | if mobj is not None: |
44bcb8d1 | 163 | keys, val = mobj.group('keys').split(','), mobj.group('val') |
45016689 | 164 | elif default_key is not None: |
d818eb74 | 165 | keys, val = [default_key], value |
45016689 | 166 | else: |
167 | raise optparse.OptionValueError( | |
168 | 'wrong %s formatting; it should be %s, not "%s"' % (opt_str, option.metavar, value)) | |
4bb6b02f | 169 | try: |
44bcb8d1 | 170 | keys = map(process_key, keys) if process_key else keys |
4bb6b02f | 171 | val = process(val) if process else val |
172 | except Exception as err: | |
44bcb8d1 | 173 | raise optparse.OptionValueError(f'wrong {opt_str} formatting; {err}') |
d818eb74 | 174 | for key in keys: |
ca30f449 | 175 | out_dict[key] = out_dict.get(key, []) + [val] if append else val |
176 | setattr(parser.values, option.dest, out_dict) | |
45016689 | 177 | |
34a741a8 | 178 | # No need to wrap help messages if we're on a wide console |
003c69a8 | 179 | columns = compat_get_terminal_size().columns |
8450c15c | 180 | max_width = columns if columns else 80 |
982ee69a MB |
181 | # 47% is chosen because that is how README.md is currently formatted |
182 | # and moving help text even further to the right is undesirable. | |
183 | # This can be reduced in the future to get a prettier output | |
184 | max_help_position = int(0.47 * max_width) | |
34a741a8 PH |
185 | |
186 | fmt = optparse.IndentedHelpFormatter(width=max_width, max_help_position=max_help_position) | |
187 | fmt.format_option_strings = _format_option_string | |
188 | ||
189 | kw = { | |
8450c15c PH |
190 | 'version': __version__, |
191 | 'formatter': fmt, | |
a42419da | 192 | 'usage': '%prog [OPTIONS] URL [URL...]', |
8450c15c | 193 | 'conflict_handler': 'resolve', |
34a741a8 PH |
194 | } |
195 | ||
c7b0add8 | 196 | parser = optparse.OptionParser(**compat_kwargs(kw)) |
34a741a8 | 197 | |
8450c15c PH |
198 | general = optparse.OptionGroup(parser, 'General Options') |
199 | general.add_option( | |
200 | '-h', '--help', | |
201 | action='help', | |
17941321 | 202 | help='Print this help text and exit') |
8450c15c | 203 | general.add_option( |
b76f0e58 | 204 | '--version', |
8450c15c | 205 | action='version', |
17941321 | 206 | help='Print program version and exit') |
8450c15c PH |
207 | general.add_option( |
208 | '-U', '--update', | |
209 | action='store_true', dest='update_self', | |
8d801631 | 210 | help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)') |
8450c15c | 211 | general.add_option( |
b1940459 | 212 | '-i', '--ignore-errors', |
213 | action='store_true', dest='ignoreerrors', | |
0930b11f | 214 | help='Ignore download and postprocessing errors. The download will be considered successful even if the postprocessing fails') |
b1940459 | 215 | general.add_option( |
216 | '--no-abort-on-error', | |
217 | action='store_const', dest='ignoreerrors', const='only_download', | |
218 | help='Continue with next video on download errors; e.g. to skip unavailable videos in a playlist (default)') | |
8450c15c | 219 | general.add_option( |
6623ac34 | 220 | '--abort-on-error', '--no-ignore-errors', |
8450c15c | 221 | action='store_false', dest='ignoreerrors', |
8a51f564 | 222 | help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)') |
8450c15c PH |
223 | general.add_option( |
224 | '--dump-user-agent', | |
225 | action='store_true', dest='dump_user_agent', default=False, | |
34488702 | 226 | help='Display the current user-agent and exit') |
34a741a8 | 227 | general.add_option( |
8450c15c PH |
228 | '--list-extractors', |
229 | action='store_true', dest='list_extractors', default=False, | |
b7b04c78 | 230 | help='List all supported extractors and exit') |
8450c15c PH |
231 | general.add_option( |
232 | '--extractor-descriptions', | |
233 | action='store_true', dest='list_extractor_descriptions', default=False, | |
b7b04c78 | 234 | help='Output descriptions of all supported extractors and exit') |
d22dec74 S |
235 | general.add_option( |
236 | '--force-generic-extractor', | |
237 | action='store_true', dest='force_generic_extractor', default=False, | |
238 | help='Force extraction to use the generic extractor') | |
34a741a8 PH |
239 | general.add_option( |
240 | '--default-search', | |
241 | dest='default_search', metavar='PREFIX', | |
9ee4f0bb | 242 | help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for the search term "large apple". Use the value "auto" to let yt-dlp 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 | 243 | general.add_option( |
6623ac34 | 244 | '--ignore-config', '--no-config', |
7303f84a | 245 | action='store_true', dest='ignoreconfig', |
6623ac34 | 246 | help=( |
298f597b | 247 | 'Disable loading any configuration files except the one provided by --config-location. ' |
248 | 'When given inside a configuration file, no further configuration files are loaded. ' | |
249 | 'Additionally, (for backward compatibility) if this option is found inside the ' | |
8a51f564 | 250 | 'system configuration file, the user configuration is not loaded')) |
e66dca5e | 251 | general.add_option( |
b6ee45e9 S |
252 | '--config-location', |
253 | dest='config_location', metavar='PATH', | |
0202b52a | 254 | help='Location of the main configuration file; either the path to the config or its containing directory') |
057a5206 PH |
255 | general.add_option( |
256 | '--flat-playlist', | |
6623ac34 | 257 | action='store_const', dest='extract_flat', const='in_playlist', default=False, |
8a51f564 | 258 | help='Do not extract the videos of a playlist, only list them') |
6623ac34 | 259 | general.add_option( |
260 | '--no-flat-playlist', | |
261 | action='store_false', dest='extract_flat', | |
262 | help='Extract the videos of a playlist') | |
adbc4ec4 THD |
263 | general.add_option( |
264 | '--live-from-start', | |
265 | action='store_true', dest='live_from_start', | |
266 | help='Download livestreams from the start. Currently only supported for YouTube') | |
267 | general.add_option( | |
268 | '--no-live-from-start', | |
269 | action='store_false', dest='live_from_start', | |
270 | help='Download livestreams from the current time (default)') | |
f2ebc5c7 | 271 | general.add_option( |
272 | '--wait-for-video', | |
273 | dest='wait_for_video', metavar='MIN[-MAX]', default=None, | |
274 | help=( | |
275 | 'Wait for scheduled streams to become available. ' | |
276 | 'Pass the minimum number of seconds (or range) to wait between retries')) | |
277 | general.add_option( | |
278 | '--no-wait-for-video', | |
279 | dest='wait_for_video', action='store_const', const=None, | |
280 | help='Do not wait for scheduled streams (default)') | |
d77ab8e2 S |
281 | general.add_option( |
282 | '--mark-watched', | |
283 | action='store_true', dest='mark_watched', default=False, | |
e6f21b3d | 284 | help='Mark videos watched (even with --simulate). Currently only supported for YouTube') |
90f794c6 S |
285 | general.add_option( |
286 | '--no-mark-watched', | |
597c1866 | 287 | action='store_false', dest='mark_watched', |
288 | help='Do not mark videos watched (default)') | |
7e5db8c9 | 289 | general.add_option( |
8a51f564 | 290 | '--no-colors', |
597c1866 | 291 | action='store_true', dest='no_color', default=False, |
17941321 | 292 | help='Do not emit color codes in output') |
53ed7066 | 293 | general.add_option( |
294 | '--compat-options', | |
31654882 | 295 | metavar='OPTS', dest='compat_opts', default=set(), type='str', |
296 | action='callback', callback=_set_from_options_callback, | |
297 | callback_kwargs={ | |
298 | 'allowed_values': { | |
299 | 'filename', 'format-sort', 'abort-on-error', 'format-spec', 'no-playlist-metafiles', | |
300 | 'multistreams', 'no-live-chat', 'playlist-index', 'list-formats', 'no-direct-merge', | |
f279aaee | 301 | 'no-youtube-channel-redirect', 'no-youtube-unavailable-videos', 'no-attach-info-json', 'embed-metadata', |
31654882 | 302 | 'embed-thumbnail-atomicparsley', 'seperate-video-versions', 'no-clean-infojson', 'no-keep-subs', |
d21bba78 | 303 | }, 'aliases': { |
31654882 | 304 | 'youtube-dl': ['-multistreams', 'all'], |
305 | 'youtube-dlc': ['-no-youtube-channel-redirect', '-no-live-chat', 'all'], | |
306 | } | |
307 | }, help=( | |
308 | 'Options that can help keep compatibility with youtube-dl or youtube-dlc ' | |
53ed7066 | 309 | 'configurations by reverting some of the changes made in yt-dlp. ' |
310 | 'See "Differences in default behavior" for details')) | |
34a741a8 | 311 | |
be4a824d PH |
312 | network = optparse.OptionGroup(parser, 'Network Options') |
313 | network.add_option( | |
314 | '--proxy', dest='proxy', | |
315 | default=None, metavar='URL', | |
6623ac34 | 316 | help=( |
317 | 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable ' | |
318 | 'SOCKS proxy, specify a proper scheme. For example ' | |
319 | 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") ' | |
320 | 'for direct connection')) | |
be4a824d PH |
321 | network.add_option( |
322 | '--socket-timeout', | |
323 | dest='socket_timeout', type=float, default=None, metavar='SECONDS', | |
324 | help='Time to wait before giving up, in seconds') | |
325 | network.add_option( | |
326 | '--source-address', | |
327 | metavar='IP', dest='source_address', default=None, | |
24ee6b97 | 328 | help='Client-side IP address to bind to', |
be4a824d | 329 | ) |
500b8b41 PH |
330 | network.add_option( |
331 | '-4', '--force-ipv4', | |
332 | action='store_const', const='0.0.0.0', dest='source_address', | |
24ee6b97 | 333 | help='Make all connections via IPv4', |
500b8b41 PH |
334 | ) |
335 | network.add_option( | |
336 | '-6', '--force-ipv6', | |
337 | action='store_const', const='::', dest='source_address', | |
24ee6b97 | 338 | help='Make all connections via IPv6', |
500b8b41 | 339 | ) |
0aa10994 | 340 | |
b31fdeed | 341 | geo = optparse.OptionGroup(parser, 'Geo-restriction') |
0aa10994 | 342 | geo.add_option( |
38cce791 YCH |
343 | '--geo-verification-proxy', |
344 | dest='geo_verification_proxy', default=None, metavar='URL', | |
6623ac34 | 345 | help=( |
346 | 'Use this proxy to verify the IP address for some geo-restricted sites. ' | |
8a51f564 | 347 | 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading')) |
0aa10994 | 348 | geo.add_option( |
91410c9b PH |
349 | '--cn-verification-proxy', |
350 | dest='cn_verification_proxy', default=None, metavar='URL', | |
0aa10994 S |
351 | help=optparse.SUPPRESS_HELP) |
352 | geo.add_option( | |
353 | '--geo-bypass', | |
354 | action='store_true', dest='geo_bypass', default=True, | |
504f20dd | 355 | help='Bypass geographic restriction via faking X-Forwarded-For HTTP header') |
0aa10994 S |
356 | geo.add_option( |
357 | '--no-geo-bypass', | |
358 | action='store_false', dest='geo_bypass', default=True, | |
504f20dd | 359 | help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header') |
0aa10994 S |
360 | geo.add_option( |
361 | '--geo-bypass-country', metavar='CODE', | |
362 | dest='geo_bypass_country', default=None, | |
504f20dd | 363 | help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code') |
5f95927a S |
364 | geo.add_option( |
365 | '--geo-bypass-ip-block', metavar='IP_BLOCK', | |
366 | dest='geo_bypass_ip_block', default=None, | |
504f20dd | 367 | help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation') |
be4a824d | 368 | |
8450c15c | 369 | selection = optparse.OptionGroup(parser, 'Video Selection') |
34a741a8 PH |
370 | selection.add_option( |
371 | '--playlist-start', | |
372 | dest='playliststart', metavar='NUMBER', default=1, type=int, | |
17941321 | 373 | help='Playlist video to start at (default is %default)') |
34a741a8 PH |
374 | selection.add_option( |
375 | '--playlist-end', | |
376 | dest='playlistend', metavar='NUMBER', default=None, type=int, | |
17941321 | 377 | help='Playlist video to end at (default is last)') |
c14e88f0 PH |
378 | selection.add_option( |
379 | '--playlist-items', | |
380 | dest='playlist_items', metavar='ITEM_SPEC', default=None, | |
8a51f564 | 381 | 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 | 382 | selection.add_option( |
8450c15c PH |
383 | '--match-title', |
384 | dest='matchtitle', metavar='REGEX', | |
8f18aca8 | 385 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
386 | selection.add_option( |
387 | '--reject-title', | |
388 | dest='rejecttitle', metavar='REGEX', | |
8f18aca8 | 389 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
390 | selection.add_option( |
391 | '--min-filesize', | |
392 | metavar='SIZE', dest='min_filesize', default=None, | |
393 | help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)') | |
394 | selection.add_option( | |
395 | '--max-filesize', | |
396 | metavar='SIZE', dest='max_filesize', default=None, | |
397 | help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)') | |
398 | selection.add_option( | |
399 | '--date', | |
400 | metavar='DATE', dest='date', default=None, | |
c76eb41b | 401 | help=( |
0930b11f | 402 | 'Download only videos uploaded on this date. ' |
8a51f564 | 403 | 'The date can be "YYYYMMDD" or in the format ' |
c76eb41b | 404 | '"(now|today)[+-][0-9](day|week|month|year)(s)?"')) |
8450c15c PH |
405 | selection.add_option( |
406 | '--datebefore', | |
407 | metavar='DATE', dest='datebefore', default=None, | |
c76eb41b | 408 | help=( |
409 | 'Download only videos uploaded on or before this date. ' | |
410 | 'The date formats accepted is the same as --date')) | |
34a741a8 | 411 | selection.add_option( |
8450c15c PH |
412 | '--dateafter', |
413 | metavar='DATE', dest='dateafter', default=None, | |
c76eb41b | 414 | help=( |
415 | 'Download only videos uploaded on or after this date. ' | |
416 | 'The date formats accepted is the same as --date')) | |
34a741a8 | 417 | selection.add_option( |
8450c15c PH |
418 | '--min-views', |
419 | metavar='COUNT', dest='min_views', default=None, type=int, | |
8f18aca8 | 420 | help=optparse.SUPPRESS_HELP) |
34a741a8 | 421 | selection.add_option( |
8450c15c PH |
422 | '--max-views', |
423 | metavar='COUNT', dest='max_views', default=None, type=int, | |
8f18aca8 | 424 | help=optparse.SUPPRESS_HELP) |
347de493 PH |
425 | selection.add_option( |
426 | '--match-filter', | |
427 | metavar='FILTER', dest='match_filter', default=None, | |
428 | help=( | |
77b87f05 MT |
429 | 'Generic video filter. Any field (see "OUTPUT TEMPLATE") can be compared with a ' |
430 | 'number or a string using the operators defined in "Filtering formats". ' | |
431 | 'You can also simply specify a field to match if the field is present ' | |
a047eeb6 | 432 | 'and "!field" to check if the field is not present. In addition, ' |
433 | 'Python style regular expression matching can be done using "~=", ' | |
434 | 'and multiple filters can be checked with "&". ' | |
435 | 'Use a "\\" to escape "&" or quotes if needed. Eg: --match-filter ' | |
2e7781a9 | 436 | '"!is_live & like_count>?100 & description~=\'(?i)\\bcats \\& dogs\\b\'" ' |
a047eeb6 | 437 | 'matches only videos that are not live, has a like count more than 100 ' |
438 | '(or the like field is not available), and also has a description ' | |
439 | 'that contains the phrase "cats & dogs" (ignoring case)')) | |
6623ac34 | 440 | selection.add_option( |
441 | '--no-match-filter', | |
442 | metavar='FILTER', dest='match_filter', action='store_const', const=None, | |
443 | help='Do not use generic video filter (default)') | |
34a741a8 | 444 | selection.add_option( |
8450c15c PH |
445 | '--no-playlist', |
446 | action='store_true', dest='noplaylist', default=False, | |
8a51f564 | 447 | help='Download only the video, if the URL refers to a video and a playlist') |
df4bd0d5 PH |
448 | selection.add_option( |
449 | '--yes-playlist', | |
f0884c8b | 450 | action='store_false', dest='noplaylist', |
8a51f564 | 451 | help='Download the playlist, if the URL refers to a video and a playlist') |
8450c15c PH |
452 | selection.add_option( |
453 | '--age-limit', | |
454 | metavar='YEARS', dest='age_limit', default=None, type=int, | |
17941321 | 455 | help='Download only videos suitable for the given age') |
8450c15c PH |
456 | selection.add_option( |
457 | '--download-archive', metavar='FILE', | |
458 | dest='download_archive', | |
8a51f564 | 459 | help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it') |
f304da8a | 460 | selection.add_option( |
461 | '--no-download-archive', | |
462 | dest='download_archive', action="store_const", const=None, | |
463 | help='Do not use archive file (default)') | |
464 | selection.add_option( | |
465 | '--max-downloads', | |
466 | dest='max_downloads', metavar='NUMBER', type=int, default=None, | |
467 | help='Abort after downloading NUMBER files') | |
ea6e0c2b | 468 | selection.add_option( |
469 | '--break-on-existing', | |
470 | action='store_true', dest='break_on_existing', default=False, | |
8a51f564 | 471 | help='Stop the download process when encountering a file that is in the archive') |
8b0d7497 | 472 | selection.add_option( |
473 | '--break-on-reject', | |
474 | action='store_true', dest='break_on_reject', default=False, | |
8a51f564 | 475 | help='Stop the download process when encountering a file that has been filtered out') |
b222c271 | 476 | selection.add_option( |
477 | '--break-per-input', | |
478 | action='store_true', dest='break_per_url', default=False, | |
479 | help='Make --break-on-existing and --break-on-reject act only on the current input URL') | |
480 | selection.add_option( | |
481 | '--no-break-per-input', | |
482 | action='store_false', dest='break_per_url', | |
483 | help='--break-on-existing and --break-on-reject terminates the entire download queue') | |
26e2805c | 484 | selection.add_option( |
485 | '--skip-playlist-after-errors', metavar='N', | |
486 | dest='skip_playlist_after_errors', default=None, type=int, | |
487 | help='Number of allowed failures until the rest of the playlist is skipped') | |
8450c15c PH |
488 | selection.add_option( |
489 | '--include-ads', | |
490 | dest='include_ads', action='store_true', | |
d9aa2332 | 491 | help=optparse.SUPPRESS_HELP) |
6623ac34 | 492 | selection.add_option( |
493 | '--no-include-ads', | |
494 | dest='include_ads', action='store_false', | |
d9aa2332 | 495 | help=optparse.SUPPRESS_HELP) |
34a741a8 | 496 | |
8450c15c PH |
497 | authentication = optparse.OptionGroup(parser, 'Authentication Options') |
498 | authentication.add_option( | |
499 | '-u', '--username', | |
500 | dest='username', metavar='USERNAME', | |
17941321 | 501 | help='Login with this account ID') |
8450c15c PH |
502 | authentication.add_option( |
503 | '-p', '--password', | |
504 | dest='password', metavar='PASSWORD', | |
7a5c1cfe | 505 | help='Account password. If this option is left out, yt-dlp will ask interactively') |
8450c15c PH |
506 | authentication.add_option( |
507 | '-2', '--twofactor', | |
508 | dest='twofactor', metavar='TWOFACTOR', | |
3540fe26 | 509 | help='Two-factor authentication code') |
8450c15c PH |
510 | authentication.add_option( |
511 | '-n', '--netrc', | |
512 | action='store_true', dest='usenetrc', default=False, | |
17941321 | 513 | help='Use .netrc authentication data') |
0001fcb5 | 514 | authentication.add_option( |
515 | '--netrc-location', | |
516 | dest='netrc_location', metavar='PATH', | |
517 | help='Location of .netrc authentication data; either the path or its containing directory. Defaults to ~/.netrc') | |
8450c15c PH |
518 | authentication.add_option( |
519 | '--video-password', | |
520 | dest='videopassword', metavar='PASSWORD', | |
29f7c58a | 521 | help='Video password (vimeo, youku)') |
b31fdeed | 522 | authentication.add_option( |
797c636b RA |
523 | '--ap-mso', |
524 | dest='ap_mso', metavar='MSO', | |
537f7533 | 525 | help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs') |
b31fdeed | 526 | authentication.add_option( |
1b6712ab | 527 | '--ap-username', |
797c636b | 528 | dest='ap_username', metavar='USERNAME', |
537f7533 | 529 | help='Multiple-system operator account login') |
b31fdeed | 530 | authentication.add_option( |
1b6712ab | 531 | '--ap-password', |
797c636b | 532 | dest='ap_password', metavar='PASSWORD', |
7a5c1cfe | 533 | help='Multiple-system operator account password. If this option is left out, yt-dlp will ask interactively') |
b31fdeed | 534 | authentication.add_option( |
87148bb7 RA |
535 | '--ap-list-mso', |
536 | action='store_true', dest='ap_list_mso', default=False, | |
537f7533 | 537 | help='List all supported multiple-system operators') |
8450c15c PH |
538 | |
539 | video_format = optparse.OptionGroup(parser, 'Video Format Options') | |
540 | video_format.add_option( | |
541 | '-f', '--format', | |
542 | action='store', dest='format', metavar='FORMAT', default=None, | |
eb8a4433 | 543 | help='Video format code, see "FORMAT SELECTION" for more details') |
544 | video_format.add_option( | |
c76eb41b | 545 | '-S', '--format-sort', metavar='SORTORDER', |
e632bce2 | 546 | dest='format_sort', default=[], type='str', action='callback', |
547 | callback=_list_from_options_callback, callback_kwargs={'append': -1}, | |
eb8a4433 | 548 | help='Sort the formats by the fields given, see "Sorting Formats" for more details') |
549 | video_format.add_option( | |
550 | '--format-sort-force', '--S-force', | |
551 | action='store_true', dest='format_sort_force', metavar='FORMAT', default=False, | |
552 | help=( | |
553 | 'Force user specified sort order to have precedence over all fields, ' | |
554 | 'see "Sorting Formats" for more details')) | |
555 | video_format.add_option( | |
556 | '--no-format-sort-force', | |
557 | action='store_false', dest='format_sort_force', metavar='FORMAT', default=False, | |
558 | help=( | |
559 | 'Some fields have precedence over the user specified sort order (default), ' | |
560 | 'see "Sorting Formats" for more details')) | |
909d24dd | 561 | video_format.add_option( |
562 | '--video-multistreams', | |
53ed7066 | 563 | action='store_true', dest='allow_multiple_video_streams', default=None, |
91ebc640 | 564 | help='Allow multiple video streams to be merged into a single file') |
909d24dd | 565 | video_format.add_option( |
566 | '--no-video-multistreams', | |
567 | action='store_false', dest='allow_multiple_video_streams', | |
91ebc640 | 568 | help='Only one video stream is downloaded for each output file (default)') |
909d24dd | 569 | video_format.add_option( |
570 | '--audio-multistreams', | |
53ed7066 | 571 | action='store_true', dest='allow_multiple_audio_streams', default=None, |
91ebc640 | 572 | help='Allow multiple audio streams to be merged into a single file') |
909d24dd | 573 | video_format.add_option( |
574 | '--no-audio-multistreams', | |
575 | action='store_false', dest='allow_multiple_audio_streams', | |
91ebc640 | 576 | help='Only one audio stream is downloaded for each output file (default)') |
8450c15c PH |
577 | video_format.add_option( |
578 | '--all-formats', | |
579 | action='store_const', dest='format', const='all', | |
d9aa2332 | 580 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
581 | video_format.add_option( |
582 | '--prefer-free-formats', | |
583 | action='store_true', dest='prefer_free_formats', default=False, | |
da9be05e | 584 | help=( |
585 | 'Prefer video formats with free containers over non-free ones of same quality. ' | |
586 | 'Use with "-S ext" to strictly prefer free containers irrespective of quality')) | |
587 | video_format.add_option( | |
588 | '--no-prefer-free-formats', | |
1c36c1f3 | 589 | action='store_false', dest='prefer_free_formats', default=False, |
da9be05e | 590 | help="Don't give any special preference to free containers (default)") |
e8e73840 | 591 | video_format.add_option( |
592 | '--check-formats', | |
9f1a1c36 | 593 | action='store_const', const='selected', dest='check_formats', default=None, |
594 | help='Check that the selected formats are actually downloadable') | |
595 | video_format.add_option( | |
596 | '--check-all-formats', | |
597 | action='store_true', dest='check_formats', | |
598 | help='Check all formats for whether they are actually downloadable') | |
0ba692ac | 599 | video_format.add_option( |
600 | '--no-check-formats', | |
601 | action='store_false', dest='check_formats', | |
9f1a1c36 | 602 | help='Do not check that the formats are actually downloadable') |
8450c15c PH |
603 | video_format.add_option( |
604 | '-F', '--list-formats', | |
605 | action='store_true', dest='listformats', | |
b7b04c78 | 606 | help='List available formats of each video. Simulate unless --no-simulate is used') |
76d321f6 | 607 | video_format.add_option( |
608 | '--list-formats-as-table', | |
91ebc640 | 609 | action='store_true', dest='listformats_table', default=True, |
53ed7066 | 610 | help=optparse.SUPPRESS_HELP) |
76d321f6 | 611 | video_format.add_option( |
6623ac34 | 612 | '--list-formats-old', '--no-list-formats-as-table', |
76d321f6 | 613 | action='store_false', dest='listformats_table', |
53ed7066 | 614 | help=optparse.SUPPRESS_HELP) |
d120e901 | 615 | video_format.add_option( |
bd1a281e PH |
616 | '--merge-output-format', |
617 | action='store', dest='merge_output_format', metavar='FORMAT', default=None, | |
d120e901 | 618 | help=( |
00334d0d S |
619 | 'If a merge is required (e.g. bestvideo+bestaudio), ' |
620 | 'output to given container format. One of mkv, mp4, ogg, webm, flv. ' | |
d120e901 | 621 | 'Ignored if no merge is required')) |
63ad4d43 | 622 | video_format.add_option( |
623 | '--allow-unplayable-formats', | |
624 | action='store_true', dest='allow_unplayable_formats', default=False, | |
88acdbc2 | 625 | help=optparse.SUPPRESS_HELP) |
63ad4d43 | 626 | video_format.add_option( |
627 | '--no-allow-unplayable-formats', | |
628 | action='store_false', dest='allow_unplayable_formats', | |
88acdbc2 | 629 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
630 | |
631 | subtitles = optparse.OptionGroup(parser, 'Subtitle Options') | |
632 | subtitles.add_option( | |
6623ac34 | 633 | '--write-subs', '--write-srt', |
8450c15c | 634 | action='store_true', dest='writesubtitles', default=False, |
17941321 | 635 | help='Write subtitle file') |
8450c15c | 636 | subtitles.add_option( |
6623ac34 | 637 | '--no-write-subs', '--no-write-srt', |
638 | action='store_false', dest='writesubtitles', | |
639 | help='Do not write subtitle file (default)') | |
640 | subtitles.add_option( | |
641 | '--write-auto-subs', '--write-automatic-subs', | |
8450c15c | 642 | action='store_true', dest='writeautomaticsub', default=False, |
e167860c | 643 | help='Write automatically generated subtitle file (Alias: --write-automatic-subs)') |
6623ac34 | 644 | subtitles.add_option( |
645 | '--no-write-auto-subs', '--no-write-automatic-subs', | |
646 | action='store_false', dest='writeautomaticsub', default=False, | |
e167860c | 647 | help='Do not write auto-generated subtitles (default) (Alias: --no-write-automatic-subs)') |
8450c15c PH |
648 | subtitles.add_option( |
649 | '--all-subs', | |
650 | action='store_true', dest='allsubtitles', default=False, | |
c32b0aab | 651 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
652 | subtitles.add_option( |
653 | '--list-subs', | |
654 | action='store_true', dest='listsubtitles', default=False, | |
b7b04c78 | 655 | help='List available subtitles of each video. Simulate unless --no-simulate is used') |
8450c15c PH |
656 | subtitles.add_option( |
657 | '--sub-format', | |
a504ced0 | 658 | action='store', dest='subtitlesformat', metavar='FORMAT', default='best', |
4a3cdf81 | 659 | help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"') |
8450c15c | 660 | subtitles.add_option( |
e167860c | 661 | '--sub-langs', '--srt-langs', |
8450c15c | 662 | action='callback', dest='subtitleslangs', metavar='LANGS', type='str', |
e632bce2 | 663 | default=[], callback=_list_from_options_callback, |
c32b0aab | 664 | help=( |
a4211baf | 665 | 'Languages of the subtitles to download (can be regex) or "all" separated by commas. (Eg: --sub-langs "en.*,ja") ' |
c32b0aab | 666 | 'You can prefix the language code with a "-" to exempt it from the requested languages. (Eg: --sub-langs all,-live_chat) ' |
667 | 'Use --list-subs for a list of available language tags')) | |
8450c15c PH |
668 | |
669 | downloader = optparse.OptionGroup(parser, 'Download Options') | |
4cf1e5d2 | 670 | downloader.add_option( |
671 | '-N', '--concurrent-fragments', | |
672 | dest='concurrent_fragment_downloads', metavar='N', default=1, type=int, | |
b69fd25c | 673 | help='Number of fragments of a dash/hlsnative video that should be downloaded concurrently (default is %default)') |
8450c15c | 674 | downloader.add_option( |
8ec2b2c4 S |
675 | '-r', '--limit-rate', '--rate-limit', |
676 | dest='ratelimit', metavar='RATE', | |
17941321 | 677 | help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)') |
51d9739f | 678 | downloader.add_option( |
679 | '--throttled-rate', | |
680 | dest='throttledratelimit', metavar='RATE', | |
681 | help='Minimum download rate in bytes per second below which throttling is assumed and the video data is re-extracted (e.g. 100K)') | |
8450c15c PH |
682 | downloader.add_option( |
683 | '-R', '--retries', | |
684 | dest='retries', metavar='RETRIES', default=10, | |
8a51f564 | 685 | help='Number of retries (default is %default), or "infinite"') |
205a0654 EH |
686 | downloader.add_option( |
687 | '--file-access-retries', | |
688 | dest='file_access_retries', metavar='RETRIES', default=10, | |
689 | help='Number of times to retry on file access error (default is %default), or "infinite"') | |
52bb437e S |
690 | downloader.add_option( |
691 | '--fragment-retries', | |
692 | dest='fragment_retries', metavar='RETRIES', default=10, | |
12ee65ea | 693 | help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)') |
9603b660 | 694 | downloader.add_option( |
c76eb41b | 695 | '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment', |
9603b660 | 696 | action='store_true', dest='skip_unavailable_fragments', default=True, |
8a51f564 | 697 | help='Skip unavailable fragments for DASH, hlsnative and ISM (default) (Alias: --no-abort-on-unavailable-fragment)') |
732fb3f8 | 698 | downloader.add_option( |
6623ac34 | 699 | '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments', |
9603b660 | 700 | action='store_false', dest='skip_unavailable_fragments', |
8a51f564 | 701 | help='Abort downloading if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)') |
0eee52f3 S |
702 | downloader.add_option( |
703 | '--keep-fragments', | |
704 | action='store_true', dest='keep_fragments', default=False, | |
6623ac34 | 705 | help='Keep downloaded fragments on disk after downloading is finished') |
706 | downloader.add_option( | |
707 | '--no-keep-fragments', | |
708 | action='store_false', dest='keep_fragments', | |
709 | help='Delete downloaded fragments after downloading is finished (default)') | |
8450c15c PH |
710 | downloader.add_option( |
711 | '--buffer-size', | |
712 | dest='buffersize', metavar='SIZE', default='1024', | |
17941321 | 713 | help='Size of download buffer (e.g. 1024 or 16K) (default is %default)') |
6623ac34 | 714 | downloader.add_option( |
715 | '--resize-buffer', | |
716 | action='store_false', dest='noresizebuffer', | |
717 | help='The buffer size is automatically resized from an initial value of --buffer-size (default)') | |
8450c15c PH |
718 | downloader.add_option( |
719 | '--no-resize-buffer', | |
720 | action='store_true', dest='noresizebuffer', default=False, | |
6623ac34 | 721 | help='Do not automatically adjust the buffer size') |
ba515388 S |
722 | downloader.add_option( |
723 | '--http-chunk-size', | |
724 | dest='http_chunk_size', metavar='SIZE', default=None, | |
6623ac34 | 725 | help=( |
726 | 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). ' | |
727 | 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)')) | |
8450c15c PH |
728 | downloader.add_option( |
729 | '--test', | |
730 | action='store_true', dest='test', default=False, | |
731 | help=optparse.SUPPRESS_HELP) | |
ff815fe6 MS |
732 | downloader.add_option( |
733 | '--playlist-reverse', | |
734 | action='store_true', | |
735 | help='Download playlist videos in reverse order') | |
6623ac34 | 736 | downloader.add_option( |
737 | '--no-playlist-reverse', | |
c76eb41b | 738 | action='store_false', dest='playlist_reverse', |
6623ac34 | 739 | help='Download playlist videos in default order (default)') |
75822ca7 TC |
740 | downloader.add_option( |
741 | '--playlist-random', | |
742 | action='store_true', | |
743 | help='Download playlist videos in random order') | |
881e6a1f PH |
744 | downloader.add_option( |
745 | '--xattr-set-filesize', | |
746 | dest='xattr_set_filesize', action='store_true', | |
504f20dd | 747 | help='Set file xattribute ytdl.filesize with expected file size') |
85729c51 PH |
748 | downloader.add_option( |
749 | '--hls-prefer-native', | |
bf09af3a | 750 | dest='hls_prefer_native', action='store_true', default=None, |
52a8a1e1 | 751 | help=optparse.SUPPRESS_HELP) |
bf09af3a S |
752 | downloader.add_option( |
753 | '--hls-prefer-ffmpeg', | |
754 | dest='hls_prefer_native', action='store_false', default=None, | |
52a8a1e1 | 755 | help=optparse.SUPPRESS_HELP) |
7d106a65 JMF |
756 | downloader.add_option( |
757 | '--hls-use-mpegts', | |
9bd20204 | 758 | dest='hls_use_mpegts', action='store_true', default=None, |
6623ac34 | 759 | help=( |
9bd20204 | 760 | 'Use the mpegts container for HLS videos; ' |
761 | 'allowing some players to play the video while downloading, ' | |
762 | 'and reducing the chance of file corruption if download is interrupted. ' | |
763 | 'This is enabled by default for live streams')) | |
764 | downloader.add_option( | |
765 | '--no-hls-use-mpegts', | |
766 | dest='hls_use_mpegts', action='store_false', | |
767 | help=( | |
768 | 'Do not use the mpegts container for HLS videos. ' | |
769 | 'This is default when not downloading live streams')) | |
222516d9 | 770 | downloader.add_option( |
52a8a1e1 | 771 | '--downloader', '--external-downloader', |
772 | dest='external_downloader', metavar='[PROTO:]NAME', default={}, type='str', | |
e632bce2 | 773 | action='callback', callback=_dict_from_options_callback, |
52a8a1e1 | 774 | callback_kwargs={ |
775 | 'allowed_keys': 'http|ftp|m3u8|dash|rtsp|rtmp|mms', | |
cc0ec3e1 | 776 | 'default_key': 'default', |
dbf5416a | 777 | 'process': str.strip |
778 | }, help=( | |
52a8a1e1 | 779 | 'Name or path of the external downloader to use (optionally) prefixed by ' |
780 | 'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. ' | |
781 | 'Currently supports native, %s (Recommended: aria2c). ' | |
782 | 'You can use this option multiple times to set different downloaders for different protocols. ' | |
783 | 'For example, --downloader aria2c --downloader "dash,m3u8:native" will use ' | |
784 | 'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads ' | |
785 | '(Alias: --external-downloader)' % ', '.join(list_external_downloaders()))) | |
c75f0b36 | 786 | downloader.add_option( |
46ee996e | 787 | '--downloader-args', '--external-downloader-args', |
788 | metavar='NAME:ARGS', dest='external_downloader_args', default={}, type='str', | |
e632bce2 | 789 | action='callback', callback=_dict_from_options_callback, |
b8f6bbe6 | 790 | callback_kwargs={ |
330690a2 | 791 | 'allowed_keys': r'ffmpeg_[io]\d*|%s' % '|'.join(list_external_downloaders()), |
cc0ec3e1 | 792 | 'default_key': 'default', |
793 | 'process': compat_shlex_split | |
dbf5416a | 794 | }, help=( |
46ee996e | 795 | 'Give these arguments to the external downloader. ' |
796 | 'Specify the downloader name and the arguments separated by a colon ":". ' | |
330690a2 | 797 | 'For ffmpeg, arguments can be passed to different positions using the same syntax as --postprocessor-args. ' |
5d3a0e79 | 798 | 'You can use this option multiple times to give different arguments to different downloaders ' |
799 | '(Alias: --external-downloader-args)')) | |
8450c15c PH |
800 | |
801 | workarounds = optparse.OptionGroup(parser, 'Workarounds') | |
34a741a8 | 802 | workarounds.add_option( |
8450c15c PH |
803 | '--encoding', |
804 | dest='encoding', metavar='ENCODING', | |
34a741a8 PH |
805 | help='Force the specified encoding (experimental)') |
806 | workarounds.add_option( | |
e6f21b3d | 807 | '--no-check-certificates', |
8450c15c | 808 | action='store_true', dest='no_check_certificate', default=False, |
17941321 | 809 | help='Suppress HTTPS certificate validation') |
34a741a8 | 810 | workarounds.add_option( |
6623ac34 | 811 | '--prefer-insecure', '--prefer-unsecure', |
812 | action='store_true', dest='prefer_insecure', | |
e167860c | 813 | help='Use an unencrypted connection to retrieve information about the video (Currently supported only for YouTube)') |
34a741a8 | 814 | workarounds.add_option( |
8450c15c PH |
815 | '--user-agent', |
816 | metavar='UA', dest='user_agent', | |
17941321 | 817 | help='Specify a custom user agent') |
34a741a8 | 818 | workarounds.add_option( |
8450c15c PH |
819 | '--referer', |
820 | metavar='URL', dest='referer', default=None, | |
17941321 | 821 | help='Specify a custom referer, use if the video access is restricted to one domain', |
34a741a8 PH |
822 | ) |
823 | workarounds.add_option( | |
8450c15c | 824 | '--add-header', |
45016689 | 825 | metavar='FIELD:VALUE', dest='headers', default={}, type='str', |
e632bce2 | 826 | action='callback', callback=_dict_from_options_callback, |
44bcb8d1 | 827 | callback_kwargs={'multiple_keys': False, 'process_key': None}, |
45016689 | 828 | help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times', |
34a741a8 PH |
829 | ) |
830 | workarounds.add_option( | |
8450c15c PH |
831 | '--bidi-workaround', |
832 | dest='bidi_workaround', action='store_true', | |
833 | help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH') | |
1cf376f5 | 834 | workarounds.add_option( |
835 | '--sleep-requests', metavar='SECONDS', | |
836 | dest='sleep_interval_requests', type=float, | |
837 | help='Number of seconds to sleep between requests during data extraction') | |
5f0d813d | 838 | workarounds.add_option( |
065bc354 | 839 | '--sleep-interval', '--min-sleep-interval', metavar='SECONDS', |
649f7966 | 840 | dest='sleep_interval', type=float, |
7aa589a5 | 841 | help=( |
e167860c | 842 | 'Number of seconds to sleep before each download. ' |
843 | 'This is the minimum time to sleep when used along with --max-sleep-interval ' | |
844 | '(Alias: --min-sleep-interval)')) | |
065bc354 | 845 | workarounds.add_option( |
846 | '--max-sleep-interval', metavar='SECONDS', | |
847 | dest='max_sleep_interval', type=float, | |
e167860c | 848 | help='Maximum number of seconds to sleep. Can only be used along with --min-sleep-interval') |
0c9df79e | 849 | workarounds.add_option( |
c76eb41b | 850 | '--sleep-subtitles', metavar='SECONDS', |
31108ce9 | 851 | dest='sleep_interval_subtitles', default=0, type=int, |
1cf376f5 | 852 | help='Number of seconds to sleep before each subtitle download') |
34a741a8 | 853 | |
0744a815 | 854 | verbosity = optparse.OptionGroup(parser, 'Verbosity and Simulation Options') |
8450c15c PH |
855 | verbosity.add_option( |
856 | '-q', '--quiet', | |
857 | action='store_true', dest='quiet', default=False, | |
34488702 | 858 | help='Activate quiet mode. If used with --verbose, print the log to stderr') |
34a741a8 PH |
859 | verbosity.add_option( |
860 | '--no-warnings', | |
861 | dest='no_warnings', action='store_true', default=False, | |
862 | help='Ignore warnings') | |
8450c15c PH |
863 | verbosity.add_option( |
864 | '-s', '--simulate', | |
b7b04c78 | 865 | action='store_true', dest='simulate', default=None, |
17941321 | 866 | help='Do not download the video and do not write anything to disk') |
b7b04c78 | 867 | verbosity.add_option( |
868 | '--no-simulate', | |
869 | action='store_false', dest='simulate', | |
870 | help='Download the video even if printing/listing options are used') | |
b7da73eb | 871 | verbosity.add_option( |
872 | '--ignore-no-formats-error', | |
873 | action='store_true', dest='ignore_no_formats_error', default=False, | |
874 | help=( | |
0930b11f | 875 | 'Ignore "No video formats" error. Useful for extracting metadata ' |
34488702 | 876 | 'even if the videos are not actually available for download (experimental)')) |
b7da73eb | 877 | verbosity.add_option( |
878 | '--no-ignore-no-formats-error', | |
879 | action='store_false', dest='ignore_no_formats_error', | |
880 | help='Throw error when no downloadable video formats are found (default)') | |
8450c15c | 881 | verbosity.add_option( |
6623ac34 | 882 | '--skip-download', '--no-download', |
8450c15c | 883 | action='store_true', dest='skip_download', default=False, |
e167860c | 884 | help='Do not download the video but write all related files (Alias: --no-download)') |
53c18592 | 885 | verbosity.add_option( |
ad3dc496 | 886 | '-O', '--print', |
ca30f449 | 887 | metavar='[WHEN:]TEMPLATE', dest='forceprint', default={}, type='str', |
888 | action='callback', callback=_dict_from_options_callback, | |
889 | callback_kwargs={ | |
890 | 'allowed_keys': 'video|playlist', | |
891 | 'default_key': 'video', | |
892 | 'multiple_keys': False, | |
893 | 'append': True, | |
894 | }, help=( | |
895 | 'Field name or output template to print to screen per video. ' | |
896 | 'Prefix the template with "playlist:" to print it once per playlist instead. ' | |
897 | 'Implies --quiet and --simulate (unless --no-simulate is used). This option can be used multiple times')) | |
8450c15c PH |
898 | verbosity.add_option( |
899 | '-g', '--get-url', | |
900 | action='store_true', dest='geturl', default=False, | |
53c18592 | 901 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
902 | verbosity.add_option( |
903 | '-e', '--get-title', | |
904 | action='store_true', dest='gettitle', default=False, | |
53c18592 | 905 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
906 | verbosity.add_option( |
907 | '--get-id', | |
908 | action='store_true', dest='getid', default=False, | |
53c18592 | 909 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
910 | verbosity.add_option( |
911 | '--get-thumbnail', | |
912 | action='store_true', dest='getthumbnail', default=False, | |
53c18592 | 913 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
914 | verbosity.add_option( |
915 | '--get-description', | |
916 | action='store_true', dest='getdescription', default=False, | |
53c18592 | 917 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
918 | verbosity.add_option( |
919 | '--get-duration', | |
920 | action='store_true', dest='getduration', default=False, | |
53c18592 | 921 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
922 | verbosity.add_option( |
923 | '--get-filename', | |
924 | action='store_true', dest='getfilename', default=False, | |
53c18592 | 925 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
926 | verbosity.add_option( |
927 | '--get-format', | |
928 | action='store_true', dest='getformat', default=False, | |
53c18592 | 929 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
930 | verbosity.add_option( |
931 | '-j', '--dump-json', | |
932 | action='store_true', dest='dumpjson', default=False, | |
b7b04c78 | 933 | help='Quiet, but print JSON information for each video. Simulate unless --no-simulate is used. See "OUTPUT TEMPLATE" for a description of available keys') |
63e0be34 PH |
934 | verbosity.add_option( |
935 | '-J', '--dump-single-json', | |
936 | action='store_true', dest='dump_single_json', default=False, | |
6623ac34 | 937 | help=( |
b7b04c78 | 938 | 'Quiet, but print JSON information for each url or infojson passed. Simulate unless --no-simulate is used. ' |
939 | 'If the URL refers to a playlist, the whole playlist information is dumped in a single line')) | |
c0bdf32a PH |
940 | verbosity.add_option( |
941 | '--print-json', | |
942 | action='store_true', dest='print_json', default=False, | |
b7b04c78 | 943 | help=optparse.SUPPRESS_HELP) |
2d30509f | 944 | verbosity.add_option( |
c76eb41b | 945 | '--force-write-archive', '--force-write-download-archive', '--force-download-archive', |
2d30509f | 946 | action='store_true', dest='force_write_download_archive', default=False, |
947 | help=( | |
e58c22a0 | 948 | 'Force download archive entries to be written as far as no errors occur, ' |
949 | 'even if -s or another simulation option is used (Alias: --force-download-archive)')) | |
8450c15c PH |
950 | verbosity.add_option( |
951 | '--newline', | |
952 | action='store_true', dest='progress_with_newline', default=False, | |
17941321 | 953 | help='Output progress bar as new lines') |
8450c15c PH |
954 | verbosity.add_option( |
955 | '--no-progress', | |
819e0531 | 956 | action='store_true', dest='noprogress', default=None, |
17941321 | 957 | help='Do not print progress bar') |
819e0531 | 958 | verbosity.add_option( |
959 | '--progress', | |
960 | action='store_false', dest='noprogress', | |
961 | help='Show progress bar, even if in quiet mode') | |
8450c15c PH |
962 | verbosity.add_option( |
963 | '--console-title', | |
964 | action='store_true', dest='consoletitle', default=False, | |
17941321 | 965 | help='Display progress in console titlebar') |
819e0531 | 966 | verbosity.add_option( |
967 | '--progress-template', | |
968 | metavar='[TYPES:]TEMPLATE', dest='progress_template', default={}, type='str', | |
969 | action='callback', callback=_dict_from_options_callback, | |
970 | callback_kwargs={ | |
971 | 'allowed_keys': '(download|postprocess)(-title)?', | |
972 | 'default_key': 'download' | |
973 | }, help=( | |
974 | 'Template for progress outputs, optionally prefixed with one of "download:" (default), ' | |
975 | '"download-title:" (the console title), "postprocess:", or "postprocess-title:". ' | |
976 | 'The video\'s fields are accessible under the "info" key and ' | |
0930b11f | 977 | 'the progress attributes are accessible under "progress" key. E.g.: ' |
819e0531 | 978 | # TODO: Document the fields inside "progress" |
979 | '--console-title --progress-template "download-title:%(info.id)s-%(progress.eta)s"')) | |
8450c15c PH |
980 | verbosity.add_option( |
981 | '-v', '--verbose', | |
982 | action='store_true', dest='verbose', default=False, | |
17941321 | 983 | help='Print various debugging information') |
8450c15c | 984 | verbosity.add_option( |
8bba753c | 985 | '--dump-pages', '--dump-intermediate-pages', |
8450c15c | 986 | action='store_true', dest='dump_intermediate_pages', default=False, |
79979c68 | 987 | help='Print downloaded pages encoded using base64 to debug problems (very verbose)') |
8450c15c PH |
988 | verbosity.add_option( |
989 | '--write-pages', | |
990 | action='store_true', dest='write_pages', default=False, | |
991 | help='Write downloaded intermediary pages to files in the current directory to debug problems') | |
992 | verbosity.add_option( | |
993 | '--youtube-print-sig-code', | |
994 | action='store_true', dest='youtube_print_sig_code', default=False, | |
995 | help=optparse.SUPPRESS_HELP) | |
996 | verbosity.add_option( | |
2f543a21 | 997 | '--print-traffic', '--dump-headers', |
8450c15c PH |
998 | dest='debug_printtraffic', action='store_true', default=False, |
999 | help='Display sent and read HTTP traffic') | |
58b1f00d PH |
1000 | verbosity.add_option( |
1001 | '-C', '--call-home', | |
1002 | dest='call_home', action='store_true', default=False, | |
7a5c1cfe | 1003 | # help='[Broken] Contact the yt-dlp server for debugging') |
8d801631 | 1004 | help=optparse.SUPPRESS_HELP) |
8bfa7545 PH |
1005 | verbosity.add_option( |
1006 | '--no-call-home', | |
6623ac34 | 1007 | dest='call_home', action='store_false', |
7a5c1cfe | 1008 | # help='Do not contact the yt-dlp server for debugging (default)') |
8d801631 | 1009 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
1010 | |
1011 | filesystem = optparse.OptionGroup(parser, 'Filesystem Options') | |
1012 | filesystem.add_option( | |
1013 | '-a', '--batch-file', | |
1014 | dest='batchfile', metavar='FILE', | |
940a67a3 | 1015 | help=( |
1016 | 'File containing URLs to download ("-" for stdin), one URL per line. ' | |
1017 | 'Lines starting with "#", ";" or "]" are considered as comments and ignored')) | |
1e520b55 Z |
1018 | filesystem.add_option( |
1019 | '--no-batch-file', | |
1020 | dest='batchfile', action='store_const', const=None, | |
1021 | help='Do not read URLs from batch file (default)') | |
19b824f6 | 1022 | filesystem.add_option( |
1023 | '--id', default=False, | |
1024 | action='store_true', dest='useid', help=optparse.SUPPRESS_HELP) | |
0202b52a | 1025 | filesystem.add_option( |
1026 | '-P', '--paths', | |
d74a58a1 | 1027 | metavar='[TYPES:]PATH', dest='paths', default={}, type='str', |
e632bce2 | 1028 | action='callback', callback=_dict_from_options_callback, |
d74a58a1 | 1029 | callback_kwargs={ |
1030 | 'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES.keys()), | |
1031 | 'default_key': 'home' | |
1032 | }, help=( | |
0202b52a | 1033 | 'The paths where the files should be downloaded. ' |
de6000d9 | 1034 | 'Specify the type of file and the path separated by a colon ":". ' |
6a34813a | 1035 | 'All the same TYPES as --output are supported. ' |
d74a58a1 | 1036 | 'Additionally, you can also provide "home" (default) and "temp" paths. ' |
0202b52a | 1037 | 'All intermediary files are first downloaded to the temp path and ' |
1038 | 'then the final files are moved over to the home path after download is finished. ' | |
de6000d9 | 1039 | 'This option is ignored if --output is an absolute path')) |
8450c15c PH |
1040 | filesystem.add_option( |
1041 | '-o', '--output', | |
d818eb74 | 1042 | metavar='[TYPES:]TEMPLATE', dest='outtmpl', default={}, type='str', |
e632bce2 | 1043 | action='callback', callback=_dict_from_options_callback, |
de6000d9 | 1044 | callback_kwargs={ |
1045 | 'allowed_keys': '|'.join(OUTTMPL_TYPES.keys()), | |
cc0ec3e1 | 1046 | 'default_key': 'default' |
dbf5416a | 1047 | }, help='Output filename template; see "OUTPUT TEMPLATE" for details') |
a820dc72 RA |
1048 | filesystem.add_option( |
1049 | '--output-na-placeholder', | |
0bc0a322 | 1050 | dest='outtmpl_na_placeholder', metavar='TEXT', default='NA', |
1051 | help=('Placeholder value for unavailable meta fields in output filename template (default: "%default")')) | |
8450c15c PH |
1052 | filesystem.add_option( |
1053 | '--autonumber-size', | |
be5df5ee S |
1054 | dest='autonumber_size', metavar='NUMBER', type=int, |
1055 | help=optparse.SUPPRESS_HELP) | |
acbb2374 CP |
1056 | filesystem.add_option( |
1057 | '--autonumber-start', | |
1a241a2d | 1058 | dest='autonumber_start', metavar='NUMBER', default=1, type=int, |
a439a3a4 | 1059 | help=optparse.SUPPRESS_HELP) |
8450c15c PH |
1060 | filesystem.add_option( |
1061 | '--restrict-filenames', | |
1062 | action='store_true', dest='restrictfilenames', default=False, | |
1063 | help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames') | |
6623ac34 | 1064 | filesystem.add_option( |
1065 | '--no-restrict-filenames', | |
c2934512 | 1066 | action='store_false', dest='restrictfilenames', |
6623ac34 | 1067 | help='Allow Unicode characters, "&" and spaces in filenames (default)') |
c2934512 | 1068 | filesystem.add_option( |
1069 | '--windows-filenames', | |
1070 | action='store_true', dest='windowsfilenames', default=False, | |
0930b11f | 1071 | help='Force filenames to be Windows-compatible') |
c2934512 | 1072 | filesystem.add_option( |
1073 | '--no-windows-filenames', | |
1074 | action='store_false', dest='windowsfilenames', | |
0930b11f | 1075 | help='Make filenames Windows-compatible only if using Windows (default)') |
c2934512 | 1076 | filesystem.add_option( |
1077 | '--trim-filenames', '--trim-file-names', metavar='LENGTH', | |
1078 | dest='trim_file_name', default=0, type=int, | |
1079 | help='Limit the filename length (excluding extension) to the specified number of characters') | |
8450c15c PH |
1080 | filesystem.add_option( |
1081 | '-w', '--no-overwrites', | |
0c3d0f51 | 1082 | action='store_false', dest='overwrites', default=None, |
1083 | help='Do not overwrite any files') | |
1084 | filesystem.add_option( | |
1085 | '--force-overwrites', '--yes-overwrites', | |
1086 | action='store_true', dest='overwrites', | |
1087 | help='Overwrite all video and metadata files. This option includes --no-continue') | |
1088 | filesystem.add_option( | |
1089 | '--no-force-overwrites', | |
1090 | action='store_const', dest='overwrites', const=None, | |
1091 | help='Do not overwrite the video, but overwrite related files (default)') | |
8450c15c PH |
1092 | filesystem.add_option( |
1093 | '-c', '--continue', | |
1094 | action='store_true', dest='continue_dl', default=True, | |
c25228e5 | 1095 | help='Resume partially downloaded files/fragments (default)') |
8450c15c PH |
1096 | filesystem.add_option( |
1097 | '--no-continue', | |
1098 | action='store_false', dest='continue_dl', | |
c25228e5 | 1099 | help=( |
1100 | 'Do not resume partially downloaded fragments. ' | |
e58c22a0 | 1101 | 'If the file is not fragmented, restart download of the entire file')) |
6623ac34 | 1102 | filesystem.add_option( |
1103 | '--part', | |
1104 | action='store_false', dest='nopart', default=False, | |
1105 | help='Use .part files instead of writing directly into output file (default)') | |
8450c15c PH |
1106 | filesystem.add_option( |
1107 | '--no-part', | |
6623ac34 | 1108 | action='store_true', dest='nopart', |
17941321 | 1109 | help='Do not use .part files - write directly into output file') |
6623ac34 | 1110 | filesystem.add_option( |
1111 | '--mtime', | |
1112 | action='store_true', dest='updatetime', default=True, | |
1113 | help='Use the Last-modified header to set the file modification time (default)') | |
8450c15c PH |
1114 | filesystem.add_option( |
1115 | '--no-mtime', | |
6623ac34 | 1116 | action='store_false', dest='updatetime', |
17941321 | 1117 | help='Do not use the Last-modified header to set the file modification time') |
8450c15c PH |
1118 | filesystem.add_option( |
1119 | '--write-description', | |
1120 | action='store_true', dest='writedescription', default=False, | |
17941321 | 1121 | help='Write video description to a .description file') |
6623ac34 | 1122 | filesystem.add_option( |
1123 | '--no-write-description', | |
1124 | action='store_false', dest='writedescription', | |
1125 | help='Do not write video description (default)') | |
8450c15c PH |
1126 | filesystem.add_option( |
1127 | '--write-info-json', | |
1128 | action='store_true', dest='writeinfojson', default=False, | |
c25228e5 | 1129 | help='Write video metadata to a .info.json file (this may contain personal information)') |
6623ac34 | 1130 | filesystem.add_option( |
1131 | '--no-write-info-json', | |
1132 | action='store_false', dest='writeinfojson', | |
1133 | help='Do not write video metadata (default)') | |
8450c15c PH |
1134 | filesystem.add_option( |
1135 | '--write-annotations', | |
1136 | action='store_true', dest='writeannotations', default=False, | |
0bb1bc1b | 1137 | help=optparse.SUPPRESS_HELP) |
6623ac34 | 1138 | filesystem.add_option( |
1139 | '--no-write-annotations', | |
1140 | action='store_false', dest='writeannotations', | |
0bb1bc1b | 1141 | help=optparse.SUPPRESS_HELP) |
cac96421 | 1142 | filesystem.add_option( |
1143 | '--write-playlist-metafiles', | |
53ed7066 | 1144 | action='store_true', dest='allow_playlist_files', default=None, |
cac96421 | 1145 | help=( |
1146 | 'Write playlist metadata in addition to the video metadata ' | |
1147 | 'when using --write-info-json, --write-description etc. (default)')) | |
1148 | filesystem.add_option( | |
1149 | '--no-write-playlist-metafiles', | |
1150 | action='store_false', dest='allow_playlist_files', | |
e167860c | 1151 | help='Do not write playlist metadata when using --write-info-json, --write-description etc.') |
75d43ca0 | 1152 | filesystem.add_option( |
1153 | '--clean-infojson', | |
e4f02757 | 1154 | action='store_true', dest='clean_infojson', default=None, |
75d43ca0 | 1155 | help=( |
1156 | 'Remove some private fields such as filenames from the infojson. ' | |
1157 | 'Note that it could still contain some personal information (default)')) | |
1158 | filesystem.add_option( | |
1159 | '--no-clean-infojson', | |
1160 | action='store_false', dest='clean_infojson', | |
1161 | help='Write all fields to the infojson') | |
06167fbb | 1162 | filesystem.add_option( |
2305e2e5 | 1163 | '--write-comments', '--get-comments', |
06167fbb | 1164 | action='store_true', dest='getcomments', default=False, |
277d6ff5 | 1165 | help=( |
2305e2e5 | 1166 | 'Retrieve video comments to be placed in the infojson. ' |
1167 | 'The comments are fetched even without this option if the extraction is known to be quick (Alias: --get-comments)')) | |
1168 | filesystem.add_option( | |
1169 | '--no-write-comments', '--no-get-comments', | |
dd594deb | 1170 | action='store_false', dest='getcomments', |
2305e2e5 | 1171 | help='Do not retrieve video comments unless the extraction is known to be quick (Alias: --no-get-comments)') |
8450c15c | 1172 | filesystem.add_option( |
244fe977 | 1173 | '--load-info-json', '--load-info', |
8450c15c | 1174 | dest='load_info_filename', metavar='FILE', |
1a48181a | 1175 | help='JSON file containing the video information (created with the "--write-info-json" option)') |
8450c15c PH |
1176 | filesystem.add_option( |
1177 | '--cookies', | |
1178 | dest='cookiefile', metavar='FILE', | |
f304da8a | 1179 | help='Netscape formatted file to read cookies from and dump cookie jar in') |
6623ac34 | 1180 | filesystem.add_option( |
1181 | '--no-cookies', | |
1182 | action='store_const', const=None, dest='cookiefile', metavar='FILE', | |
982ee69a MB |
1183 | help='Do not read/dump cookies from/to file (default)') |
1184 | filesystem.add_option( | |
1185 | '--cookies-from-browser', | |
f59f5ef8 | 1186 | dest='cookiesfrombrowser', metavar='BROWSER[+KEYRING][:PROFILE]', |
982ee69a | 1187 | help=( |
f59f5ef8 MB |
1188 | 'The name of the browser and (optionally) the name/path of ' |
1189 | 'the profile to load cookies from, separated by a ":". ' | |
1190 | f'Currently supported browsers are: {", ".join(sorted(SUPPORTED_BROWSERS))}. ' | |
1191 | 'By default, the most recently accessed profile is used. ' | |
1192 | 'The keyring used for decrypting Chromium cookies on Linux can be ' | |
1193 | '(optionally) specified after the browser name separated by a "+". ' | |
1194 | f'Currently supported keyrings are: {", ".join(map(str.lower, sorted(SUPPORTED_KEYRINGS)))}')) | |
982ee69a MB |
1195 | filesystem.add_option( |
1196 | '--no-cookies-from-browser', | |
1197 | action='store_const', const=None, dest='cookiesfrombrowser', | |
1198 | help='Do not load cookies from browser (default)') | |
34a741a8 PH |
1199 | filesystem.add_option( |
1200 | '--cache-dir', dest='cachedir', default=None, metavar='DIR', | |
9ee4f0bb | 1201 | help='Location in the filesystem where youtube-dl can store some downloaded information (such as client ids and signatures) permanently. By default $XDG_CACHE_HOME/yt-dlp or ~/.cache/yt-dlp') |
34a741a8 | 1202 | filesystem.add_option( |
6623ac34 | 1203 | '--no-cache-dir', action='store_false', dest='cachedir', |
34a741a8 PH |
1204 | help='Disable filesystem caching') |
1205 | filesystem.add_option( | |
8450c15c PH |
1206 | '--rm-cache-dir', |
1207 | action='store_true', dest='rm_cachedir', | |
34a741a8 PH |
1208 | help='Delete all filesystem cache files') |
1209 | ||
b31fdeed | 1210 | thumbnail = optparse.OptionGroup(parser, 'Thumbnail Options') |
cfb56d1a PH |
1211 | thumbnail.add_option( |
1212 | '--write-thumbnail', | |
acc0d6a4 | 1213 | action='callback', dest='writethumbnail', default=False, |
1214 | # Should override --no-write-thumbnail, but not --write-all-thumbnail | |
1215 | callback=lambda option, _, __, parser: setattr( | |
1216 | parser.values, option.dest, getattr(parser.values, option.dest) or True), | |
17941321 | 1217 | help='Write thumbnail image to disk') |
6623ac34 | 1218 | thumbnail.add_option( |
1219 | '--no-write-thumbnail', | |
1220 | action='store_false', dest='writethumbnail', | |
1221 | help='Do not write thumbnail image to disk (default)') | |
ec82d85a PH |
1222 | thumbnail.add_option( |
1223 | '--write-all-thumbnails', | |
acc0d6a4 | 1224 | action='store_const', dest='writethumbnail', const='all', |
17941321 | 1225 | help='Write all thumbnail image formats to disk') |
cfb56d1a PH |
1226 | thumbnail.add_option( |
1227 | '--list-thumbnails', | |
1228 | action='store_true', dest='list_thumbnails', default=False, | |
b7b04c78 | 1229 | help='List available thumbnails of each video. Simulate unless --no-simulate is used') |
cfb56d1a | 1230 | |
732044af | 1231 | link = optparse.OptionGroup(parser, 'Internet Shortcut Options') |
1232 | link.add_option( | |
1233 | '--write-link', | |
1234 | action='store_true', dest='writelink', default=False, | |
8a51f564 | 1235 | help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS') |
732044af | 1236 | link.add_option( |
1237 | '--write-url-link', | |
1238 | action='store_true', dest='writeurllink', default=False, | |
8a51f564 | 1239 | help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path') |
732044af | 1240 | link.add_option( |
1241 | '--write-webloc-link', | |
1242 | action='store_true', dest='writewebloclink', default=False, | |
8a51f564 | 1243 | help='Write a .webloc macOS internet shortcut') |
732044af | 1244 | link.add_option( |
1245 | '--write-desktop-link', | |
1246 | action='store_true', dest='writedesktoplink', default=False, | |
8a51f564 | 1247 | help='Write a .desktop Linux internet shortcut') |
732044af | 1248 | |
1249 | postproc = optparse.OptionGroup(parser, 'Post-Processing Options') | |
8450c15c PH |
1250 | postproc.add_option( |
1251 | '-x', '--extract-audio', | |
1252 | action='store_true', dest='extractaudio', default=False, | |
e4172ac9 | 1253 | help='Convert video files to audio-only files (requires ffmpeg and ffprobe)') |
8450c15c PH |
1254 | postproc.add_option( |
1255 | '--audio-format', metavar='FORMAT', dest='audioformat', default='best', | |
81a23040 | 1256 | help=( |
1257 | 'Specify audio format to convert the audio to when -x is used. Currently supported formats are: ' | |
1258 | 'best (default) or one of %s' % '|'.join(FFmpegExtractAudioPP.SUPPORTED_EXTS))) | |
8450c15c PH |
1259 | postproc.add_option( |
1260 | '--audio-quality', metavar='QUALITY', | |
1261 | dest='audioquality', default='5', | |
31c49255 | 1262 | help='Specify ffmpeg audio quality, insert a value between 0 (best) and 10 (worst) for VBR or a specific bitrate like 128K (default %default)') |
efe87a10 FS |
1263 | postproc.add_option( |
1264 | '--remux-video', | |
1265 | metavar='FORMAT', dest='remuxvideo', default=None, | |
6623ac34 | 1266 | help=( |
17912249 | 1267 | 'Remux the video into another container if necessary (currently supported: %s). ' |
06167fbb | 1268 | 'If target container does not support the video/audio codec, remuxing will fail. ' |
81a23040 | 1269 | 'You can specify multiple rules; Eg. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 ' |
1270 | 'and anything else to mkv.' % '|'.join(FFmpegVideoRemuxerPP.SUPPORTED_EXTS))) | |
8450c15c PH |
1271 | postproc.add_option( |
1272 | '--recode-video', | |
1273 | metavar='FORMAT', dest='recodevideo', default=None, | |
17912249 | 1274 | help=( |
1275 | 'Re-encode the video into another format if re-encoding is necessary. ' | |
81a23040 | 1276 | 'The syntax and supported formats are the same as --remux-video')) |
d84f1d14 | 1277 | postproc.add_option( |
45016689 | 1278 | '--postprocessor-args', '--ppa', |
1279 | metavar='NAME:ARGS', dest='postprocessor_args', default={}, type='str', | |
e632bce2 | 1280 | action='callback', callback=_dict_from_options_callback, |
d818eb74 | 1281 | callback_kwargs={ |
1282 | 'allowed_keys': r'\w+(?:\+\w+)?', 'default_key': 'default-compat', | |
cc0ec3e1 | 1283 | 'process': compat_shlex_split, |
1284 | 'multiple_keys': False | |
dbf5416a | 1285 | }, help=( |
1b77b347 | 1286 | 'Give these arguments to the postprocessors. ' |
43820c03 | 1287 | 'Specify the postprocessor/executable name and the arguments separated by a colon ":" ' |
8fa43c73 | 1288 | 'to give the argument to the specified postprocessor/executable. Supported PP are: ' |
7a340e0d NA |
1289 | 'Merger, ModifyChapters, SplitChapters, ExtractAudio, VideoRemuxer, VideoConvertor, ' |
1290 | 'Metadata, EmbedSubtitle, EmbedThumbnail, SubtitlesConvertor, ThumbnailsConvertor, ' | |
1291 | 'FixupStretched, FixupM4a, FixupM3u8, FixupTimestamp and FixupDuration. ' | |
1292 | 'The supported executables are: AtomicParsley, FFmpeg and FFprobe. ' | |
43820c03 | 1293 | 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable ' |
5b1ecbb3 | 1294 | 'only when being used by the specified postprocessor. Additionally, for ffmpeg/ffprobe, ' |
597c1866 | 1295 | '"_i"/"_o" can be appended to the prefix optionally followed by a number to pass the argument ' |
1296 | 'before the specified input/output file. Eg: --ppa "Merger+ffmpeg_i1:-v quiet". ' | |
5b1ecbb3 | 1297 | 'You can use this option multiple times to give different arguments to different ' |
1298 | 'postprocessors. (Alias: --ppa)')) | |
8450c15c PH |
1299 | postproc.add_option( |
1300 | '-k', '--keep-video', | |
1301 | action='store_true', dest='keepvideo', default=False, | |
6623ac34 | 1302 | help='Keep the intermediate video file on disk after post-processing') |
1303 | postproc.add_option( | |
1304 | '--no-keep-video', | |
1305 | action='store_false', dest='keepvideo', | |
1306 | help='Delete the intermediate video file after post-processing (default)') | |
1307 | postproc.add_option( | |
1308 | '--post-overwrites', | |
1309 | action='store_false', dest='nopostoverwrites', | |
1310 | help='Overwrite post-processed files (default)') | |
8450c15c PH |
1311 | postproc.add_option( |
1312 | '--no-post-overwrites', | |
1313 | action='store_true', dest='nopostoverwrites', default=False, | |
6623ac34 | 1314 | help='Do not overwrite post-processed files') |
8450c15c PH |
1315 | postproc.add_option( |
1316 | '--embed-subs', | |
1317 | action='store_true', dest='embedsubtitles', default=False, | |
40025ee2 | 1318 | help='Embed subtitles in the video (only for mp4, webm and mkv videos)') |
6623ac34 | 1319 | postproc.add_option( |
1320 | '--no-embed-subs', | |
1321 | action='store_false', dest='embedsubtitles', | |
1322 | help='Do not embed subtitles (default)') | |
8450c15c PH |
1323 | postproc.add_option( |
1324 | '--embed-thumbnail', | |
1325 | action='store_true', dest='embedthumbnail', default=False, | |
6aecd871 | 1326 | help='Embed thumbnail in the video as cover art') |
6623ac34 | 1327 | postproc.add_option( |
1328 | '--no-embed-thumbnail', | |
1329 | action='store_false', dest='embedthumbnail', | |
1330 | help='Do not embed thumbnail (default)') | |
8450c15c | 1331 | postproc.add_option( |
7e067091 | 1332 | '--embed-metadata', '--add-metadata', |
8450c15c | 1333 | action='store_true', dest='addmetadata', default=False, |
dac5df5a | 1334 | help=( |
1335 | 'Embed metadata to the video file. Also embeds chapters/infojson if present ' | |
1336 | 'unless --no-embed-chapters/--no-embed-info-json are used (Alias: --add-metadata)')) | |
6623ac34 | 1337 | postproc.add_option( |
7e067091 | 1338 | '--no-embed-metadata', '--no-add-metadata', |
6623ac34 | 1339 | action='store_false', dest='addmetadata', |
7a340e0d NA |
1340 | help='Do not add metadata to file (default) (Alias: --no-add-metadata)') |
1341 | postproc.add_option( | |
1342 | '--embed-chapters', '--add-chapters', | |
1343 | action='store_true', dest='addchapters', default=None, | |
1344 | help='Add chapter markers to the video file (Alias: --add-chapters)') | |
1345 | postproc.add_option( | |
1346 | '--no-embed-chapters', '--no-add-chapters', | |
1347 | action='store_false', dest='addchapters', | |
1348 | help='Do not add chapter markers (default) (Alias: --no-add-chapters)') | |
dac5df5a | 1349 | postproc.add_option( |
1350 | '--embed-info-json', | |
1351 | action='store_true', dest='embed_infojson', default=None, | |
1352 | help='Embed the infojson as an attachment to mkv/mka video files') | |
1353 | postproc.add_option( | |
1354 | '--no-embed-info-json', | |
1355 | action='store_false', dest='embed_infojson', | |
1356 | help='Do not embed the infojson as an attachment to the video file') | |
e7db87f7 | 1357 | postproc.add_option( |
1358 | '--metadata-from-title', | |
1359 | metavar='FORMAT', dest='metafromtitle', | |
5bfa4862 | 1360 | help=optparse.SUPPRESS_HELP) |
1361 | postproc.add_option( | |
1362 | '--parse-metadata', | |
e9f4ccd1 | 1363 | metavar='FROM:TO', dest='parse_metadata', action='append', |
6623ac34 | 1364 | help=( |
73cd218f | 1365 | 'Parse additional metadata like title/artist from other fields; ' |
1366 | 'see "MODIFYING METADATA" for details')) | |
e9f4ccd1 | 1367 | postproc.add_option( |
1368 | '--replace-in-metadata', | |
1369 | dest='parse_metadata', metavar='FIELDS REGEX REPLACE', action='append', nargs=3, | |
1370 | help='Replace text in a metadata field using the given regex. This option can be used multiple times') | |
8450c15c PH |
1371 | postproc.add_option( |
1372 | '--xattrs', | |
1373 | action='store_true', dest='xattrs', default=False, | |
17941321 | 1374 | help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)') |
6271f1ca PH |
1375 | postproc.add_option( |
1376 | '--fixup', | |
99594a11 | 1377 | metavar='POLICY', dest='fixup', default=None, |
f89b3e2d | 1378 | choices=('never', 'ignore', 'warn', 'detect_or_warn', 'force'), |
6623ac34 | 1379 | help=( |
1380 | 'Automatically correct known faults of the file. ' | |
1381 | 'One of never (do nothing), warn (only emit a warning), ' | |
f89b3e2d | 1382 | 'detect_or_warn (the default; fix file if we can, warn otherwise), ' |
f304da8a | 1383 | 'force (try fixing even if file already exists)')) |
8450c15c | 1384 | postproc.add_option( |
6623ac34 | 1385 | '--prefer-avconv', '--no-prefer-ffmpeg', |
8450c15c | 1386 | action='store_false', dest='prefer_ffmpeg', |
e4172ac9 | 1387 | help=optparse.SUPPRESS_HELP) |
8450c15c | 1388 | postproc.add_option( |
6623ac34 | 1389 | '--prefer-ffmpeg', '--no-prefer-avconv', |
e4172ac9 | 1390 | action='store_true', dest='prefer_ffmpeg', default=True, |
1391 | help=optparse.SUPPRESS_HELP) | |
73fac4e9 PH |
1392 | postproc.add_option( |
1393 | '--ffmpeg-location', '--avconv-location', metavar='PATH', | |
1394 | dest='ffmpeg_location', | |
e4172ac9 | 1395 | help='Location of the ffmpeg binary; either the path to the binary or its containing directory') |
34a741a8 | 1396 | postproc.add_option( |
1e43a6f7 | 1397 | '--exec', |
1398 | metavar='[WHEN:]CMD', dest='exec_cmd', default={}, type='str', | |
1399 | action='callback', callback=_dict_from_options_callback, | |
1400 | callback_kwargs={ | |
1401 | 'allowed_keys': '|'.join(map(re.escape, POSTPROCESS_WHEN)), | |
1402 | 'default_key': 'after_move', | |
1403 | 'multiple_keys': False, | |
1404 | 'append': True, | |
1405 | }, help=( | |
1406 | 'Execute a command, optionally prefixed with when to execute it (after_move if unspecified), separated by a ":". ' | |
1407 | 'Supported values of "WHEN" are the same as that of --use-postprocessor. ' | |
34488702 | 1408 | 'Same syntax as the output template can be used to pass any field as arguments to the command. ' |
1e43a6f7 | 1409 | 'After download, an additional field "filepath" that contains the final path of the downloaded file ' |
1410 | 'is also available, and if no fields are passed, %(filepath)q is appended to the end of the command. ' | |
c681cb5d | 1411 | 'This option can be used multiple times')) |
1412 | postproc.add_option( | |
1413 | '--no-exec', | |
1e43a6f7 | 1414 | action='store_const', dest='exec_cmd', const={}, |
c681cb5d | 1415 | help='Remove any previously defined --exec') |
1416 | postproc.add_option( | |
1417 | '--exec-before-download', metavar='CMD', | |
ad3dc496 | 1418 | action='append', dest='exec_before_dl_cmd', |
1e43a6f7 | 1419 | help=optparse.SUPPRESS_HELP) |
5520aa2d | 1420 | postproc.add_option( |
c681cb5d | 1421 | '--no-exec-before-download', |
1422 | action='store_const', dest='exec_before_dl_cmd', const=[], | |
1e43a6f7 | 1423 | help=optparse.SUPPRESS_HELP) |
e9fade72 | 1424 | postproc.add_option( |
e167860c | 1425 | '--convert-subs', '--convert-sub', '--convert-subtitles', |
e9fade72 | 1426 | metavar='FORMAT', dest='convertsubtitles', default=None, |
81a23040 | 1427 | help=( |
1428 | 'Convert the subtitles to another format (currently supported: %s) ' | |
1429 | '(Alias: --convert-subtitles)' % '|'.join(FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS))) | |
8fa43c73 | 1430 | postproc.add_option( |
1431 | '--convert-thumbnails', | |
1432 | metavar='FORMAT', dest='convertthumbnails', default=None, | |
81a23040 | 1433 | help=( |
1434 | 'Convert the thumbnails to another format ' | |
1435 | '(currently supported: %s) ' % '|'.join(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS))) | |
72755351 | 1436 | postproc.add_option( |
1437 | '--split-chapters', '--split-tracks', | |
1438 | dest='split_chapters', action='store_true', default=False, | |
1439 | help=( | |
1440 | 'Split video into multiple files based on internal chapters. ' | |
1441 | 'The "chapter:" prefix can be used with "--paths" and "--output" to ' | |
1442 | 'set the output filename for the split files. See "OUTPUT TEMPLATE" for details')) | |
1443 | postproc.add_option( | |
1444 | '--no-split-chapters', '--no-split-tracks', | |
1445 | dest='split_chapters', action='store_false', | |
1446 | help='Do not split video based on chapters (default)') | |
7a340e0d NA |
1447 | postproc.add_option( |
1448 | '--remove-chapters', | |
1449 | metavar='REGEX', dest='remove_chapters', action='append', | |
2d9ec704 | 1450 | help=( |
1451 | 'Remove chapters whose title matches the given regular expression. ' | |
1452 | 'Time ranges prefixed by a "*" can also be used in place of chapters to remove the specified range. ' | |
1453 | 'Eg: --remove-chapters "*10:15-15:00" --remove-chapters "intro". ' | |
1454 | 'This option can be used multiple times')) | |
7a340e0d NA |
1455 | postproc.add_option( |
1456 | '--no-remove-chapters', dest='remove_chapters', action='store_const', const=None, | |
1457 | help='Do not remove any chapters from the file (default)') | |
1458 | postproc.add_option( | |
1459 | '--force-keyframes-at-cuts', | |
1460 | action='store_true', dest='force_keyframes_at_cuts', default=False, | |
1461 | help=( | |
1462 | 'Force keyframes around the chapters before removing/splitting them. ' | |
e75bb0d6 | 1463 | 'Requires a re-encode and thus is very slow, but the resulting video ' |
7a340e0d NA |
1464 | 'may have fewer artifacts around the cuts')) |
1465 | postproc.add_option( | |
1466 | '--no-force-keyframes-at-cuts', | |
1467 | action='store_false', dest='force_keyframes_at_cuts', | |
1468 | help='Do not force keyframes around the chapters when cutting/splitting (default)') | |
3ae5e797 | 1469 | _postprocessor_opts_parser = lambda key, val='': ( |
1470 | *(item.split('=', 1) for item in (val.split(';') if val else [])), | |
1471 | ('key', remove_end(key, 'PP'))) | |
1472 | postproc.add_option( | |
1473 | '--use-postprocessor', | |
1474 | metavar='NAME[:ARGS]', dest='add_postprocessors', default=[], type='str', | |
1475 | action='callback', callback=_list_from_options_callback, | |
1476 | callback_kwargs={ | |
1477 | 'delim': None, | |
1478 | 'process': lambda val: dict(_postprocessor_opts_parser(*val.split(':', 1))) | |
1479 | }, help=( | |
1480 | 'The (case sensitive) name of plugin postprocessors to be enabled, ' | |
e75bb0d6 | 1481 | 'and (optionally) arguments to be passed to it, separated by a colon ":". ' |
3ae5e797 | 1482 | 'ARGS are a semicolon ";" delimited list of NAME=VALUE. ' |
1483 | 'The "when" argument determines when the postprocessor is invoked. ' | |
1484 | 'It can be one of "pre_process" (after extraction), ' | |
1485 | '"before_dl" (before video download), "post_process" (after video download; default) ' | |
1486 | 'or "after_move" (after moving file to their final locations). ' | |
1487 | 'This option can be used multiple times to add different postprocessors')) | |
34a741a8 | 1488 | |
7a340e0d NA |
1489 | sponsorblock = optparse.OptionGroup(parser, 'SponsorBlock Options', description=( |
1490 | 'Make chapter entries for, or remove various segments (sponsor, introductions, etc.) ' | |
1491 | 'from downloaded YouTube videos using the SponsorBlock API (https://sponsor.ajay.app)')) | |
1492 | sponsorblock.add_option( | |
1493 | '--sponsorblock-mark', metavar='CATS', | |
1494 | dest='sponsorblock_mark', default=set(), action='callback', type='str', | |
8157a09d NA |
1495 | callback=_set_from_options_callback, callback_kwargs={ |
1496 | 'allowed_values': SponsorBlockPP.CATEGORIES.keys(), | |
1497 | 'aliases': {'default': ['all']} | |
1498 | }, help=( | |
7a340e0d | 1499 | 'SponsorBlock categories to create chapters for, separated by commas. ' |
8157a09d NA |
1500 | f'Available categories are all, default(=all), {", ".join(SponsorBlockPP.CATEGORIES.keys())}. ' |
1501 | 'You can prefix the category with a "-" to exempt it. See [1] for description of the categories. ' | |
1502 | 'Eg: --sponsorblock-mark all,-preview [1] https://wiki.sponsor.ajay.app/w/Segment_Categories')) | |
7a340e0d NA |
1503 | sponsorblock.add_option( |
1504 | '--sponsorblock-remove', metavar='CATS', | |
1505 | dest='sponsorblock_remove', default=set(), action='callback', type='str', | |
8157a09d NA |
1506 | callback=_set_from_options_callback, callback_kwargs={ |
1507 | 'allowed_values': set(SponsorBlockPP.CATEGORIES.keys()) - set(SponsorBlockPP.POI_CATEGORIES.keys()), | |
1508 | # Note: From https://wiki.sponsor.ajay.app/w/Types: | |
1509 | # The filler category is very aggressive. | |
1510 | # It is strongly recommended to not use this in a client by default. | |
1511 | 'aliases': {'default': ['all', '-filler']} | |
1512 | }, help=( | |
7a340e0d NA |
1513 | 'SponsorBlock categories to be removed from the video file, separated by commas. ' |
1514 | 'If a category is present in both mark and remove, remove takes precedence. ' | |
8157a09d NA |
1515 | 'The syntax and available categories are the same as for --sponsorblock-mark ' |
1516 | 'except that "default" refers to "all,-filler" ' | |
1517 | f'and {", ".join(SponsorBlockPP.POI_CATEGORIES.keys())} is not available')) | |
7a340e0d NA |
1518 | sponsorblock.add_option( |
1519 | '--sponsorblock-chapter-title', metavar='TEMPLATE', | |
1520 | default=DEFAULT_SPONSORBLOCK_CHAPTER_TITLE, dest='sponsorblock_chapter_title', | |
1521 | help=( | |
1522 | 'The title template for SponsorBlock chapters created by --sponsorblock-mark. ' | |
1523 | 'The same syntax as the output template is used, but the only available fields are ' | |
1524 | 'start_time, end_time, category, categories, name, category_names. Defaults to "%default"')) | |
1525 | sponsorblock.add_option( | |
1526 | '--no-sponsorblock', default=False, | |
1527 | action='store_true', dest='no_sponsorblock', | |
1528 | help='Disable both --sponsorblock-mark and --sponsorblock-remove') | |
1529 | sponsorblock.add_option( | |
1530 | '--sponsorblock-api', metavar='URL', | |
1531 | default='https://sponsor.ajay.app', dest='sponsorblock_api', | |
1532 | help='SponsorBlock API location, defaults to %default') | |
1533 | ||
1534 | sponsorblock.add_option( | |
a9e7f546 | 1535 | '--sponskrub', |
165efb82 | 1536 | action='store_true', dest='sponskrub', default=False, |
7a340e0d NA |
1537 | help=optparse.SUPPRESS_HELP) |
1538 | sponsorblock.add_option( | |
a9e7f546 | 1539 | '--no-sponskrub', |
1540 | action='store_false', dest='sponskrub', | |
7a340e0d NA |
1541 | help=optparse.SUPPRESS_HELP) |
1542 | sponsorblock.add_option( | |
a9e7f546 | 1543 | '--sponskrub-cut', default=False, |
1544 | action='store_true', dest='sponskrub_cut', | |
7a340e0d NA |
1545 | help=optparse.SUPPRESS_HELP) |
1546 | sponsorblock.add_option( | |
6623ac34 | 1547 | '--no-sponskrub-cut', |
1548 | action='store_false', dest='sponskrub_cut', | |
7a340e0d NA |
1549 | help=optparse.SUPPRESS_HELP) |
1550 | sponsorblock.add_option( | |
a9e7f546 | 1551 | '--sponskrub-force', default=False, |
1552 | action='store_true', dest='sponskrub_force', | |
7a340e0d NA |
1553 | help=optparse.SUPPRESS_HELP) |
1554 | sponsorblock.add_option( | |
6623ac34 | 1555 | '--no-sponskrub-force', |
1556 | action='store_true', dest='sponskrub_force', | |
7a340e0d NA |
1557 | help=optparse.SUPPRESS_HELP) |
1558 | sponsorblock.add_option( | |
a9e7f546 | 1559 | '--sponskrub-location', metavar='PATH', |
1560 | dest='sponskrub_path', default='', | |
7a340e0d NA |
1561 | help=optparse.SUPPRESS_HELP) |
1562 | sponsorblock.add_option( | |
c76eb41b | 1563 | '--sponskrub-args', dest='sponskrub_args', metavar='ARGS', |
1b77b347 | 1564 | help=optparse.SUPPRESS_HELP) |
a9e7f546 | 1565 | |
78895bd3 | 1566 | extractor = optparse.OptionGroup(parser, 'Extractor Options') |
62bff2c1 | 1567 | extractor.add_option( |
1568 | '--extractor-retries', | |
d6e51845 | 1569 | dest='extractor_retries', metavar='RETRIES', default=3, |
62bff2c1 | 1570 | help='Number of retries for known extractor errors (default is %default), or "infinite"') |
78895bd3 | 1571 | extractor.add_option( |
6623ac34 | 1572 | '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd', |
78895bd3 | 1573 | action='store_true', dest='dynamic_mpd', default=True, |
8a51f564 | 1574 | help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)') |
78895bd3 | 1575 | extractor.add_option( |
6623ac34 | 1576 | '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd', |
78895bd3 | 1577 | action='store_false', dest='dynamic_mpd', |
8a51f564 | 1578 | help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)') |
310c2ed2 | 1579 | extractor.add_option( |
1580 | '--hls-split-discontinuity', | |
1581 | dest='hls_split_discontinuity', action='store_true', default=False, | |
1582 | help='Split HLS playlists to different formats at discontinuities such as ad breaks' | |
1583 | ) | |
1584 | extractor.add_option( | |
1585 | '--no-hls-split-discontinuity', | |
1586 | dest='hls_split_discontinuity', action='store_false', | |
1587 | help='Do not split HLS playlists to different formats at discontinuities such as ad breaks (default)') | |
042931a5 | 1588 | _extractor_arg_parser = lambda key, vals='': (key.strip().lower().replace('-', '_'), [ |
1589 | val.replace(r'\,', ',').strip() for val in re.split(r'(?<!\\),', vals)]) | |
5d3a0e79 | 1590 | extractor.add_option( |
1591 | '--extractor-args', | |
1592 | metavar='KEY:ARGS', dest='extractor_args', default={}, type='str', | |
1593 | action='callback', callback=_dict_from_options_callback, | |
1594 | callback_kwargs={ | |
1595 | 'multiple_keys': False, | |
1596 | 'process': lambda val: dict( | |
4bb6b02f | 1597 | _extractor_arg_parser(*arg.split('=', 1)) for arg in val.split(';')) |
dbf5416a | 1598 | }, help=( |
5d3a0e79 | 1599 | 'Pass these arguments to the extractor. See "EXTRACTOR ARGUMENTS" for details. ' |
4bb6b02f | 1600 | 'You can use this option multiple times to give arguments for different extractors')) |
e409895f | 1601 | extractor.add_option( |
1602 | '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest', | |
1603 | action='store_true', dest='youtube_include_dash_manifest', default=True, | |
5d3a0e79 | 1604 | help=optparse.SUPPRESS_HELP) |
e409895f | 1605 | extractor.add_option( |
1606 | '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest', | |
1607 | action='store_false', dest='youtube_include_dash_manifest', | |
5d3a0e79 | 1608 | help=optparse.SUPPRESS_HELP) |
e409895f | 1609 | extractor.add_option( |
1610 | '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest', | |
1611 | action='store_true', dest='youtube_include_hls_manifest', default=True, | |
5d3a0e79 | 1612 | help=optparse.SUPPRESS_HELP) |
e409895f | 1613 | extractor.add_option( |
1614 | '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest', | |
1615 | action='store_false', dest='youtube_include_hls_manifest', | |
5d3a0e79 | 1616 | help=optparse.SUPPRESS_HELP) |
78895bd3 | 1617 | |
34a741a8 | 1618 | parser.add_option_group(general) |
be4a824d | 1619 | parser.add_option_group(network) |
0aa10994 | 1620 | parser.add_option_group(geo) |
34a741a8 PH |
1621 | parser.add_option_group(selection) |
1622 | parser.add_option_group(downloader) | |
1623 | parser.add_option_group(filesystem) | |
cfb56d1a | 1624 | parser.add_option_group(thumbnail) |
732044af | 1625 | parser.add_option_group(link) |
34a741a8 PH |
1626 | parser.add_option_group(verbosity) |
1627 | parser.add_option_group(workarounds) | |
1628 | parser.add_option_group(video_format) | |
1629 | parser.add_option_group(subtitles) | |
1630 | parser.add_option_group(authentication) | |
1631 | parser.add_option_group(postproc) | |
7a340e0d | 1632 | parser.add_option_group(sponsorblock) |
78895bd3 | 1633 | parser.add_option_group(extractor) |
34a741a8 PH |
1634 | |
1635 | if overrideArguments is not None: | |
1636 | opts, args = parser.parse_args(overrideArguments) | |
1637 | if opts.verbose: | |
8450c15c | 1638 | write_string('[debug] Override config: ' + repr(overrideArguments) + '\n') |
34a741a8 | 1639 | else: |
b04b94da S |
1640 | def compat_conf(conf): |
1641 | if sys.version_info < (3,): | |
1642 | return [a.decode(preferredencoding(), 'replace') for a in conf] | |
1643 | return conf | |
1644 | ||
e2e43aea | 1645 | configs = { |
0202b52a | 1646 | 'command-line': compat_conf(sys.argv[1:]), |
1647 | 'custom': [], 'home': [], 'portable': [], 'user': [], 'system': []} | |
1648 | paths = {'command-line': False} | |
7303f84a | 1649 | |
1650 | def read_options(name, path, user=False): | |
1651 | ''' loads config files and returns ignoreconfig ''' | |
1652 | # Multiple package names can be given here | |
1653 | # Eg: ('yt-dlp', 'youtube-dlc', 'youtube-dl') will look for | |
1654 | # the configuration file of any of these three packages | |
1655 | for package in ('yt-dlp',): | |
1656 | if user: | |
1657 | config, current_path = _readUserConf(package, default=None) | |
1658 | else: | |
1659 | current_path = os.path.join(path, '%s.conf' % package) | |
1660 | config = _readOptions(current_path, default=None) | |
1661 | if config is not None: | |
2aa5e2cc | 1662 | current_path = os.path.realpath(current_path) |
1663 | if current_path in paths.values(): | |
1664 | return False | |
7303f84a | 1665 | configs[name], paths[name] = config, current_path |
1666 | return parser.parse_args(config)[0].ignoreconfig | |
1667 | return False | |
f5e2efbb | 1668 | |
e2e43aea | 1669 | def get_configs(): |
7303f84a | 1670 | opts, _ = parser.parse_args(configs['command-line']) |
1671 | if opts.config_location is not None: | |
e2e43aea | 1672 | location = compat_expanduser(opts.config_location) |
1673 | if os.path.isdir(location): | |
7a5c1cfe | 1674 | location = os.path.join(location, 'yt-dlp.conf') |
e2e43aea | 1675 | if not os.path.exists(location): |
1676 | parser.error('config-location %s does not exist.' % location) | |
7303f84a | 1677 | config = _readOptions(location, default=None) |
1678 | if config: | |
7b386498 | 1679 | configs['custom'], paths['custom'] = config, location |
7303f84a | 1680 | |
1681 | if opts.ignoreconfig: | |
e2e43aea | 1682 | return |
7303f84a | 1683 | if parser.parse_args(configs['custom'])[0].ignoreconfig: |
e2e43aea | 1684 | return |
7303f84a | 1685 | if read_options('portable', get_executable_path()): |
e2e43aea | 1686 | return |
7303f84a | 1687 | opts, _ = parser.parse_args(configs['portable'] + configs['custom'] + configs['command-line']) |
1688 | if read_options('home', expand_path(opts.paths.get('home', '')).strip()): | |
0202b52a | 1689 | return |
7303f84a | 1690 | if read_options('system', '/etc'): |
e2e43aea | 1691 | return |
7303f84a | 1692 | if read_options('user', None, user=True): |
0202b52a | 1693 | configs['system'], paths['system'] = [], None |
e66dca5e | 1694 | |
e2e43aea | 1695 | get_configs() |
0202b52a | 1696 | argv = configs['system'] + configs['user'] + configs['home'] + configs['portable'] + configs['custom'] + configs['command-line'] |
34a741a8 PH |
1697 | opts, args = parser.parse_args(argv) |
1698 | if opts.verbose: | |
b5ae35ee | 1699 | for label in ('Command-line', 'Custom', 'Portable', 'Home', 'User', 'System'): |
0202b52a | 1700 | key = label.lower() |
7303f84a | 1701 | if paths.get(key): |
1702 | write_string(f'[debug] {label} config file: {paths[key]}\n') | |
1703 | if paths.get(key) is not None: | |
1704 | write_string(f'[debug] {label} config: {_hide_login_info(configs[key])!r}\n') | |
34a741a8 PH |
1705 | |
1706 | return parser, opts, args |