options.py 95 KB

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