options.py 96 KB

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