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