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