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