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