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