options.py 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  1. import collections
  2. import contextlib
  3. import optparse
  4. import os.path
  5. import re
  6. import shlex
  7. import shutil
  8. import string
  9. import sys
  10. from .compat import compat_expanduser
  11. from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS
  12. from .downloader.external import list_external_downloaders
  13. from .postprocessor import (
  14. FFmpegExtractAudioPP,
  15. FFmpegMergerPP,
  16. FFmpegSubtitlesConvertorPP,
  17. FFmpegThumbnailsConvertorPP,
  18. FFmpegVideoRemuxerPP,
  19. SponsorBlockPP,
  20. )
  21. from .postprocessor.modify_chapters import DEFAULT_SPONSORBLOCK_CHAPTER_TITLE
  22. from .update import UPDATE_SOURCES, detect_variant, is_non_updateable
  23. from .utils import (
  24. OUTTMPL_TYPES,
  25. POSTPROCESS_WHEN,
  26. Config,
  27. deprecation_warning,
  28. expand_path,
  29. format_field,
  30. get_executable_path,
  31. get_system_config_dirs,
  32. get_user_config_dirs,
  33. join_nonempty,
  34. orderedSet_from_options,
  35. remove_end,
  36. variadic,
  37. write_string,
  38. )
  39. from .version import CHANNEL, __version__
  40. def parseOpts(overrideArguments=None, ignore_config_files='if_override'): # noqa: N803
  41. PACKAGE_NAME = 'yt-dlp'
  42. root = Config(create_parser())
  43. if ignore_config_files == 'if_override':
  44. ignore_config_files = overrideArguments is not None
  45. def read_config(*paths):
  46. path = os.path.join(*paths)
  47. conf = Config.read_file(path, default=None)
  48. if conf is not None:
  49. return conf, path
  50. def _load_from_config_dirs(config_dirs):
  51. for config_dir in config_dirs:
  52. head, tail = os.path.split(config_dir)
  53. assert tail == PACKAGE_NAME or config_dir == os.path.join(compat_expanduser('~'), f'.{PACKAGE_NAME}')
  54. yield read_config(head, f'{PACKAGE_NAME}.conf')
  55. if tail.startswith('.'): # ~/.PACKAGE_NAME
  56. yield read_config(head, f'{PACKAGE_NAME}.conf.txt')
  57. yield read_config(config_dir, 'config')
  58. yield read_config(config_dir, 'config.txt')
  59. def add_config(label, path=None, func=None):
  60. """ Adds config and returns whether to continue """
  61. if root.parse_known_args()[0].ignoreconfig:
  62. return False
  63. elif func:
  64. assert path is None
  65. args, current_path = next(
  66. filter(None, _load_from_config_dirs(func(PACKAGE_NAME))), (None, None))
  67. else:
  68. current_path = os.path.join(path, 'yt-dlp.conf')
  69. args = Config.read_file(current_path, default=None)
  70. if args is not None:
  71. root.append_config(args, current_path, label=label)
  72. return True
  73. def load_configs():
  74. yield not ignore_config_files
  75. yield add_config('Portable', get_executable_path())
  76. yield add_config('Home', expand_path(root.parse_known_args()[0].paths.get('home', '')).strip())
  77. yield add_config('User', func=get_user_config_dirs)
  78. yield add_config('System', func=get_system_config_dirs)
  79. opts = optparse.Values({'verbose': True, 'print_help': False})
  80. try:
  81. try:
  82. if overrideArguments is not None:
  83. root.append_config(overrideArguments, label='Override')
  84. else:
  85. root.append_config(sys.argv[1:], label='Command-line')
  86. loaded_all_configs = all(load_configs())
  87. except ValueError as err:
  88. raise root.parser.error(err)
  89. if loaded_all_configs:
  90. # If ignoreconfig is found inside the system configuration file,
  91. # the user configuration is removed
  92. if root.parse_known_args()[0].ignoreconfig:
  93. user_conf = next((i for i, conf in enumerate(root.configs) if conf.label == 'User'), None)
  94. if user_conf is not None:
  95. root.configs.pop(user_conf)
  96. try:
  97. root.configs[0].load_configs() # Resolve any aliases using --config-location
  98. except ValueError as err:
  99. raise root.parser.error(err)
  100. opts, args = root.parse_args()
  101. except optparse.OptParseError:
  102. with contextlib.suppress(optparse.OptParseError):
  103. opts, _ = root.parse_known_args(strict=False)
  104. raise
  105. except (SystemExit, KeyboardInterrupt):
  106. opts.verbose = False
  107. raise
  108. finally:
  109. verbose = opts.verbose and f'\n{root}'.replace('\n| ', '\n[debug] ')[1:]
  110. if verbose:
  111. write_string(f'{verbose}\n')
  112. if opts.print_help:
  113. if verbose:
  114. write_string('\n')
  115. root.parser.print_help()
  116. if opts.print_help:
  117. sys.exit()
  118. return root.parser, opts, args
  119. class _YoutubeDLHelpFormatter(optparse.IndentedHelpFormatter):
  120. def __init__(self):
  121. # No need to wrap help messages if we're on a wide console
  122. max_width = shutil.get_terminal_size().columns or 80
  123. # The % is chosen to get a pretty output in README.md
  124. super().__init__(width=max_width, max_help_position=int(0.45 * max_width))
  125. @staticmethod
  126. def format_option_strings(option):
  127. """ ('-o', '--option') -> -o, --format METAVAR """
  128. opts = join_nonempty(
  129. option._short_opts and option._short_opts[0],
  130. option._long_opts and option._long_opts[0],
  131. delim=', ')
  132. if option.takes_value():
  133. opts += f' {option.metavar}'
  134. return opts
  135. class _YoutubeDLOptionParser(optparse.OptionParser):
  136. # optparse is deprecated since Python 3.2. So assume a stable interface even for private methods
  137. ALIAS_DEST = '_triggered_aliases'
  138. ALIAS_TRIGGER_LIMIT = 100
  139. def __init__(self):
  140. super().__init__(
  141. prog='yt-dlp' if detect_variant() == 'source' else None,
  142. version=__version__,
  143. usage='%prog [OPTIONS] URL [URL...]',
  144. epilog='See full documentation at https://github.com/yt-dlp/yt-dlp#readme',
  145. formatter=_YoutubeDLHelpFormatter(),
  146. conflict_handler='resolve',
  147. )
  148. self.set_default(self.ALIAS_DEST, collections.defaultdict(int))
  149. _UNKNOWN_OPTION = (optparse.BadOptionError, optparse.AmbiguousOptionError)
  150. _BAD_OPTION = optparse.OptionValueError
  151. def parse_known_args(self, args=None, values=None, strict=True):
  152. """Same as parse_args, but ignore unknown switches. Similar to argparse.parse_known_args"""
  153. self.rargs, self.largs = self._get_args(args), []
  154. self.values = values or self.get_default_values()
  155. while self.rargs:
  156. arg = self.rargs[0]
  157. try:
  158. if arg == '--':
  159. del self.rargs[0]
  160. break
  161. elif arg.startswith('--'):
  162. self._process_long_opt(self.rargs, self.values)
  163. elif arg.startswith('-') and arg != '-':
  164. self._process_short_opts(self.rargs, self.values)
  165. elif self.allow_interspersed_args:
  166. self.largs.append(self.rargs.pop(0))
  167. else:
  168. break
  169. except optparse.OptParseError as err:
  170. if isinstance(err, self._UNKNOWN_OPTION):
  171. self.largs.append(err.opt_str)
  172. elif strict:
  173. if isinstance(err, self._BAD_OPTION):
  174. self.error(str(err))
  175. raise
  176. return self.check_values(self.values, self.largs)
  177. def _generate_error_message(self, msg):
  178. msg = f'{self.get_prog_name()}: error: {str(msg).strip()}\n'
  179. return f'{self.get_usage()}\n{msg}' if self.usage else msg
  180. def error(self, msg):
  181. raise optparse.OptParseError(self._generate_error_message(msg))
  182. def _get_args(self, args):
  183. return sys.argv[1:] if args is None else list(args)
  184. def _match_long_opt(self, opt):
  185. """Improve ambiguous argument resolution by comparing option objects instead of argument strings"""
  186. try:
  187. return super()._match_long_opt(opt)
  188. except optparse.AmbiguousOptionError as e:
  189. if len({self._long_opt[p] for p in e.possibilities}) == 1:
  190. return e.possibilities[0]
  191. raise
  192. def create_parser():
  193. def _list_from_options_callback(option, opt_str, value, parser, append=True, delim=',', process=str.strip):
  194. # append can be True, False or -1 (prepend)
  195. current = list(getattr(parser.values, option.dest)) if append else []
  196. value = list(filter(None, [process(value)] if delim is None else map(process, value.split(delim))))
  197. setattr(
  198. parser.values, option.dest,
  199. current + value if append is True else value + current)
  200. def _set_from_options_callback(
  201. option, opt_str, value, parser, allowed_values, delim=',', aliases={},
  202. process=lambda x: x.lower().strip()):
  203. values = [process(value)] if delim is None else map(process, value.split(delim))
  204. try:
  205. requested = orderedSet_from_options(values, collections.ChainMap(aliases, {'all': allowed_values}),
  206. start=getattr(parser.values, option.dest))
  207. except ValueError as e:
  208. raise optparse.OptionValueError(f'wrong {option.metavar} for {opt_str}: {e.args[0]}')
  209. setattr(parser.values, option.dest, set(requested))
  210. def _dict_from_options_callback(
  211. option, opt_str, value, parser,
  212. allowed_keys=r'[\w-]+', delimiter=':', default_key=None, process=None, multiple_keys=True,
  213. process_key=str.lower, append=False):
  214. out_dict = dict(getattr(parser.values, option.dest))
  215. multiple_args = not isinstance(value, str)
  216. if multiple_keys:
  217. allowed_keys = fr'({allowed_keys})(,({allowed_keys}))*'
  218. mobj = re.match(
  219. fr'(?is)(?P<keys>{allowed_keys}){delimiter}(?P<val>.*)$',
  220. value[0] if multiple_args else value)
  221. if mobj is not None:
  222. keys, val = mobj.group('keys').split(','), mobj.group('val')
  223. if multiple_args:
  224. val = [val, *value[1:]]
  225. elif default_key is not None:
  226. keys, val = variadic(default_key), value
  227. else:
  228. raise optparse.OptionValueError(
  229. f'wrong {opt_str} formatting; it should be {option.metavar}, not "{value}"')
  230. try:
  231. keys = map(process_key, keys) if process_key else keys
  232. val = process(val) if process else val
  233. except Exception as err:
  234. raise optparse.OptionValueError(f'wrong {opt_str} formatting; {err}')
  235. for key in keys:
  236. out_dict[key] = [*out_dict.get(key, []), val] if append else val
  237. setattr(parser.values, option.dest, out_dict)
  238. def when_prefix(default):
  239. return {
  240. 'default': {},
  241. 'type': 'str',
  242. 'action': 'callback',
  243. 'callback': _dict_from_options_callback,
  244. 'callback_kwargs': {
  245. 'allowed_keys': '|'.join(map(re.escape, POSTPROCESS_WHEN)),
  246. 'default_key': default,
  247. 'multiple_keys': False,
  248. 'append': True,
  249. },
  250. }
  251. parser = _YoutubeDLOptionParser()
  252. alias_group = optparse.OptionGroup(parser, 'Aliases')
  253. Formatter = string.Formatter()
  254. def _create_alias(option, opt_str, value, parser):
  255. aliases, opts = value
  256. try:
  257. nargs = len({i if f == '' else f
  258. for i, (_, f, _, _) in enumerate(Formatter.parse(opts)) if f is not None})
  259. opts.format(*map(str, range(nargs))) # validate
  260. except Exception as err:
  261. raise optparse.OptionValueError(f'wrong {opt_str} OPTIONS formatting; {err}')
  262. if alias_group not in parser.option_groups:
  263. parser.add_option_group(alias_group)
  264. aliases = (x if x.startswith('-') else f'--{x}' for x in map(str.strip, aliases.split(',')))
  265. try:
  266. args = [f'ARG{i}' for i in range(nargs)]
  267. alias_group.add_option(
  268. *aliases, nargs=nargs, dest=parser.ALIAS_DEST, type='str' if nargs else None,
  269. metavar=' '.join(args), help=opts.format(*args), action='callback',
  270. callback=_alias_callback, callback_kwargs={'opts': opts, 'nargs': nargs})
  271. except Exception as err:
  272. raise optparse.OptionValueError(f'wrong {opt_str} formatting; {err}')
  273. def _alias_callback(option, opt_str, value, parser, opts, nargs):
  274. counter = getattr(parser.values, option.dest)
  275. counter[opt_str] += 1
  276. if counter[opt_str] > parser.ALIAS_TRIGGER_LIMIT:
  277. raise optparse.OptionValueError(f'Alias {opt_str} exceeded invocation limit')
  278. if nargs == 1:
  279. value = [value]
  280. assert (nargs == 0 and value is None) or len(value) == nargs
  281. parser.rargs[:0] = shlex.split(
  282. opts if value is None else opts.format(*map(shlex.quote, value)))
  283. general = optparse.OptionGroup(parser, 'General Options')
  284. general.add_option(
  285. '-h', '--help', dest='print_help', action='store_true',
  286. help='Print this help text and exit')
  287. general.add_option(
  288. '--version',
  289. action='version',
  290. help='Print program version and exit')
  291. general.add_option(
  292. '-U', '--update',
  293. action='store_const', dest='update_self', const=CHANNEL,
  294. help=format_field(
  295. is_non_updateable(), None, 'Check if updates are available. %s',
  296. default=f'Update this program to the latest {CHANNEL} version'))
  297. general.add_option(
  298. '--no-update',
  299. action='store_false', dest='update_self',
  300. help='Do not check for updates (default)')
  301. general.add_option(
  302. '--update-to',
  303. action='store', dest='update_self', metavar='[CHANNEL]@[TAG]',
  304. help=(
  305. 'Upgrade/downgrade to a specific version. CHANNEL can be a repository as well. '
  306. f'CHANNEL and TAG default to "{CHANNEL.partition("@")[0]}" and "latest" respectively if omitted; '
  307. f'See "UPDATE" for details. Supported channels: {", ".join(UPDATE_SOURCES)}'))
  308. general.add_option(
  309. '-i', '--ignore-errors',
  310. action='store_true', dest='ignoreerrors',
  311. help='Ignore download and postprocessing errors. The download will be considered successful even if the postprocessing fails')
  312. general.add_option(
  313. '--no-abort-on-error',
  314. action='store_const', dest='ignoreerrors', const='only_download',
  315. help='Continue with next video on download errors; e.g. to skip unavailable videos in a playlist (default)')
  316. general.add_option(
  317. '--abort-on-error', '--no-ignore-errors',
  318. action='store_false', dest='ignoreerrors',
  319. help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)')
  320. general.add_option(
  321. '--dump-user-agent',
  322. action='store_true', dest='dump_user_agent', default=False,
  323. help='Display the current user-agent and exit')
  324. general.add_option(
  325. '--list-extractors',
  326. action='store_true', dest='list_extractors', default=False,
  327. help='List all supported extractors and exit')
  328. general.add_option(
  329. '--extractor-descriptions',
  330. action='store_true', dest='list_extractor_descriptions', default=False,
  331. help='Output descriptions of all supported extractors and exit')
  332. general.add_option(
  333. '--use-extractors', '--ies',
  334. action='callback', dest='allowed_extractors', metavar='NAMES', type='str',
  335. default=[], callback=_list_from_options_callback,
  336. help=(
  337. 'Extractor names to use separated by commas. '
  338. 'You can also use regexes, "all", "default" and "end" (end URL matching); '
  339. 'e.g. --ies "holodex.*,end,youtube". '
  340. 'Prefix the name with a "-" to exclude it, e.g. --ies default,-generic. '
  341. 'Use --list-extractors for a list of extractor names. (Alias: --ies)'))
  342. general.add_option(
  343. '--force-generic-extractor',
  344. action='store_true', dest='force_generic_extractor', default=False,
  345. help=optparse.SUPPRESS_HELP)
  346. general.add_option(
  347. '--default-search',
  348. dest='default_search', metavar='PREFIX',
  349. help=(
  350. 'Use this prefix for unqualified URLs. '
  351. 'E.g. "gvsearch2:python" downloads two videos from google videos for the search term "python". '
  352. 'Use the value "auto" to let yt-dlp guess ("auto_warning" to emit a warning when guessing). '
  353. '"error" just throws an error. The default value "fixup_error" repairs broken URLs, '
  354. 'but emits an error if this is not possible instead of searching'))
  355. general.add_option(
  356. '--ignore-config', '--no-config',
  357. action='store_true', dest='ignoreconfig',
  358. help=(
  359. 'Don\'t load any more configuration files except those given to --config-locations. '
  360. 'For backward compatibility, if this option is found inside the system configuration file, the user configuration is not loaded. '
  361. '(Alias: --no-config)'))
  362. general.add_option(
  363. '--no-config-locations',
  364. action='store_const', dest='config_locations', const=[],
  365. help=(
  366. 'Do not load any custom configuration files (default). When given inside a '
  367. 'configuration file, ignore all previous --config-locations defined in the current file'))
  368. general.add_option(
  369. '--config-locations',
  370. dest='config_locations', metavar='PATH', action='append',
  371. help=(
  372. 'Location of the main configuration file; either the path to the config or its containing directory '
  373. '("-" for stdin). Can be used multiple times and inside other configuration files'))
  374. general.add_option(
  375. '--flat-playlist',
  376. action='store_const', dest='extract_flat', const='in_playlist', default=False,
  377. help='Do not extract the videos of a playlist, only list them')
  378. general.add_option(
  379. '--no-flat-playlist',
  380. action='store_false', dest='extract_flat',
  381. help='Fully extract the videos of a playlist (default)')
  382. general.add_option(
  383. '--live-from-start',
  384. action='store_true', dest='live_from_start',
  385. help='Download livestreams from the start. Currently only supported for YouTube (Experimental)')
  386. general.add_option(
  387. '--no-live-from-start',
  388. action='store_false', dest='live_from_start',
  389. help='Download livestreams from the current time (default)')
  390. general.add_option(
  391. '--wait-for-video',
  392. dest='wait_for_video', metavar='MIN[-MAX]', default=None,
  393. help=(
  394. 'Wait for scheduled streams to become available. '
  395. 'Pass the minimum number of seconds (or range) to wait between retries'))
  396. general.add_option(
  397. '--no-wait-for-video',
  398. dest='wait_for_video', action='store_const', const=None,
  399. help='Do not wait for scheduled streams (default)')
  400. general.add_option(
  401. '--mark-watched',
  402. action='store_true', dest='mark_watched', default=False,
  403. help='Mark videos watched (even with --simulate)')
  404. general.add_option(
  405. '--no-mark-watched',
  406. action='store_false', dest='mark_watched',
  407. help='Do not mark videos watched (default)')
  408. general.add_option(
  409. '--no-colors', '--no-colours',
  410. action='store_const', dest='color', const={
  411. 'stdout': 'no_color',
  412. 'stderr': 'no_color',
  413. },
  414. help=optparse.SUPPRESS_HELP)
  415. general.add_option(
  416. '--color',
  417. dest='color', metavar='[STREAM:]POLICY', default={}, type='str',
  418. action='callback', callback=_dict_from_options_callback,
  419. callback_kwargs={
  420. 'allowed_keys': 'stdout|stderr',
  421. 'default_key': ['stdout', 'stderr'],
  422. 'process': str.strip,
  423. }, help=(
  424. 'Whether to emit color codes in output, optionally prefixed by '
  425. 'the STREAM (stdout or stderr) to apply the setting to. '
  426. 'Can be one of "always", "auto" (default), "never", or '
  427. '"no_color" (use non color terminal sequences). '
  428. 'Use "auto-tty" or "no_color-tty" to decide based on terminal support only. '
  429. 'Can be used multiple times'))
  430. general.add_option(
  431. '--compat-options',
  432. metavar='OPTS', dest='compat_opts', default=set(), type='str',
  433. action='callback', callback=_set_from_options_callback,
  434. callback_kwargs={
  435. 'allowed_values': {
  436. 'filename', 'filename-sanitization', 'format-sort', 'abort-on-error', 'format-spec', 'no-playlist-metafiles',
  437. 'multistreams', 'no-live-chat', 'playlist-index', 'list-formats', 'no-direct-merge', 'playlist-match-filter',
  438. 'no-attach-info-json', 'embed-thumbnail-atomicparsley', 'no-external-downloader-progress',
  439. 'embed-metadata', 'seperate-video-versions', 'no-clean-infojson', 'no-keep-subs', 'no-certifi',
  440. 'no-youtube-channel-redirect', 'no-youtube-unavailable-videos', 'no-youtube-prefer-utc-upload-date',
  441. 'prefer-legacy-http-handler', 'manifest-filesize-approx', 'allow-unsafe-ext',
  442. }, 'aliases': {
  443. 'youtube-dl': ['all', '-multistreams', '-playlist-match-filter', '-manifest-filesize-approx', '-allow-unsafe-ext'],
  444. 'youtube-dlc': ['all', '-no-youtube-channel-redirect', '-no-live-chat', '-playlist-match-filter', '-manifest-filesize-approx', '-allow-unsafe-ext'],
  445. '2021': ['2022', 'no-certifi', 'filename-sanitization'],
  446. '2022': ['2023', 'no-external-downloader-progress', 'playlist-match-filter', 'prefer-legacy-http-handler', 'manifest-filesize-approx'],
  447. '2023': [],
  448. },
  449. }, help=(
  450. 'Options that can help keep compatibility with youtube-dl or youtube-dlc '
  451. 'configurations by reverting some of the changes made in yt-dlp. '
  452. 'See "Differences in default behavior" for details'))
  453. general.add_option(
  454. '--alias', metavar='ALIASES OPTIONS', dest='_', type='str', nargs=2,
  455. action='callback', callback=_create_alias,
  456. help=(
  457. 'Create aliases for an option string. Unless an alias starts with a dash "-", it is prefixed with "--". '
  458. 'Arguments are parsed according to the Python string formatting mini-language. '
  459. 'E.g. --alias get-audio,-X "-S=aext:{0},abr -x --audio-format {0}" creates options '
  460. '"--get-audio" and "-X" that takes an argument (ARG0) and expands to '
  461. '"-S=aext:ARG0,abr -x --audio-format ARG0". All defined aliases are listed in the --help output. '
  462. 'Alias options can trigger more aliases; so be careful to avoid defining recursive options. '
  463. f'As a safety measure, each alias may be triggered a maximum of {_YoutubeDLOptionParser.ALIAS_TRIGGER_LIMIT} times. '
  464. 'This option can be used multiple times'))
  465. network = optparse.OptionGroup(parser, 'Network Options')
  466. network.add_option(
  467. '--proxy', dest='proxy',
  468. default=None, metavar='URL',
  469. help=(
  470. 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable SOCKS proxy, specify a proper scheme, '
  471. 'e.g. socks5://user:pass@127.0.0.1:1080/. Pass in an empty string (--proxy "") for direct connection'))
  472. network.add_option(
  473. '--socket-timeout',
  474. dest='socket_timeout', type=float, default=None, metavar='SECONDS',
  475. help='Time to wait before giving up, in seconds')
  476. network.add_option(
  477. '--source-address',
  478. metavar='IP', dest='source_address', default=None,
  479. help='Client-side IP address to bind to',
  480. )
  481. network.add_option(
  482. '--impersonate',
  483. metavar='CLIENT[:OS]', dest='impersonate', default=None,
  484. help=(
  485. 'Client to impersonate for requests. E.g. chrome, chrome-110, chrome:windows-10. '
  486. 'Pass --impersonate="" to impersonate any client. Note that forcing impersonation '
  487. 'for all requests may have a detrimental impact on download speed and stability'),
  488. )
  489. network.add_option(
  490. '--list-impersonate-targets',
  491. dest='list_impersonate_targets', default=False, action='store_true',
  492. help='List available clients to impersonate.',
  493. )
  494. network.add_option(
  495. '-4', '--force-ipv4',
  496. action='store_const', const='0.0.0.0', dest='source_address',
  497. help='Make all connections via IPv4',
  498. )
  499. network.add_option(
  500. '-6', '--force-ipv6',
  501. action='store_const', const='::', dest='source_address',
  502. help='Make all connections via IPv6',
  503. )
  504. network.add_option(
  505. '--enable-file-urls', action='store_true',
  506. dest='enable_file_urls', default=False,
  507. help='Enable file:// URLs. This is disabled by default for security reasons.',
  508. )
  509. geo = optparse.OptionGroup(parser, 'Geo-restriction')
  510. geo.add_option(
  511. '--geo-verification-proxy',
  512. dest='geo_verification_proxy', default=None, metavar='URL',
  513. help=(
  514. 'Use this proxy to verify the IP address for some geo-restricted sites. '
  515. 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
  516. geo.add_option(
  517. '--cn-verification-proxy',
  518. dest='cn_verification_proxy', default=None, metavar='URL',
  519. help=optparse.SUPPRESS_HELP)
  520. geo.add_option(
  521. '--xff', metavar='VALUE',
  522. dest='geo_bypass', default='default',
  523. help=(
  524. 'How to fake X-Forwarded-For HTTP header to try bypassing geographic restriction. '
  525. 'One of "default" (only when known to be useful), "never", '
  526. 'an IP block in CIDR notation, or a two-letter ISO 3166-2 country code'))
  527. geo.add_option(
  528. '--geo-bypass',
  529. action='store_const', dest='geo_bypass', const='default',
  530. help=optparse.SUPPRESS_HELP)
  531. geo.add_option(
  532. '--no-geo-bypass',
  533. action='store_const', dest='geo_bypass', const='never',
  534. help=optparse.SUPPRESS_HELP)
  535. geo.add_option(
  536. '--geo-bypass-country', metavar='CODE', dest='geo_bypass',
  537. help=optparse.SUPPRESS_HELP)
  538. geo.add_option(
  539. '--geo-bypass-ip-block', metavar='IP_BLOCK', dest='geo_bypass',
  540. help=optparse.SUPPRESS_HELP)
  541. selection = optparse.OptionGroup(parser, 'Video Selection')
  542. selection.add_option(
  543. '--playlist-start',
  544. dest='playliststart', metavar='NUMBER', default=1, type=int,
  545. help=optparse.SUPPRESS_HELP)
  546. selection.add_option(
  547. '--playlist-end',
  548. dest='playlistend', metavar='NUMBER', default=None, type=int,
  549. help=optparse.SUPPRESS_HELP)
  550. selection.add_option(
  551. '-I', '--playlist-items',
  552. dest='playlist_items', metavar='ITEM_SPEC', default=None,
  553. help=(
  554. 'Comma separated playlist_index of the items to download. '
  555. 'You can specify a range using "[START]:[STOP][:STEP]". For backward compatibility, START-STOP is also supported. '
  556. 'Use negative indices to count from the right and negative STEP to download in reverse order. '
  557. 'E.g. "-I 1:3,7,-5::2" used on a playlist of size 15 will download the items at index 1,2,3,7,11,13,15'))
  558. selection.add_option(
  559. '--match-title',
  560. dest='matchtitle', metavar='REGEX',
  561. help=optparse.SUPPRESS_HELP)
  562. selection.add_option(
  563. '--reject-title',
  564. dest='rejecttitle', metavar='REGEX',
  565. help=optparse.SUPPRESS_HELP)
  566. selection.add_option(
  567. '--min-filesize',
  568. metavar='SIZE', dest='min_filesize', default=None,
  569. help='Abort download if filesize is smaller than SIZE, e.g. 50k or 44.6M')
  570. selection.add_option(
  571. '--max-filesize',
  572. metavar='SIZE', dest='max_filesize', default=None,
  573. help='Abort download if filesize is larger than SIZE, e.g. 50k or 44.6M')
  574. selection.add_option(
  575. '--date',
  576. metavar='DATE', dest='date', default=None,
  577. help=(
  578. 'Download only videos uploaded on this date. '
  579. 'The date can be "YYYYMMDD" or in the format [now|today|yesterday][-N[day|week|month|year]]. '
  580. 'E.g. "--date today-2weeks" downloads only videos uploaded on the same day two weeks ago'))
  581. selection.add_option(
  582. '--datebefore',
  583. metavar='DATE', dest='datebefore', default=None,
  584. help=(
  585. 'Download only videos uploaded on or before this date. '
  586. 'The date formats accepted is the same as --date'))
  587. selection.add_option(
  588. '--dateafter',
  589. metavar='DATE', dest='dateafter', default=None,
  590. help=(
  591. 'Download only videos uploaded on or after this date. '
  592. 'The date formats accepted is the same as --date'))
  593. selection.add_option(
  594. '--min-views',
  595. metavar='COUNT', dest='min_views', default=None, type=int,
  596. help=optparse.SUPPRESS_HELP)
  597. selection.add_option(
  598. '--max-views',
  599. metavar='COUNT', dest='max_views', default=None, type=int,
  600. help=optparse.SUPPRESS_HELP)
  601. selection.add_option(
  602. '--match-filters',
  603. metavar='FILTER', dest='match_filter', action='append',
  604. help=(
  605. 'Generic video filter. Any "OUTPUT TEMPLATE" field can be compared with a '
  606. 'number or a string using the operators defined in "Filtering Formats". '
  607. 'You can also simply specify a field to match if the field is present, '
  608. 'use "!field" to check if the field is not present, and "&" to check multiple conditions. '
  609. 'Use a "\\" to escape "&" or quotes if needed. If used multiple times, '
  610. 'the filter matches if at least one of the conditions is met. E.g. --match-filters '
  611. '!is_live --match-filters "like_count>?100 & description~=\'(?i)\\bcats \\& dogs\\b\'" '
  612. 'matches only videos that are not live OR those that have a like count more than 100 '
  613. '(or the like field is not available) and also has a description '
  614. 'that contains the phrase "cats & dogs" (caseless). '
  615. 'Use "--match-filters -" to interactively ask whether to download each video'))
  616. selection.add_option(
  617. '--no-match-filters',
  618. dest='match_filter', action='store_const', const=None,
  619. help='Do not use any --match-filters (default)')
  620. selection.add_option(
  621. '--break-match-filters',
  622. metavar='FILTER', dest='breaking_match_filter', action='append',
  623. help='Same as "--match-filters" but stops the download process when a video is rejected')
  624. selection.add_option(
  625. '--no-break-match-filters',
  626. dest='breaking_match_filter', action='store_const', const=None,
  627. help='Do not use any --break-match-filters (default)')
  628. selection.add_option(
  629. '--no-playlist',
  630. action='store_true', dest='noplaylist', default=False,
  631. help='Download only the video, if the URL refers to a video and a playlist')
  632. selection.add_option(
  633. '--yes-playlist',
  634. action='store_false', dest='noplaylist',
  635. help='Download the playlist, if the URL refers to a video and a playlist')
  636. selection.add_option(
  637. '--age-limit',
  638. metavar='YEARS', dest='age_limit', default=None, type=int,
  639. help='Download only videos suitable for the given age')
  640. selection.add_option(
  641. '--download-archive', metavar='FILE',
  642. dest='download_archive',
  643. help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
  644. selection.add_option(
  645. '--no-download-archive',
  646. dest='download_archive', action='store_const', const=None,
  647. help='Do not use archive file (default)')
  648. selection.add_option(
  649. '--max-downloads',
  650. dest='max_downloads', metavar='NUMBER', type=int, default=None,
  651. help='Abort after downloading NUMBER files')
  652. selection.add_option(
  653. '--break-on-existing',
  654. action='store_true', dest='break_on_existing', default=False,
  655. help='Stop the download process when encountering a file that is in the archive')
  656. selection.add_option(
  657. '--no-break-on-existing',
  658. action='store_false', dest='break_on_existing',
  659. help='Do not stop the download process when encountering a file that is in the archive (default)')
  660. selection.add_option(
  661. '--break-on-reject',
  662. action='store_true', dest='break_on_reject', default=False,
  663. help=optparse.SUPPRESS_HELP)
  664. selection.add_option(
  665. '--break-per-input',
  666. action='store_true', dest='break_per_url', default=False,
  667. help='Alters --max-downloads, --break-on-existing, --break-match-filters, and autonumber to reset per input URL')
  668. selection.add_option(
  669. '--no-break-per-input',
  670. action='store_false', dest='break_per_url',
  671. help='--break-on-existing and similar options terminates the entire download queue')
  672. selection.add_option(
  673. '--skip-playlist-after-errors', metavar='N',
  674. dest='skip_playlist_after_errors', default=None, type=int,
  675. help='Number of allowed failures until the rest of the playlist is skipped')
  676. selection.add_option(
  677. '--include-ads',
  678. dest='include_ads', action='store_true',
  679. help=optparse.SUPPRESS_HELP)
  680. selection.add_option(
  681. '--no-include-ads',
  682. dest='include_ads', action='store_false',
  683. help=optparse.SUPPRESS_HELP)
  684. authentication = optparse.OptionGroup(parser, 'Authentication Options')
  685. authentication.add_option(
  686. '-u', '--username',
  687. dest='username', metavar='USERNAME',
  688. help='Login with this account ID')
  689. authentication.add_option(
  690. '-p', '--password',
  691. dest='password', metavar='PASSWORD',
  692. help='Account password. If this option is left out, yt-dlp will ask interactively')
  693. authentication.add_option(
  694. '-2', '--twofactor',
  695. dest='twofactor', metavar='TWOFACTOR',
  696. help='Two-factor authentication code')
  697. authentication.add_option(
  698. '-n', '--netrc',
  699. action='store_true', dest='usenetrc', default=False,
  700. help='Use .netrc authentication data')
  701. authentication.add_option(
  702. '--netrc-location',
  703. dest='netrc_location', metavar='PATH',
  704. help='Location of .netrc authentication data; either the path or its containing directory. Defaults to ~/.netrc')
  705. authentication.add_option(
  706. '--netrc-cmd',
  707. dest='netrc_cmd', metavar='NETRC_CMD',
  708. help='Command to execute to get the credentials for an extractor.')
  709. authentication.add_option(
  710. '--video-password',
  711. dest='videopassword', metavar='PASSWORD',
  712. help='Video-specific password')
  713. authentication.add_option(
  714. '--ap-mso',
  715. dest='ap_mso', metavar='MSO',
  716. help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
  717. authentication.add_option(
  718. '--ap-username',
  719. dest='ap_username', metavar='USERNAME',
  720. help='Multiple-system operator account login')
  721. authentication.add_option(
  722. '--ap-password',
  723. dest='ap_password', metavar='PASSWORD',
  724. help='Multiple-system operator account password. If this option is left out, yt-dlp will ask interactively')
  725. authentication.add_option(
  726. '--ap-list-mso',
  727. action='store_true', dest='ap_list_mso', default=False,
  728. help='List all supported multiple-system operators')
  729. authentication.add_option(
  730. '--client-certificate',
  731. dest='client_certificate', metavar='CERTFILE',
  732. help='Path to client certificate file in PEM format. May include the private key')
  733. authentication.add_option(
  734. '--client-certificate-key',
  735. dest='client_certificate_key', metavar='KEYFILE',
  736. help='Path to private key file for client certificate')
  737. authentication.add_option(
  738. '--client-certificate-password',
  739. dest='client_certificate_password', metavar='PASSWORD',
  740. help='Password for client certificate private key, if encrypted. '
  741. 'If not provided, and the key is encrypted, yt-dlp will ask interactively')
  742. video_format = optparse.OptionGroup(parser, 'Video Format Options')
  743. video_format.add_option(
  744. '-f', '--format',
  745. action='store', dest='format', metavar='FORMAT', default=None,
  746. help='Video format code, see "FORMAT SELECTION" for more details')
  747. video_format.add_option(
  748. '-S', '--format-sort', metavar='SORTORDER',
  749. dest='format_sort', default=[], type='str', action='callback',
  750. callback=_list_from_options_callback, callback_kwargs={'append': -1},
  751. help='Sort the formats by the fields given, see "Sorting Formats" for more details')
  752. video_format.add_option(
  753. '--format-sort-force', '--S-force',
  754. action='store_true', dest='format_sort_force', metavar='FORMAT', default=False,
  755. help=(
  756. 'Force user specified sort order to have precedence over all fields, '
  757. 'see "Sorting Formats" for more details (Alias: --S-force)'))
  758. video_format.add_option(
  759. '--no-format-sort-force',
  760. action='store_false', dest='format_sort_force', metavar='FORMAT', default=False,
  761. help='Some fields have precedence over the user specified sort order (default)')
  762. video_format.add_option(
  763. '--video-multistreams',
  764. action='store_true', dest='allow_multiple_video_streams', default=None,
  765. help='Allow multiple video streams to be merged into a single file')
  766. video_format.add_option(
  767. '--no-video-multistreams',
  768. action='store_false', dest='allow_multiple_video_streams',
  769. help='Only one video stream is downloaded for each output file (default)')
  770. video_format.add_option(
  771. '--audio-multistreams',
  772. action='store_true', dest='allow_multiple_audio_streams', default=None,
  773. help='Allow multiple audio streams to be merged into a single file')
  774. video_format.add_option(
  775. '--no-audio-multistreams',
  776. action='store_false', dest='allow_multiple_audio_streams',
  777. help='Only one audio stream is downloaded for each output file (default)')
  778. video_format.add_option(
  779. '--all-formats',
  780. action='store_const', dest='format', const='all',
  781. help=optparse.SUPPRESS_HELP)
  782. video_format.add_option(
  783. '--prefer-free-formats',
  784. action='store_true', dest='prefer_free_formats', default=False,
  785. help=(
  786. 'Prefer video formats with free containers over non-free ones of same quality. '
  787. 'Use with "-S ext" to strictly prefer free containers irrespective of quality'))
  788. video_format.add_option(
  789. '--no-prefer-free-formats',
  790. action='store_false', dest='prefer_free_formats', default=False,
  791. help="Don't give any special preference to free containers (default)")
  792. video_format.add_option(
  793. '--check-formats',
  794. action='store_const', const='selected', dest='check_formats', default=None,
  795. help='Make sure formats are selected only from those that are actually downloadable')
  796. video_format.add_option(
  797. '--check-all-formats',
  798. action='store_true', dest='check_formats',
  799. help='Check all formats for whether they are actually downloadable')
  800. video_format.add_option(
  801. '--no-check-formats',
  802. action='store_false', dest='check_formats',
  803. help='Do not check that the formats are actually downloadable')
  804. video_format.add_option(
  805. '-F', '--list-formats',
  806. action='store_true', dest='listformats',
  807. help='List available formats of each video. Simulate unless --no-simulate is used')
  808. video_format.add_option(
  809. '--list-formats-as-table',
  810. action='store_true', dest='listformats_table', default=True,
  811. help=optparse.SUPPRESS_HELP)
  812. video_format.add_option(
  813. '--list-formats-old', '--no-list-formats-as-table',
  814. action='store_false', dest='listformats_table',
  815. help=optparse.SUPPRESS_HELP)
  816. video_format.add_option(
  817. '--merge-output-format',
  818. action='store', dest='merge_output_format', metavar='FORMAT', default=None,
  819. help=(
  820. 'Containers that may be used when merging formats, separated by "/", e.g. "mp4/mkv". '
  821. 'Ignored if no merge is required. '
  822. f'(currently supported: {", ".join(sorted(FFmpegMergerPP.SUPPORTED_EXTS))})'))
  823. video_format.add_option(
  824. '--allow-unplayable-formats',
  825. action='store_true', dest='allow_unplayable_formats', default=False,
  826. help=optparse.SUPPRESS_HELP)
  827. video_format.add_option(
  828. '--no-allow-unplayable-formats',
  829. action='store_false', dest='allow_unplayable_formats',
  830. help=optparse.SUPPRESS_HELP)
  831. subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
  832. subtitles.add_option(
  833. '--write-subs', '--write-srt',
  834. action='store_true', dest='writesubtitles', default=False,
  835. help='Write subtitle file')
  836. subtitles.add_option(
  837. '--no-write-subs', '--no-write-srt',
  838. action='store_false', dest='writesubtitles',
  839. help='Do not write subtitle file (default)')
  840. subtitles.add_option(
  841. '--write-auto-subs', '--write-automatic-subs',
  842. action='store_true', dest='writeautomaticsub', default=False,
  843. help='Write automatically generated subtitle file (Alias: --write-automatic-subs)')
  844. subtitles.add_option(
  845. '--no-write-auto-subs', '--no-write-automatic-subs',
  846. action='store_false', dest='writeautomaticsub', default=False,
  847. help='Do not write auto-generated subtitles (default) (Alias: --no-write-automatic-subs)')
  848. subtitles.add_option(
  849. '--all-subs',
  850. action='store_true', dest='allsubtitles', default=False,
  851. help=optparse.SUPPRESS_HELP)
  852. subtitles.add_option(
  853. '--list-subs',
  854. action='store_true', dest='listsubtitles', default=False,
  855. help='List available subtitles of each video. Simulate unless --no-simulate is used')
  856. subtitles.add_option(
  857. '--sub-format',
  858. action='store', dest='subtitlesformat', metavar='FORMAT', default='best',
  859. help='Subtitle format; accepts formats preference, e.g. "srt" or "ass/srt/best"')
  860. subtitles.add_option(
  861. '--sub-langs', '--srt-langs',
  862. action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
  863. default=[], callback=_list_from_options_callback,
  864. help=(
  865. 'Languages of the subtitles to download (can be regex) or "all" separated by commas, e.g. --sub-langs "en.*,ja". '
  866. 'You can prefix the language code with a "-" to exclude it from the requested languages, e.g. --sub-langs all,-live_chat. '
  867. 'Use --list-subs for a list of available language tags'))
  868. downloader = optparse.OptionGroup(parser, 'Download Options')
  869. downloader.add_option(
  870. '-N', '--concurrent-fragments',
  871. dest='concurrent_fragment_downloads', metavar='N', default=1, type=int,
  872. help='Number of fragments of a dash/hlsnative video that should be downloaded concurrently (default is %default)')
  873. downloader.add_option(
  874. '-r', '--limit-rate', '--rate-limit',
  875. dest='ratelimit', metavar='RATE',
  876. help='Maximum download rate in bytes per second, e.g. 50K or 4.2M')
  877. downloader.add_option(
  878. '--throttled-rate',
  879. dest='throttledratelimit', metavar='RATE',
  880. help='Minimum download rate in bytes per second below which throttling is assumed and the video data is re-extracted, e.g. 100K')
  881. downloader.add_option(
  882. '-R', '--retries',
  883. dest='retries', metavar='RETRIES', default=10,
  884. help='Number of retries (default is %default), or "infinite"')
  885. downloader.add_option(
  886. '--file-access-retries',
  887. dest='file_access_retries', metavar='RETRIES', default=3,
  888. help='Number of times to retry on file access error (default is %default), or "infinite"')
  889. downloader.add_option(
  890. '--fragment-retries',
  891. dest='fragment_retries', metavar='RETRIES', default=10,
  892. help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
  893. downloader.add_option(
  894. '--retry-sleep',
  895. dest='retry_sleep', metavar='[TYPE:]EXPR', default={}, type='str',
  896. action='callback', callback=_dict_from_options_callback,
  897. callback_kwargs={
  898. 'allowed_keys': 'http|fragment|file_access|extractor',
  899. 'default_key': 'http',
  900. }, help=(
  901. 'Time to sleep between retries in seconds (optionally) prefixed by the type of retry '
  902. '(http (default), fragment, file_access, extractor) to apply the sleep to. '
  903. 'EXPR can be a number, linear=START[:END[:STEP=1]] or exp=START[:END[:BASE=2]]. '
  904. 'This option can be used multiple times to set the sleep for the different retry types, '
  905. 'e.g. --retry-sleep linear=1::2 --retry-sleep fragment:exp=1:20'))
  906. downloader.add_option(
  907. '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragments',
  908. action='store_true', dest='skip_unavailable_fragments', default=True,
  909. help='Skip unavailable fragments for DASH, hlsnative and ISM downloads (default) (Alias: --no-abort-on-unavailable-fragments)')
  910. downloader.add_option(
  911. '--abort-on-unavailable-fragments', '--no-skip-unavailable-fragments',
  912. action='store_false', dest='skip_unavailable_fragments',
  913. help='Abort download if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
  914. downloader.add_option(
  915. '--keep-fragments',
  916. action='store_true', dest='keep_fragments', default=False,
  917. help='Keep downloaded fragments on disk after downloading is finished')
  918. downloader.add_option(
  919. '--no-keep-fragments',
  920. action='store_false', dest='keep_fragments',
  921. help='Delete downloaded fragments after downloading is finished (default)')
  922. downloader.add_option(
  923. '--buffer-size',
  924. dest='buffersize', metavar='SIZE', default='1024',
  925. help='Size of download buffer, e.g. 1024 or 16K (default is %default)')
  926. downloader.add_option(
  927. '--resize-buffer',
  928. action='store_false', dest='noresizebuffer',
  929. help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
  930. downloader.add_option(
  931. '--no-resize-buffer',
  932. action='store_true', dest='noresizebuffer', default=False,
  933. help='Do not automatically adjust the buffer size')
  934. downloader.add_option(
  935. '--http-chunk-size',
  936. dest='http_chunk_size', metavar='SIZE', default=None,
  937. help=(
  938. 'Size of a chunk for chunk-based HTTP downloading, e.g. 10485760 or 10M (default is disabled). '
  939. 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
  940. downloader.add_option(
  941. '--test',
  942. action='store_true', dest='test', default=False,
  943. help=optparse.SUPPRESS_HELP)
  944. downloader.add_option(
  945. '--playlist-reverse',
  946. action='store_true', dest='playlist_reverse',
  947. help=optparse.SUPPRESS_HELP)
  948. downloader.add_option(
  949. '--no-playlist-reverse',
  950. action='store_false', dest='playlist_reverse',
  951. help=optparse.SUPPRESS_HELP)
  952. downloader.add_option(
  953. '--playlist-random',
  954. action='store_true', dest='playlist_random',
  955. help='Download playlist videos in random order')
  956. downloader.add_option(
  957. '--lazy-playlist',
  958. action='store_true', dest='lazy_playlist',
  959. help='Process entries in the playlist as they are received. This disables n_entries, --playlist-random and --playlist-reverse')
  960. downloader.add_option(
  961. '--no-lazy-playlist',
  962. action='store_false', dest='lazy_playlist',
  963. help='Process videos in the playlist only after the entire playlist is parsed (default)')
  964. downloader.add_option(
  965. '--xattr-set-filesize',
  966. dest='xattr_set_filesize', action='store_true',
  967. help='Set file xattribute ytdl.filesize with expected file size')
  968. downloader.add_option(
  969. '--hls-prefer-native',
  970. dest='hls_prefer_native', action='store_true', default=None,
  971. help=optparse.SUPPRESS_HELP)
  972. downloader.add_option(
  973. '--hls-prefer-ffmpeg',
  974. dest='hls_prefer_native', action='store_false', default=None,
  975. help=optparse.SUPPRESS_HELP)
  976. downloader.add_option(
  977. '--hls-use-mpegts',
  978. dest='hls_use_mpegts', action='store_true', default=None,
  979. help=(
  980. 'Use the mpegts container for HLS videos; '
  981. 'allowing some players to play the video while downloading, '
  982. 'and reducing the chance of file corruption if download is interrupted. '
  983. 'This is enabled by default for live streams'))
  984. downloader.add_option(
  985. '--no-hls-use-mpegts',
  986. dest='hls_use_mpegts', action='store_false',
  987. help=(
  988. 'Do not use the mpegts container for HLS videos. '
  989. 'This is default when not downloading live streams'))
  990. downloader.add_option(
  991. '--download-sections',
  992. metavar='REGEX', dest='download_ranges', action='append',
  993. help=(
  994. 'Download only chapters that match the regular expression. '
  995. 'A "*" prefix denotes time-range instead of chapter. Negative timestamps are calculated from the end. '
  996. '"*from-url" can be used to download between the "start_time" and "end_time" extracted from the URL. '
  997. 'Needs ffmpeg. This option can be used multiple times to download multiple sections, '
  998. 'e.g. --download-sections "*10:15-inf" --download-sections "intro"'))
  999. downloader.add_option(
  1000. '--downloader', '--external-downloader',
  1001. dest='external_downloader', metavar='[PROTO:]NAME', default={}, type='str',
  1002. action='callback', callback=_dict_from_options_callback,
  1003. callback_kwargs={
  1004. 'allowed_keys': 'http|ftp|m3u8|dash|rtsp|rtmp|mms',
  1005. 'default_key': 'default',
  1006. 'process': str.strip,
  1007. }, help=(
  1008. 'Name or path of the external downloader to use (optionally) prefixed by '
  1009. 'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. '
  1010. f'Currently supports native, {", ".join(sorted(list_external_downloaders()))}. '
  1011. 'You can use this option multiple times to set different downloaders for different protocols. '
  1012. 'E.g. --downloader aria2c --downloader "dash,m3u8:native" will use '
  1013. 'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads '
  1014. '(Alias: --external-downloader)'))
  1015. downloader.add_option(
  1016. '--downloader-args', '--external-downloader-args',
  1017. metavar='NAME:ARGS', dest='external_downloader_args', default={}, type='str',
  1018. action='callback', callback=_dict_from_options_callback,
  1019. callback_kwargs={
  1020. 'allowed_keys': r'ffmpeg_[io]\d*|{}'.format('|'.join(map(re.escape, list_external_downloaders()))),
  1021. 'default_key': 'default',
  1022. 'process': shlex.split,
  1023. }, help=(
  1024. 'Give these arguments to the external downloader. '
  1025. 'Specify the downloader name and the arguments separated by a colon ":". '
  1026. 'For ffmpeg, arguments can be passed to different positions using the same syntax as --postprocessor-args. '
  1027. 'You can use this option multiple times to give different arguments to different downloaders '
  1028. '(Alias: --external-downloader-args)'))
  1029. workarounds = optparse.OptionGroup(parser, 'Workarounds')
  1030. workarounds.add_option(
  1031. '--encoding',
  1032. dest='encoding', metavar='ENCODING',
  1033. help='Force the specified encoding (experimental)')
  1034. workarounds.add_option(
  1035. '--legacy-server-connect',
  1036. action='store_true', dest='legacy_server_connect', default=False,
  1037. help='Explicitly allow HTTPS connection to servers that do not support RFC 5746 secure renegotiation')
  1038. workarounds.add_option(
  1039. '--no-check-certificates',
  1040. action='store_true', dest='no_check_certificate', default=False,
  1041. help='Suppress HTTPS certificate validation')
  1042. workarounds.add_option(
  1043. '--prefer-insecure', '--prefer-unsecure',
  1044. action='store_true', dest='prefer_insecure',
  1045. help='Use an unencrypted connection to retrieve information about the video (Currently supported only for YouTube)')
  1046. workarounds.add_option(
  1047. '--user-agent',
  1048. metavar='UA', dest='user_agent',
  1049. help=optparse.SUPPRESS_HELP)
  1050. workarounds.add_option(
  1051. '--referer',
  1052. metavar='URL', dest='referer', default=None,
  1053. help=optparse.SUPPRESS_HELP)
  1054. workarounds.add_option(
  1055. '--add-headers',
  1056. metavar='FIELD:VALUE', dest='headers', default={}, type='str',
  1057. action='callback', callback=_dict_from_options_callback,
  1058. callback_kwargs={'multiple_keys': False},
  1059. help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
  1060. )
  1061. workarounds.add_option(
  1062. '--bidi-workaround',
  1063. dest='bidi_workaround', action='store_true',
  1064. help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
  1065. workarounds.add_option(
  1066. '--sleep-requests', metavar='SECONDS',
  1067. dest='sleep_interval_requests', type=float,
  1068. help='Number of seconds to sleep between requests during data extraction')
  1069. workarounds.add_option(
  1070. '--sleep-interval', '--min-sleep-interval', metavar='SECONDS',
  1071. dest='sleep_interval', type=float,
  1072. help=(
  1073. 'Number of seconds to sleep before each download. '
  1074. 'This is the minimum time to sleep when used along with --max-sleep-interval '
  1075. '(Alias: --min-sleep-interval)'))
  1076. workarounds.add_option(
  1077. '--max-sleep-interval', metavar='SECONDS',
  1078. dest='max_sleep_interval', type=float,
  1079. help='Maximum number of seconds to sleep. Can only be used along with --min-sleep-interval')
  1080. workarounds.add_option(
  1081. '--sleep-subtitles', metavar='SECONDS',
  1082. dest='sleep_interval_subtitles', default=0, type=int,
  1083. help='Number of seconds to sleep before each subtitle download')
  1084. verbosity = optparse.OptionGroup(parser, 'Verbosity and Simulation Options')
  1085. verbosity.add_option(
  1086. '-q', '--quiet',
  1087. action='store_true', dest='quiet', default=None,
  1088. help='Activate quiet mode. If used with --verbose, print the log to stderr')
  1089. verbosity.add_option(
  1090. '--no-quiet',
  1091. action='store_false', dest='quiet',
  1092. help='Deactivate quiet mode. (Default)')
  1093. verbosity.add_option(
  1094. '--no-warnings',
  1095. dest='no_warnings', action='store_true', default=False,
  1096. help='Ignore warnings')
  1097. verbosity.add_option(
  1098. '-s', '--simulate',
  1099. action='store_true', dest='simulate', default=None,
  1100. help='Do not download the video and do not write anything to disk')
  1101. verbosity.add_option(
  1102. '--no-simulate',
  1103. action='store_false', dest='simulate',
  1104. help='Download the video even if printing/listing options are used')
  1105. verbosity.add_option(
  1106. '--ignore-no-formats-error',
  1107. action='store_true', dest='ignore_no_formats_error', default=False,
  1108. help=(
  1109. 'Ignore "No video formats" error. Useful for extracting metadata '
  1110. 'even if the videos are not actually available for download (experimental)'))
  1111. verbosity.add_option(
  1112. '--no-ignore-no-formats-error',
  1113. action='store_false', dest='ignore_no_formats_error',
  1114. help='Throw error when no downloadable video formats are found (default)')
  1115. verbosity.add_option(
  1116. '--skip-download', '--no-download',
  1117. action='store_true', dest='skip_download', default=False,
  1118. help='Do not download the video but write all related files (Alias: --no-download)')
  1119. verbosity.add_option(
  1120. '-O', '--print',
  1121. metavar='[WHEN:]TEMPLATE', dest='forceprint', **when_prefix('video'),
  1122. help=(
  1123. 'Field name or output template to print to screen, optionally prefixed with when to print it, separated by a ":". '
  1124. 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: video). '
  1125. 'Implies --quiet. Implies --simulate unless --no-simulate or later stages of WHEN are used. '
  1126. 'This option can be used multiple times'))
  1127. verbosity.add_option(
  1128. '--print-to-file',
  1129. metavar='[WHEN:]TEMPLATE FILE', dest='print_to_file', nargs=2, **when_prefix('video'),
  1130. help=(
  1131. 'Append given template to the file. The values of WHEN and TEMPLATE are same as that of --print. '
  1132. 'FILE uses the same syntax as the output template. This option can be used multiple times'))
  1133. verbosity.add_option(
  1134. '-g', '--get-url',
  1135. action='store_true', dest='geturl', default=False,
  1136. help=optparse.SUPPRESS_HELP)
  1137. verbosity.add_option(
  1138. '-e', '--get-title',
  1139. action='store_true', dest='gettitle', default=False,
  1140. help=optparse.SUPPRESS_HELP)
  1141. verbosity.add_option(
  1142. '--get-id',
  1143. action='store_true', dest='getid', default=False,
  1144. help=optparse.SUPPRESS_HELP)
  1145. verbosity.add_option(
  1146. '--get-thumbnail',
  1147. action='store_true', dest='getthumbnail', default=False,
  1148. help=optparse.SUPPRESS_HELP)
  1149. verbosity.add_option(
  1150. '--get-description',
  1151. action='store_true', dest='getdescription', default=False,
  1152. help=optparse.SUPPRESS_HELP)
  1153. verbosity.add_option(
  1154. '--get-duration',
  1155. action='store_true', dest='getduration', default=False,
  1156. help=optparse.SUPPRESS_HELP)
  1157. verbosity.add_option(
  1158. '--get-filename',
  1159. action='store_true', dest='getfilename', default=False,
  1160. help=optparse.SUPPRESS_HELP)
  1161. verbosity.add_option(
  1162. '--get-format',
  1163. action='store_true', dest='getformat', default=False,
  1164. help=optparse.SUPPRESS_HELP)
  1165. verbosity.add_option(
  1166. '-j', '--dump-json',
  1167. action='store_true', dest='dumpjson', default=False,
  1168. help=(
  1169. 'Quiet, but print JSON information for each video. Simulate unless --no-simulate is used. '
  1170. 'See "OUTPUT TEMPLATE" for a description of available keys'))
  1171. verbosity.add_option(
  1172. '-J', '--dump-single-json',
  1173. action='store_true', dest='dump_single_json', default=False,
  1174. help=(
  1175. 'Quiet, but print JSON information for each url or infojson passed. Simulate unless --no-simulate is used. '
  1176. 'If the URL refers to a playlist, the whole playlist information is dumped in a single line'))
  1177. verbosity.add_option(
  1178. '--print-json',
  1179. action='store_true', dest='print_json', default=False,
  1180. help=optparse.SUPPRESS_HELP)
  1181. verbosity.add_option(
  1182. '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
  1183. action='store_true', dest='force_write_download_archive', default=False,
  1184. help=(
  1185. 'Force download archive entries to be written as far as no errors occur, '
  1186. 'even if -s or another simulation option is used (Alias: --force-download-archive)'))
  1187. verbosity.add_option(
  1188. '--newline',
  1189. action='store_true', dest='progress_with_newline', default=False,
  1190. help='Output progress bar as new lines')
  1191. verbosity.add_option(
  1192. '--no-progress',
  1193. action='store_true', dest='noprogress', default=None,
  1194. help='Do not print progress bar')
  1195. verbosity.add_option(
  1196. '--progress',
  1197. action='store_false', dest='noprogress',
  1198. help='Show progress bar, even if in quiet mode')
  1199. verbosity.add_option(
  1200. '--console-title',
  1201. action='store_true', dest='consoletitle', default=False,
  1202. help='Display progress in console titlebar')
  1203. verbosity.add_option(
  1204. '--progress-template',
  1205. metavar='[TYPES:]TEMPLATE', dest='progress_template', default={}, type='str',
  1206. action='callback', callback=_dict_from_options_callback,
  1207. callback_kwargs={
  1208. 'allowed_keys': '(download|postprocess)(-title)?',
  1209. 'default_key': 'download',
  1210. }, help=(
  1211. 'Template for progress outputs, optionally prefixed with one of "download:" (default), '
  1212. '"download-title:" (the console title), "postprocess:", or "postprocess-title:". '
  1213. 'The video\'s fields are accessible under the "info" key and '
  1214. 'the progress attributes are accessible under "progress" key. E.g. '
  1215. # TODO: Document the fields inside "progress"
  1216. '--console-title --progress-template "download-title:%(info.id)s-%(progress.eta)s"'))
  1217. verbosity.add_option(
  1218. '--progress-delta',
  1219. metavar='SECONDS', action='store', dest='progress_delta', type=float, default=0,
  1220. help='Time between progress output (default: 0)')
  1221. verbosity.add_option(
  1222. '-v', '--verbose',
  1223. action='store_true', dest='verbose', default=False,
  1224. help='Print various debugging information')
  1225. verbosity.add_option(
  1226. '--dump-pages', '--dump-intermediate-pages',
  1227. action='store_true', dest='dump_intermediate_pages', default=False,
  1228. help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
  1229. verbosity.add_option(
  1230. '--write-pages',
  1231. action='store_true', dest='write_pages', default=False,
  1232. help='Write downloaded intermediary pages to files in the current directory to debug problems')
  1233. verbosity.add_option(
  1234. '--load-pages',
  1235. action='store_true', dest='load_pages', default=False,
  1236. help=optparse.SUPPRESS_HELP)
  1237. verbosity.add_option(
  1238. '--youtube-print-sig-code',
  1239. action='store_true', dest='youtube_print_sig_code', default=False,
  1240. help=optparse.SUPPRESS_HELP)
  1241. verbosity.add_option(
  1242. '--print-traffic', '--dump-headers',
  1243. dest='debug_printtraffic', action='store_true', default=False,
  1244. help='Display sent and read HTTP traffic')
  1245. verbosity.add_option(
  1246. '-C', '--call-home',
  1247. dest='call_home', action='store_true', default=False,
  1248. # help='Contact the yt-dlp server for debugging')
  1249. help=optparse.SUPPRESS_HELP)
  1250. verbosity.add_option(
  1251. '--no-call-home',
  1252. dest='call_home', action='store_false',
  1253. # help='Do not contact the yt-dlp server for debugging (default)')
  1254. help=optparse.SUPPRESS_HELP)
  1255. filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
  1256. filesystem.add_option(
  1257. '-a', '--batch-file',
  1258. dest='batchfile', metavar='FILE',
  1259. help=(
  1260. 'File containing URLs to download ("-" for stdin), one URL per line. '
  1261. 'Lines starting with "#", ";" or "]" are considered as comments and ignored'))
  1262. filesystem.add_option(
  1263. '--no-batch-file',
  1264. dest='batchfile', action='store_const', const=None,
  1265. help='Do not read URLs from batch file (default)')
  1266. filesystem.add_option(
  1267. '--id', default=False,
  1268. action='store_true', dest='useid', help=optparse.SUPPRESS_HELP)
  1269. filesystem.add_option(
  1270. '-P', '--paths',
  1271. metavar='[TYPES:]PATH', dest='paths', default={}, type='str',
  1272. action='callback', callback=_dict_from_options_callback,
  1273. callback_kwargs={
  1274. 'allowed_keys': 'home|temp|{}'.format('|'.join(map(re.escape, OUTTMPL_TYPES.keys()))),
  1275. 'default_key': 'home',
  1276. }, help=(
  1277. 'The paths where the files should be downloaded. '
  1278. 'Specify the type of file and the path separated by a colon ":". '
  1279. 'All the same TYPES as --output are supported. '
  1280. 'Additionally, you can also provide "home" (default) and "temp" paths. '
  1281. 'All intermediary files are first downloaded to the temp path and '
  1282. 'then the final files are moved over to the home path after download is finished. '
  1283. 'This option is ignored if --output is an absolute path'))
  1284. filesystem.add_option(
  1285. '-o', '--output',
  1286. metavar='[TYPES:]TEMPLATE', dest='outtmpl', default={}, type='str',
  1287. action='callback', callback=_dict_from_options_callback,
  1288. callback_kwargs={
  1289. 'allowed_keys': '|'.join(map(re.escape, OUTTMPL_TYPES.keys())),
  1290. 'default_key': 'default',
  1291. }, help='Output filename template; see "OUTPUT TEMPLATE" for details')
  1292. filesystem.add_option(
  1293. '--output-na-placeholder',
  1294. dest='outtmpl_na_placeholder', metavar='TEXT', default='NA',
  1295. help=('Placeholder for unavailable fields in --output (default: "%default")'))
  1296. filesystem.add_option(
  1297. '--autonumber-size',
  1298. dest='autonumber_size', metavar='NUMBER', type=int,
  1299. help=optparse.SUPPRESS_HELP)
  1300. filesystem.add_option(
  1301. '--autonumber-start',
  1302. dest='autonumber_start', metavar='NUMBER', default=1, type=int,
  1303. help=optparse.SUPPRESS_HELP)
  1304. filesystem.add_option(
  1305. '--restrict-filenames',
  1306. action='store_true', dest='restrictfilenames', default=False,
  1307. help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
  1308. filesystem.add_option(
  1309. '--no-restrict-filenames',
  1310. action='store_false', dest='restrictfilenames',
  1311. help='Allow Unicode characters, "&" and spaces in filenames (default)')
  1312. filesystem.add_option(
  1313. '--windows-filenames',
  1314. action='store_true', dest='windowsfilenames', default=False,
  1315. help='Force filenames to be Windows-compatible')
  1316. filesystem.add_option(
  1317. '--no-windows-filenames',
  1318. action='store_false', dest='windowsfilenames',
  1319. help='Make filenames Windows-compatible only if using Windows (default)')
  1320. filesystem.add_option(
  1321. '--trim-filenames', '--trim-file-names', metavar='LENGTH',
  1322. dest='trim_file_name', default=0, type=int,
  1323. help='Limit the filename length (excluding extension) to the specified number of characters')
  1324. filesystem.add_option(
  1325. '-w', '--no-overwrites',
  1326. action='store_false', dest='overwrites', default=None,
  1327. help='Do not overwrite any files')
  1328. filesystem.add_option(
  1329. '--force-overwrites', '--yes-overwrites',
  1330. action='store_true', dest='overwrites',
  1331. help='Overwrite all video and metadata files. This option includes --no-continue')
  1332. filesystem.add_option(
  1333. '--no-force-overwrites',
  1334. action='store_const', dest='overwrites', const=None,
  1335. help='Do not overwrite the video, but overwrite related files (default)')
  1336. filesystem.add_option(
  1337. '-c', '--continue',
  1338. action='store_true', dest='continue_dl', default=True,
  1339. help='Resume partially downloaded files/fragments (default)')
  1340. filesystem.add_option(
  1341. '--no-continue',
  1342. action='store_false', dest='continue_dl',
  1343. help=(
  1344. 'Do not resume partially downloaded fragments. '
  1345. 'If the file is not fragmented, restart download of the entire file'))
  1346. filesystem.add_option(
  1347. '--part',
  1348. action='store_false', dest='nopart', default=False,
  1349. help='Use .part files instead of writing directly into output file (default)')
  1350. filesystem.add_option(
  1351. '--no-part',
  1352. action='store_true', dest='nopart',
  1353. help='Do not use .part files - write directly into output file')
  1354. filesystem.add_option(
  1355. '--mtime',
  1356. action='store_true', dest='updatetime', default=True,
  1357. help='Use the Last-modified header to set the file modification time (default)')
  1358. filesystem.add_option(
  1359. '--no-mtime',
  1360. action='store_false', dest='updatetime',
  1361. help='Do not use the Last-modified header to set the file modification time')
  1362. filesystem.add_option(
  1363. '--write-description',
  1364. action='store_true', dest='writedescription', default=False,
  1365. help='Write video description to a .description file')
  1366. filesystem.add_option(
  1367. '--no-write-description',
  1368. action='store_false', dest='writedescription',
  1369. help='Do not write video description (default)')
  1370. filesystem.add_option(
  1371. '--write-info-json',
  1372. action='store_true', dest='writeinfojson', default=None,
  1373. help='Write video metadata to a .info.json file (this may contain personal information)')
  1374. filesystem.add_option(
  1375. '--no-write-info-json',
  1376. action='store_false', dest='writeinfojson',
  1377. help='Do not write video metadata (default)')
  1378. filesystem.add_option(
  1379. '--write-annotations',
  1380. action='store_true', dest='writeannotations', default=False,
  1381. help=optparse.SUPPRESS_HELP)
  1382. filesystem.add_option(
  1383. '--no-write-annotations',
  1384. action='store_false', dest='writeannotations',
  1385. help=optparse.SUPPRESS_HELP)
  1386. filesystem.add_option(
  1387. '--write-playlist-metafiles',
  1388. action='store_true', dest='allow_playlist_files', default=None,
  1389. help=(
  1390. 'Write playlist metadata in addition to the video metadata '
  1391. 'when using --write-info-json, --write-description etc. (default)'))
  1392. filesystem.add_option(
  1393. '--no-write-playlist-metafiles',
  1394. action='store_false', dest='allow_playlist_files',
  1395. help='Do not write playlist metadata when using --write-info-json, --write-description etc.')
  1396. filesystem.add_option(
  1397. '--clean-info-json', '--clean-infojson',
  1398. action='store_true', dest='clean_infojson', default=None,
  1399. help=(
  1400. 'Remove some internal metadata such as filenames from the infojson (default)'))
  1401. filesystem.add_option(
  1402. '--no-clean-info-json', '--no-clean-infojson',
  1403. action='store_false', dest='clean_infojson',
  1404. help='Write all fields to the infojson')
  1405. filesystem.add_option(
  1406. '--write-comments', '--get-comments',
  1407. action='store_true', dest='getcomments', default=False,
  1408. help=(
  1409. 'Retrieve video comments to be placed in the infojson. '
  1410. 'The comments are fetched even without this option if the extraction is known to be quick (Alias: --get-comments)'))
  1411. filesystem.add_option(
  1412. '--no-write-comments', '--no-get-comments',
  1413. action='store_false', dest='getcomments',
  1414. help='Do not retrieve video comments unless the extraction is known to be quick (Alias: --no-get-comments)')
  1415. filesystem.add_option(
  1416. '--load-info-json', '--load-info',
  1417. dest='load_info_filename', metavar='FILE',
  1418. help='JSON file containing the video information (created with the "--write-info-json" option)')
  1419. filesystem.add_option(
  1420. '--cookies',
  1421. dest='cookiefile', metavar='FILE',
  1422. help='Netscape formatted file to read cookies from and dump cookie jar in')
  1423. filesystem.add_option(
  1424. '--no-cookies',
  1425. action='store_const', const=None, dest='cookiefile', metavar='FILE',
  1426. help='Do not read/dump cookies from/to file (default)')
  1427. filesystem.add_option(
  1428. '--cookies-from-browser',
  1429. dest='cookiesfrombrowser', metavar='BROWSER[+KEYRING][:PROFILE][::CONTAINER]',
  1430. help=(
  1431. 'The name of the browser to load cookies from. '
  1432. f'Currently supported browsers are: {", ".join(sorted(SUPPORTED_BROWSERS))}. '
  1433. 'Optionally, the KEYRING used for decrypting Chromium cookies on Linux, '
  1434. 'the name/path of the PROFILE to load cookies from, '
  1435. 'and the CONTAINER name (if Firefox) ("none" for no container) '
  1436. 'can be given with their respective separators. '
  1437. 'By default, all containers of the most recently accessed profile are used. '
  1438. f'Currently supported keyrings are: {", ".join(map(str.lower, sorted(SUPPORTED_KEYRINGS)))}'))
  1439. filesystem.add_option(
  1440. '--no-cookies-from-browser',
  1441. action='store_const', const=None, dest='cookiesfrombrowser',
  1442. help='Do not load cookies from browser (default)')
  1443. filesystem.add_option(
  1444. '--cache-dir', dest='cachedir', default=None, metavar='DIR',
  1445. help=(
  1446. 'Location in the filesystem where yt-dlp can store some downloaded information '
  1447. '(such as client ids and signatures) permanently. By default ${XDG_CACHE_HOME}/yt-dlp'))
  1448. filesystem.add_option(
  1449. '--no-cache-dir', action='store_false', dest='cachedir',
  1450. help='Disable filesystem caching')
  1451. filesystem.add_option(
  1452. '--rm-cache-dir',
  1453. action='store_true', dest='rm_cachedir',
  1454. help='Delete all filesystem cache files')
  1455. thumbnail = optparse.OptionGroup(parser, 'Thumbnail Options')
  1456. thumbnail.add_option(
  1457. '--write-thumbnail',
  1458. action='callback', dest='writethumbnail', default=False,
  1459. # Should override --no-write-thumbnail, but not --write-all-thumbnail
  1460. callback=lambda option, _, __, parser: setattr(
  1461. parser.values, option.dest, getattr(parser.values, option.dest) or True),
  1462. help='Write thumbnail image to disk')
  1463. thumbnail.add_option(
  1464. '--no-write-thumbnail',
  1465. action='store_false', dest='writethumbnail',
  1466. help='Do not write thumbnail image to disk (default)')
  1467. thumbnail.add_option(
  1468. '--write-all-thumbnails',
  1469. action='store_const', dest='writethumbnail', const='all',
  1470. help='Write all thumbnail image formats to disk')
  1471. thumbnail.add_option(
  1472. '--list-thumbnails',
  1473. action='store_true', dest='list_thumbnails', default=False,
  1474. help='List available thumbnails of each video. Simulate unless --no-simulate is used')
  1475. link = optparse.OptionGroup(parser, 'Internet Shortcut Options')
  1476. link.add_option(
  1477. '--write-link',
  1478. action='store_true', dest='writelink', default=False,
  1479. help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
  1480. link.add_option(
  1481. '--write-url-link',
  1482. action='store_true', dest='writeurllink', default=False,
  1483. help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
  1484. link.add_option(
  1485. '--write-webloc-link',
  1486. action='store_true', dest='writewebloclink', default=False,
  1487. help='Write a .webloc macOS internet shortcut')
  1488. link.add_option(
  1489. '--write-desktop-link',
  1490. action='store_true', dest='writedesktoplink', default=False,
  1491. help='Write a .desktop Linux internet shortcut')
  1492. postproc = optparse.OptionGroup(parser, 'Post-Processing Options')
  1493. postproc.add_option(
  1494. '-x', '--extract-audio',
  1495. action='store_true', dest='extractaudio', default=False,
  1496. help='Convert video files to audio-only files (requires ffmpeg and ffprobe)')
  1497. postproc.add_option(
  1498. '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
  1499. help=(
  1500. 'Format to convert the audio to when -x is used. '
  1501. f'(currently supported: best (default), {", ".join(sorted(FFmpegExtractAudioPP.SUPPORTED_EXTS))}). '
  1502. 'You can specify multiple rules using similar syntax as --remux-video'))
  1503. postproc.add_option(
  1504. '--audio-quality', metavar='QUALITY',
  1505. dest='audioquality', default='5',
  1506. help=(
  1507. 'Specify ffmpeg audio quality to use when converting the audio with -x. '
  1508. 'Insert a value between 0 (best) and 10 (worst) for VBR or a specific bitrate like 128K (default %default)'))
  1509. postproc.add_option(
  1510. '--remux-video',
  1511. metavar='FORMAT', dest='remuxvideo', default=None,
  1512. help=(
  1513. 'Remux the video into another container if necessary '
  1514. f'(currently supported: {", ".join(FFmpegVideoRemuxerPP.SUPPORTED_EXTS)}). '
  1515. 'If target container does not support the video/audio codec, remuxing will fail. You can specify multiple rules; '
  1516. 'e.g. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 and anything else to mkv'))
  1517. postproc.add_option(
  1518. '--recode-video',
  1519. metavar='FORMAT', dest='recodevideo', default=None,
  1520. help='Re-encode the video into another format if necessary. The syntax and supported formats are the same as --remux-video')
  1521. postproc.add_option(
  1522. '--postprocessor-args', '--ppa',
  1523. metavar='NAME:ARGS', dest='postprocessor_args', default={}, type='str',
  1524. action='callback', callback=_dict_from_options_callback,
  1525. callback_kwargs={
  1526. 'allowed_keys': r'\w+(?:\+\w+)?',
  1527. 'default_key': 'default-compat',
  1528. 'process': shlex.split,
  1529. 'multiple_keys': False,
  1530. }, help=(
  1531. 'Give these arguments to the postprocessors. '
  1532. 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
  1533. 'to give the argument to the specified postprocessor/executable. Supported PP are: '
  1534. 'Merger, ModifyChapters, SplitChapters, ExtractAudio, VideoRemuxer, VideoConvertor, '
  1535. 'Metadata, EmbedSubtitle, EmbedThumbnail, SubtitlesConvertor, ThumbnailsConvertor, '
  1536. 'FixupStretched, FixupM4a, FixupM3u8, FixupTimestamp and FixupDuration. '
  1537. 'The supported executables are: AtomicParsley, FFmpeg and FFprobe. '
  1538. 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
  1539. 'only when being used by the specified postprocessor. Additionally, for ffmpeg/ffprobe, '
  1540. '"_i"/"_o" can be appended to the prefix optionally followed by a number to pass the argument '
  1541. 'before the specified input/output file, e.g. --ppa "Merger+ffmpeg_i1:-v quiet". '
  1542. 'You can use this option multiple times to give different arguments to different '
  1543. 'postprocessors. (Alias: --ppa)'))
  1544. postproc.add_option(
  1545. '-k', '--keep-video',
  1546. action='store_true', dest='keepvideo', default=False,
  1547. help='Keep the intermediate video file on disk after post-processing')
  1548. postproc.add_option(
  1549. '--no-keep-video',
  1550. action='store_false', dest='keepvideo',
  1551. help='Delete the intermediate video file after post-processing (default)')
  1552. postproc.add_option(
  1553. '--post-overwrites',
  1554. action='store_false', dest='nopostoverwrites',
  1555. help='Overwrite post-processed files (default)')
  1556. postproc.add_option(
  1557. '--no-post-overwrites',
  1558. action='store_true', dest='nopostoverwrites', default=False,
  1559. help='Do not overwrite post-processed files')
  1560. postproc.add_option(
  1561. '--embed-subs',
  1562. action='store_true', dest='embedsubtitles', default=False,
  1563. help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
  1564. postproc.add_option(
  1565. '--no-embed-subs',
  1566. action='store_false', dest='embedsubtitles',
  1567. help='Do not embed subtitles (default)')
  1568. postproc.add_option(
  1569. '--embed-thumbnail',
  1570. action='store_true', dest='embedthumbnail', default=False,
  1571. help='Embed thumbnail in the video as cover art')
  1572. postproc.add_option(
  1573. '--no-embed-thumbnail',
  1574. action='store_false', dest='embedthumbnail',
  1575. help='Do not embed thumbnail (default)')
  1576. postproc.add_option(
  1577. '--embed-metadata', '--add-metadata',
  1578. action='store_true', dest='addmetadata', default=False,
  1579. help=(
  1580. 'Embed metadata to the video file. Also embeds chapters/infojson if present '
  1581. 'unless --no-embed-chapters/--no-embed-info-json are used (Alias: --add-metadata)'))
  1582. postproc.add_option(
  1583. '--no-embed-metadata', '--no-add-metadata',
  1584. action='store_false', dest='addmetadata',
  1585. help='Do not add metadata to file (default) (Alias: --no-add-metadata)')
  1586. postproc.add_option(
  1587. '--embed-chapters', '--add-chapters',
  1588. action='store_true', dest='addchapters', default=None,
  1589. help='Add chapter markers to the video file (Alias: --add-chapters)')
  1590. postproc.add_option(
  1591. '--no-embed-chapters', '--no-add-chapters',
  1592. action='store_false', dest='addchapters',
  1593. help='Do not add chapter markers (default) (Alias: --no-add-chapters)')
  1594. postproc.add_option(
  1595. '--embed-info-json',
  1596. action='store_true', dest='embed_infojson', default=None,
  1597. help='Embed the infojson as an attachment to mkv/mka video files')
  1598. postproc.add_option(
  1599. '--no-embed-info-json',
  1600. action='store_false', dest='embed_infojson',
  1601. help='Do not embed the infojson as an attachment to the video file')
  1602. postproc.add_option(
  1603. '--metadata-from-title',
  1604. metavar='FORMAT', dest='metafromtitle',
  1605. help=optparse.SUPPRESS_HELP)
  1606. postproc.add_option(
  1607. '--parse-metadata',
  1608. metavar='[WHEN:]FROM:TO', dest='parse_metadata', **when_prefix('pre_process'),
  1609. help=(
  1610. 'Parse additional metadata like title/artist from other fields; see "MODIFYING METADATA" for details. '
  1611. 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))
  1612. postproc.add_option(
  1613. '--replace-in-metadata',
  1614. dest='parse_metadata', metavar='[WHEN:]FIELDS REGEX REPLACE', nargs=3, **when_prefix('pre_process'),
  1615. help=(
  1616. 'Replace text in a metadata field using the given regex. This option can be used multiple times. '
  1617. 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))
  1618. postproc.add_option(
  1619. '--xattrs', '--xattr',
  1620. action='store_true', dest='xattrs', default=False,
  1621. help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
  1622. postproc.add_option(
  1623. '--concat-playlist',
  1624. metavar='POLICY', dest='concat_playlist', default='multi_video',
  1625. choices=('never', 'always', 'multi_video'),
  1626. help=(
  1627. 'Concatenate videos in a playlist. One of "never", "always", or '
  1628. '"multi_video" (default; only when the videos form a single show). '
  1629. 'All the video files must have same codecs and number of streams to be concatable. '
  1630. 'The "pl_video:" prefix can be used with "--paths" and "--output" to '
  1631. 'set the output filename for the concatenated files. See "OUTPUT TEMPLATE" for details'))
  1632. postproc.add_option(
  1633. '--fixup',
  1634. metavar='POLICY', dest='fixup', default=None,
  1635. choices=('never', 'ignore', 'warn', 'detect_or_warn', 'force'),
  1636. help=(
  1637. 'Automatically correct known faults of the file. '
  1638. 'One of never (do nothing), warn (only emit a warning), '
  1639. 'detect_or_warn (the default; fix file if we can, warn otherwise), '
  1640. 'force (try fixing even if file already exists)'))
  1641. postproc.add_option(
  1642. '--prefer-avconv', '--no-prefer-ffmpeg',
  1643. action='store_false', dest='prefer_ffmpeg',
  1644. help=optparse.SUPPRESS_HELP)
  1645. postproc.add_option(
  1646. '--prefer-ffmpeg', '--no-prefer-avconv',
  1647. action='store_true', dest='prefer_ffmpeg', default=True,
  1648. help=optparse.SUPPRESS_HELP)
  1649. postproc.add_option(
  1650. '--ffmpeg-location', '--avconv-location', metavar='PATH',
  1651. dest='ffmpeg_location',
  1652. help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
  1653. postproc.add_option(
  1654. '--exec',
  1655. metavar='[WHEN:]CMD', dest='exec_cmd', **when_prefix('after_move'),
  1656. help=(
  1657. 'Execute a command, optionally prefixed with when to execute it, separated by a ":". '
  1658. 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: after_move). '
  1659. 'Same syntax as the output template can be used to pass any field as arguments to the command. '
  1660. 'If no fields are passed, %(filepath,_filename|)q is appended to the end of the command. '
  1661. 'This option can be used multiple times'))
  1662. postproc.add_option(
  1663. '--no-exec',
  1664. action='store_const', dest='exec_cmd', const={},
  1665. help='Remove any previously defined --exec')
  1666. postproc.add_option(
  1667. '--exec-before-download', metavar='CMD',
  1668. action='append', dest='exec_before_dl_cmd',
  1669. help=optparse.SUPPRESS_HELP)
  1670. postproc.add_option(
  1671. '--no-exec-before-download',
  1672. action='store_const', dest='exec_before_dl_cmd', const=None,
  1673. help=optparse.SUPPRESS_HELP)
  1674. postproc.add_option(
  1675. '--convert-subs', '--convert-sub', '--convert-subtitles',
  1676. metavar='FORMAT', dest='convertsubtitles', default=None,
  1677. help=(
  1678. 'Convert the subtitles to another format '
  1679. f'(currently supported: {", ".join(sorted(FFmpegSubtitlesConvertorPP.SUPPORTED_EXTS))}). '
  1680. 'Use "--convert-subs none" to disable conversion (default) (Alias: --convert-subtitles)'))
  1681. postproc.add_option(
  1682. '--convert-thumbnails',
  1683. metavar='FORMAT', dest='convertthumbnails', default=None,
  1684. help=(
  1685. 'Convert the thumbnails to another format '
  1686. f'(currently supported: {", ".join(sorted(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS))}). '
  1687. 'You can specify multiple rules using similar syntax as "--remux-video". '
  1688. 'Use "--convert-thumbnails none" to disable conversion (default)'))
  1689. postproc.add_option(
  1690. '--split-chapters', '--split-tracks',
  1691. dest='split_chapters', action='store_true', default=False,
  1692. help=(
  1693. 'Split video into multiple files based on internal chapters. '
  1694. 'The "chapter:" prefix can be used with "--paths" and "--output" to '
  1695. 'set the output filename for the split files. See "OUTPUT TEMPLATE" for details'))
  1696. postproc.add_option(
  1697. '--no-split-chapters', '--no-split-tracks',
  1698. dest='split_chapters', action='store_false',
  1699. help='Do not split video based on chapters (default)')
  1700. postproc.add_option(
  1701. '--remove-chapters',
  1702. metavar='REGEX', dest='remove_chapters', action='append',
  1703. help=(
  1704. 'Remove chapters whose title matches the given regular expression. '
  1705. 'The syntax is the same as --download-sections. This option can be used multiple times'))
  1706. postproc.add_option(
  1707. '--no-remove-chapters', dest='remove_chapters', action='store_const', const=None,
  1708. help='Do not remove any chapters from the file (default)')
  1709. postproc.add_option(
  1710. '--force-keyframes-at-cuts',
  1711. action='store_true', dest='force_keyframes_at_cuts', default=False,
  1712. help=(
  1713. 'Force keyframes at cuts when downloading/splitting/removing sections. '
  1714. 'This is slow due to needing a re-encode, but the resulting video may have fewer artifacts around the cuts'))
  1715. postproc.add_option(
  1716. '--no-force-keyframes-at-cuts',
  1717. action='store_false', dest='force_keyframes_at_cuts',
  1718. help='Do not force keyframes around the chapters when cutting/splitting (default)')
  1719. _postprocessor_opts_parser = lambda key, val='': (
  1720. *(item.split('=', 1) for item in (val.split(';') if val else [])),
  1721. ('key', remove_end(key, 'PP')))
  1722. postproc.add_option(
  1723. '--use-postprocessor',
  1724. metavar='NAME[:ARGS]', dest='add_postprocessors', default=[], type='str',
  1725. action='callback', callback=_list_from_options_callback,
  1726. callback_kwargs={
  1727. 'delim': None,
  1728. 'process': lambda val: dict(_postprocessor_opts_parser(*val.split(':', 1))),
  1729. }, help=(
  1730. 'The (case sensitive) name of plugin postprocessors to be enabled, '
  1731. 'and (optionally) arguments to be passed to it, separated by a colon ":". '
  1732. 'ARGS are a semicolon ";" delimited list of NAME=VALUE. '
  1733. 'The "when" argument determines when the postprocessor is invoked. '
  1734. 'It can be one of "pre_process" (after video extraction), "after_filter" (after video passes filter), '
  1735. '"video" (after --format; before --print/--output), "before_dl" (before each video download), '
  1736. '"post_process" (after each video download; default), '
  1737. '"after_move" (after moving video file to its final locations), '
  1738. '"after_video" (after downloading and processing all formats of a video), '
  1739. 'or "playlist" (at end of playlist). '
  1740. 'This option can be used multiple times to add different postprocessors'))
  1741. sponsorblock = optparse.OptionGroup(parser, 'SponsorBlock Options', description=(
  1742. 'Make chapter entries for, or remove various segments (sponsor, introductions, etc.) '
  1743. 'from downloaded YouTube videos using the SponsorBlock API (https://sponsor.ajay.app)'))
  1744. sponsorblock.add_option(
  1745. '--sponsorblock-mark', metavar='CATS',
  1746. dest='sponsorblock_mark', default=set(), action='callback', type='str',
  1747. callback=_set_from_options_callback, callback_kwargs={
  1748. 'allowed_values': SponsorBlockPP.CATEGORIES.keys(),
  1749. 'aliases': {'default': ['all']},
  1750. }, help=(
  1751. 'SponsorBlock categories to create chapters for, separated by commas. '
  1752. f'Available categories are {", ".join(SponsorBlockPP.CATEGORIES.keys())}, all and default (=all). '
  1753. 'You can prefix the category with a "-" to exclude it. See [1] for description of the categories. '
  1754. 'E.g. --sponsorblock-mark all,-preview [1] https://wiki.sponsor.ajay.app/w/Segment_Categories'))
  1755. sponsorblock.add_option(
  1756. '--sponsorblock-remove', metavar='CATS',
  1757. dest='sponsorblock_remove', default=set(), action='callback', type='str',
  1758. callback=_set_from_options_callback, callback_kwargs={
  1759. 'allowed_values': set(SponsorBlockPP.CATEGORIES.keys()) - set(SponsorBlockPP.NON_SKIPPABLE_CATEGORIES.keys()),
  1760. # Note: From https://wiki.sponsor.ajay.app/w/Types:
  1761. # The filler category is very aggressive.
  1762. # It is strongly recommended to not use this in a client by default.
  1763. 'aliases': {'default': ['all', '-filler']},
  1764. }, help=(
  1765. 'SponsorBlock categories to be removed from the video file, separated by commas. '
  1766. 'If a category is present in both mark and remove, remove takes precedence. '
  1767. 'The syntax and available categories are the same as for --sponsorblock-mark '
  1768. 'except that "default" refers to "all,-filler" '
  1769. f'and {", ".join(SponsorBlockPP.NON_SKIPPABLE_CATEGORIES.keys())} are not available'))
  1770. sponsorblock.add_option(
  1771. '--sponsorblock-chapter-title', metavar='TEMPLATE',
  1772. default=DEFAULT_SPONSORBLOCK_CHAPTER_TITLE, dest='sponsorblock_chapter_title',
  1773. help=(
  1774. 'An output template for the title of the SponsorBlock chapters created by --sponsorblock-mark. '
  1775. 'The only available fields are start_time, end_time, category, categories, name, category_names. '
  1776. 'Defaults to "%default"'))
  1777. sponsorblock.add_option(
  1778. '--no-sponsorblock', default=False,
  1779. action='store_true', dest='no_sponsorblock',
  1780. help='Disable both --sponsorblock-mark and --sponsorblock-remove')
  1781. sponsorblock.add_option(
  1782. '--sponsorblock-api', metavar='URL',
  1783. default='https://sponsor.ajay.app', dest='sponsorblock_api',
  1784. help='SponsorBlock API location, defaults to %default')
  1785. sponsorblock.add_option(
  1786. '--sponskrub',
  1787. action='store_true', dest='sponskrub', default=False,
  1788. help=optparse.SUPPRESS_HELP)
  1789. sponsorblock.add_option(
  1790. '--no-sponskrub',
  1791. action='store_false', dest='sponskrub',
  1792. help=optparse.SUPPRESS_HELP)
  1793. sponsorblock.add_option(
  1794. '--sponskrub-cut', default=False,
  1795. action='store_true', dest='sponskrub_cut',
  1796. help=optparse.SUPPRESS_HELP)
  1797. sponsorblock.add_option(
  1798. '--no-sponskrub-cut',
  1799. action='store_false', dest='sponskrub_cut',
  1800. help=optparse.SUPPRESS_HELP)
  1801. sponsorblock.add_option(
  1802. '--sponskrub-force', default=False,
  1803. action='store_true', dest='sponskrub_force',
  1804. help=optparse.SUPPRESS_HELP)
  1805. sponsorblock.add_option(
  1806. '--no-sponskrub-force',
  1807. action='store_true', dest='sponskrub_force',
  1808. help=optparse.SUPPRESS_HELP)
  1809. sponsorblock.add_option(
  1810. '--sponskrub-location', metavar='PATH',
  1811. dest='sponskrub_path', default='',
  1812. help=optparse.SUPPRESS_HELP)
  1813. sponsorblock.add_option(
  1814. '--sponskrub-args', dest='sponskrub_args', metavar='ARGS',
  1815. help=optparse.SUPPRESS_HELP)
  1816. extractor = optparse.OptionGroup(parser, 'Extractor Options')
  1817. extractor.add_option(
  1818. '--extractor-retries',
  1819. dest='extractor_retries', metavar='RETRIES', default=3,
  1820. help='Number of retries for known extractor errors (default is %default), or "infinite"')
  1821. extractor.add_option(
  1822. '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
  1823. action='store_true', dest='dynamic_mpd', default=True,
  1824. help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
  1825. extractor.add_option(
  1826. '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
  1827. action='store_false', dest='dynamic_mpd',
  1828. help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
  1829. extractor.add_option(
  1830. '--hls-split-discontinuity',
  1831. dest='hls_split_discontinuity', action='store_true', default=False,
  1832. help='Split HLS playlists to different formats at discontinuities such as ad breaks',
  1833. )
  1834. extractor.add_option(
  1835. '--no-hls-split-discontinuity',
  1836. dest='hls_split_discontinuity', action='store_false',
  1837. help='Do not split HLS playlists to different formats at discontinuities such as ad breaks (default)')
  1838. _extractor_arg_parser = lambda key, vals='': (key.strip().lower().replace('-', '_'), [
  1839. val.replace(r'\,', ',').strip() for val in re.split(r'(?<!\\),', vals)])
  1840. extractor.add_option(
  1841. '--extractor-args',
  1842. metavar='IE_KEY:ARGS', dest='extractor_args', default={}, type='str',
  1843. action='callback', callback=_dict_from_options_callback,
  1844. callback_kwargs={
  1845. 'multiple_keys': False,
  1846. 'process': lambda val: dict(
  1847. _extractor_arg_parser(*arg.split('=', 1)) for arg in val.split(';')),
  1848. }, help=(
  1849. 'Pass ARGS arguments to the IE_KEY extractor. See "EXTRACTOR ARGUMENTS" for details. '
  1850. 'You can use this option multiple times to give arguments for different extractors'))
  1851. extractor.add_option(
  1852. '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
  1853. action='store_true', dest='youtube_include_dash_manifest', default=True,
  1854. help=optparse.SUPPRESS_HELP)
  1855. extractor.add_option(
  1856. '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
  1857. action='store_false', dest='youtube_include_dash_manifest',
  1858. help=optparse.SUPPRESS_HELP)
  1859. extractor.add_option(
  1860. '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
  1861. action='store_true', dest='youtube_include_hls_manifest', default=True,
  1862. help=optparse.SUPPRESS_HELP)
  1863. extractor.add_option(
  1864. '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
  1865. action='store_false', dest='youtube_include_hls_manifest',
  1866. help=optparse.SUPPRESS_HELP)
  1867. parser.add_option_group(general)
  1868. parser.add_option_group(network)
  1869. parser.add_option_group(geo)
  1870. parser.add_option_group(selection)
  1871. parser.add_option_group(downloader)
  1872. parser.add_option_group(filesystem)
  1873. parser.add_option_group(thumbnail)
  1874. parser.add_option_group(link)
  1875. parser.add_option_group(verbosity)
  1876. parser.add_option_group(workarounds)
  1877. parser.add_option_group(video_format)
  1878. parser.add_option_group(subtitles)
  1879. parser.add_option_group(authentication)
  1880. parser.add_option_group(postproc)
  1881. parser.add_option_group(sponsorblock)
  1882. parser.add_option_group(extractor)
  1883. return parser
  1884. def _hide_login_info(opts):
  1885. deprecation_warning(f'"{__name__}._hide_login_info" is deprecated and may be removed '
  1886. 'in a future version. Use "yt_dlp.utils.Config.hide_login_info" instead')
  1887. return Config.hide_login_info(opts)