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