options.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. from __future__ import unicode_literals
  2. import os.path
  3. import optparse
  4. import shlex
  5. import sys
  6. from .compat import (
  7. compat_expanduser,
  8. compat_getenv,
  9. compat_kwargs,
  10. )
  11. from .utils import (
  12. get_term_width,
  13. write_string,
  14. )
  15. from .version import __version__
  16. def parseOpts(overrideArguments=None):
  17. def _readOptions(filename_bytes, default=[]):
  18. try:
  19. optionf = open(filename_bytes)
  20. except IOError:
  21. return default # silently skip if file is not present
  22. try:
  23. res = []
  24. for l in optionf:
  25. res += shlex.split(l, comments=True)
  26. finally:
  27. optionf.close()
  28. return res
  29. def _readUserConf():
  30. xdg_config_home = compat_getenv('XDG_CONFIG_HOME')
  31. if xdg_config_home:
  32. userConfFile = os.path.join(xdg_config_home, 'youtube-dl', 'config')
  33. if not os.path.isfile(userConfFile):
  34. userConfFile = os.path.join(xdg_config_home, 'youtube-dl.conf')
  35. else:
  36. userConfFile = os.path.join(compat_expanduser('~'), '.config', 'youtube-dl', 'config')
  37. if not os.path.isfile(userConfFile):
  38. userConfFile = os.path.join(compat_expanduser('~'), '.config', 'youtube-dl.conf')
  39. userConf = _readOptions(userConfFile, None)
  40. if userConf is None:
  41. appdata_dir = compat_getenv('appdata')
  42. if appdata_dir:
  43. userConf = _readOptions(
  44. os.path.join(appdata_dir, 'youtube-dl', 'config'),
  45. default=None)
  46. if userConf is None:
  47. userConf = _readOptions(
  48. os.path.join(appdata_dir, 'youtube-dl', 'config.txt'),
  49. default=None)
  50. if userConf is None:
  51. userConf = _readOptions(
  52. os.path.join(compat_expanduser('~'), 'youtube-dl.conf'),
  53. default=None)
  54. if userConf is None:
  55. userConf = _readOptions(
  56. os.path.join(compat_expanduser('~'), 'youtube-dl.conf.txt'),
  57. default=None)
  58. if userConf is None:
  59. userConf = []
  60. return userConf
  61. def _format_option_string(option):
  62. ''' ('-o', '--option') -> -o, --format METAVAR'''
  63. opts = []
  64. if option._short_opts:
  65. opts.append(option._short_opts[0])
  66. if option._long_opts:
  67. opts.append(option._long_opts[0])
  68. if len(opts) > 1:
  69. opts.insert(1, ', ')
  70. if option.takes_value():
  71. opts.append(' %s' % option.metavar)
  72. return "".join(opts)
  73. def _comma_separated_values_options_callback(option, opt_str, value, parser):
  74. setattr(parser.values, option.dest, value.split(','))
  75. def _hide_login_info(opts):
  76. opts = list(opts)
  77. for private_opt in ['-p', '--password', '-u', '--username', '--video-password']:
  78. try:
  79. i = opts.index(private_opt)
  80. opts[i + 1] = 'PRIVATE'
  81. except ValueError:
  82. pass
  83. return opts
  84. # No need to wrap help messages if we're on a wide console
  85. columns = get_term_width()
  86. max_width = columns if columns else 80
  87. max_help_position = 80
  88. fmt = optparse.IndentedHelpFormatter(width=max_width, max_help_position=max_help_position)
  89. fmt.format_option_strings = _format_option_string
  90. kw = {
  91. 'version': __version__,
  92. 'formatter': fmt,
  93. 'usage': '%prog [OPTIONS] URL [URL...]',
  94. 'conflict_handler': 'resolve',
  95. }
  96. parser = optparse.OptionParser(**compat_kwargs(kw))
  97. general = optparse.OptionGroup(parser, 'General Options')
  98. general.add_option(
  99. '-h', '--help',
  100. action='help',
  101. help='print this help text and exit')
  102. general.add_option(
  103. '-v', '--version',
  104. action='version',
  105. help='print program version and exit')
  106. general.add_option(
  107. '-U', '--update',
  108. action='store_true', dest='update_self',
  109. help='update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
  110. general.add_option(
  111. '-i', '--ignore-errors',
  112. action='store_true', dest='ignoreerrors', default=False,
  113. help='continue on download errors, for example to skip unavailable videos in a playlist')
  114. general.add_option(
  115. '--abort-on-error',
  116. action='store_false', dest='ignoreerrors',
  117. help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
  118. general.add_option(
  119. '--dump-user-agent',
  120. action='store_true', dest='dump_user_agent', default=False,
  121. help='display the current browser identification')
  122. general.add_option(
  123. '--list-extractors',
  124. action='store_true', dest='list_extractors', default=False,
  125. help='List all supported extractors and the URLs they would handle')
  126. general.add_option(
  127. '--extractor-descriptions',
  128. action='store_true', dest='list_extractor_descriptions', default=False,
  129. help='Output descriptions of all supported extractors')
  130. general.add_option(
  131. '--default-search',
  132. dest='default_search', metavar='PREFIX',
  133. help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube-dl "large apple". Use the value "auto" to let youtube-dl guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching.')
  134. general.add_option(
  135. '--ignore-config',
  136. action='store_true',
  137. help='Do not read configuration files. '
  138. 'When given in the global configuration file /etc/youtube-dl.conf: '
  139. 'Do not read the user configuration in ~/.config/youtube-dl/config '
  140. '(%APPDATA%/youtube-dl/config.txt on Windows)')
  141. general.add_option(
  142. '--flat-playlist',
  143. action='store_const', dest='extract_flat', const='in_playlist',
  144. default=False,
  145. help='Do not extract the videos of a playlist, only list them.')
  146. network = optparse.OptionGroup(parser, 'Network Options')
  147. network.add_option(
  148. '--proxy', dest='proxy',
  149. default=None, metavar='URL',
  150. help='Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy "") for direct connection')
  151. network.add_option(
  152. '--socket-timeout',
  153. dest='socket_timeout', type=float, default=None, metavar='SECONDS',
  154. help='Time to wait before giving up, in seconds')
  155. network.add_option(
  156. '--source-address',
  157. metavar='IP', dest='source_address', default=None,
  158. help='Client-side IP address to bind to (experimental)',
  159. )
  160. selection = optparse.OptionGroup(parser, 'Video Selection')
  161. selection.add_option(
  162. '--playlist-start',
  163. dest='playliststart', metavar='NUMBER', default=1, type=int,
  164. help='playlist video to start at (default is %default)')
  165. selection.add_option(
  166. '--playlist-end',
  167. dest='playlistend', metavar='NUMBER', default=None, type=int,
  168. help='playlist video to end at (default is last)')
  169. selection.add_option(
  170. '--match-title',
  171. dest='matchtitle', metavar='REGEX',
  172. help='download only matching titles (regex or caseless sub-string)')
  173. selection.add_option(
  174. '--reject-title',
  175. dest='rejecttitle', metavar='REGEX',
  176. help='skip download for matching titles (regex or caseless sub-string)')
  177. selection.add_option(
  178. '--max-downloads',
  179. dest='max_downloads', metavar='NUMBER', type=int, default=None,
  180. help='Abort after downloading NUMBER files')
  181. selection.add_option(
  182. '--min-filesize',
  183. metavar='SIZE', dest='min_filesize', default=None,
  184. help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
  185. selection.add_option(
  186. '--max-filesize',
  187. metavar='SIZE', dest='max_filesize', default=None,
  188. help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
  189. selection.add_option(
  190. '--date',
  191. metavar='DATE', dest='date', default=None,
  192. help='download only videos uploaded in this date')
  193. selection.add_option(
  194. '--datebefore',
  195. metavar='DATE', dest='datebefore', default=None,
  196. help='download only videos uploaded on or before this date (i.e. inclusive)')
  197. selection.add_option(
  198. '--dateafter',
  199. metavar='DATE', dest='dateafter', default=None,
  200. help='download only videos uploaded on or after this date (i.e. inclusive)')
  201. selection.add_option(
  202. '--min-views',
  203. metavar='COUNT', dest='min_views', default=None, type=int,
  204. help='Do not download any videos with less than COUNT views',)
  205. selection.add_option(
  206. '--max-views',
  207. metavar='COUNT', dest='max_views', default=None, type=int,
  208. help='Do not download any videos with more than COUNT views')
  209. selection.add_option(
  210. '--no-playlist',
  211. action='store_true', dest='noplaylist', default=False,
  212. help='If the URL refers to a video and a playlist, download only the video.')
  213. selection.add_option(
  214. '--age-limit',
  215. metavar='YEARS', dest='age_limit', default=None, type=int,
  216. help='download only videos suitable for the given age')
  217. selection.add_option(
  218. '--download-archive', metavar='FILE',
  219. dest='download_archive',
  220. help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
  221. selection.add_option(
  222. '--include-ads',
  223. dest='include_ads', action='store_true',
  224. help='Download advertisements as well (experimental)')
  225. authentication = optparse.OptionGroup(parser, 'Authentication Options')
  226. authentication.add_option(
  227. '-u', '--username',
  228. dest='username', metavar='USERNAME',
  229. help='login with this account ID')
  230. authentication.add_option(
  231. '-p', '--password',
  232. dest='password', metavar='PASSWORD',
  233. help='account password')
  234. authentication.add_option(
  235. '-2', '--twofactor',
  236. dest='twofactor', metavar='TWOFACTOR',
  237. help='two-factor auth code')
  238. authentication.add_option(
  239. '-n', '--netrc',
  240. action='store_true', dest='usenetrc', default=False,
  241. help='use .netrc authentication data')
  242. authentication.add_option(
  243. '--video-password',
  244. dest='videopassword', metavar='PASSWORD',
  245. help='video password (vimeo, smotri)')
  246. video_format = optparse.OptionGroup(parser, 'Video Format Options')
  247. video_format.add_option(
  248. '-f', '--format',
  249. action='store', dest='format', metavar='FORMAT', default=None,
  250. help=(
  251. 'video format code, specify the order of preference using'
  252. ' slashes, as in -f 22/17/18 . '
  253. ' Instead of format codes, you can select by extension for the '
  254. 'extensions aac, m4a, mp3, mp4, ogg, wav, webm. '
  255. 'You can also use the special names "best",'
  256. ' "bestvideo", "bestaudio", "worst". '
  257. ' By default, youtube-dl will pick the best quality.'
  258. ' Use commas to download multiple audio formats, such as'
  259. ' -f 136/137/mp4/bestvideo,140/m4a/bestaudio.'
  260. ' You can merge the video and audio of two formats into a single'
  261. ' file using -f <video-format>+<audio-format> (requires ffmpeg or'
  262. ' avconv), for example -f bestvideo+bestaudio.'))
  263. video_format.add_option(
  264. '--all-formats',
  265. action='store_const', dest='format', const='all',
  266. help='download all available video formats')
  267. video_format.add_option(
  268. '--prefer-free-formats',
  269. action='store_true', dest='prefer_free_formats', default=False,
  270. help='prefer free video formats unless a specific one is requested')
  271. video_format.add_option(
  272. '--max-quality',
  273. action='store', dest='format_limit', metavar='FORMAT',
  274. help='highest quality format to download')
  275. video_format.add_option(
  276. '-F', '--list-formats',
  277. action='store_true', dest='listformats',
  278. help='list all available formats')
  279. video_format.add_option(
  280. '--youtube-include-dash-manifest',
  281. action='store_true', dest='youtube_include_dash_manifest', default=True,
  282. help=optparse.SUPPRESS_HELP)
  283. video_format.add_option(
  284. '--youtube-skip-dash-manifest',
  285. action='store_false', dest='youtube_include_dash_manifest',
  286. help='Do not download the DASH manifest on YouTube videos')
  287. video_format.add_option(
  288. '--merge-output-format',
  289. action='store', dest='merge_output_format', metavar='FORMAT', default=None,
  290. help=(
  291. 'If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv.'
  292. 'Ignored if no merge is required'))
  293. subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
  294. subtitles.add_option(
  295. '--write-sub', '--write-srt',
  296. action='store_true', dest='writesubtitles', default=False,
  297. help='write subtitle file')
  298. subtitles.add_option(
  299. '--write-auto-sub', '--write-automatic-sub',
  300. action='store_true', dest='writeautomaticsub', default=False,
  301. help='write automatic subtitle file (youtube only)')
  302. subtitles.add_option(
  303. '--all-subs',
  304. action='store_true', dest='allsubtitles', default=False,
  305. help='downloads all the available subtitles of the video')
  306. subtitles.add_option(
  307. '--list-subs',
  308. action='store_true', dest='listsubtitles', default=False,
  309. help='lists all available subtitles for the video')
  310. subtitles.add_option(
  311. '--sub-format',
  312. action='store', dest='subtitlesformat', metavar='FORMAT', default='srt',
  313. help='subtitle format (default=srt) ([sbv/vtt] youtube only)')
  314. subtitles.add_option(
  315. '--sub-lang', '--sub-langs', '--srt-lang',
  316. action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
  317. default=[], callback=_comma_separated_values_options_callback,
  318. help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
  319. downloader = optparse.OptionGroup(parser, 'Download Options')
  320. downloader.add_option(
  321. '-r', '--rate-limit',
  322. dest='ratelimit', metavar='LIMIT',
  323. help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
  324. downloader.add_option(
  325. '-R', '--retries',
  326. dest='retries', metavar='RETRIES', default=10,
  327. help='number of retries (default is %default)')
  328. downloader.add_option(
  329. '--buffer-size',
  330. dest='buffersize', metavar='SIZE', default='1024',
  331. help='size of download buffer (e.g. 1024 or 16K) (default is %default)')
  332. downloader.add_option(
  333. '--no-resize-buffer',
  334. action='store_true', dest='noresizebuffer', default=False,
  335. help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
  336. downloader.add_option(
  337. '--test',
  338. action='store_true', dest='test', default=False,
  339. help=optparse.SUPPRESS_HELP)
  340. downloader.add_option(
  341. '--playlist-reverse',
  342. action='store_true',
  343. help='Download playlist videos in reverse order')
  344. workarounds = optparse.OptionGroup(parser, 'Workarounds')
  345. workarounds.add_option(
  346. '--encoding',
  347. dest='encoding', metavar='ENCODING',
  348. help='Force the specified encoding (experimental)')
  349. workarounds.add_option(
  350. '--no-check-certificate',
  351. action='store_true', dest='no_check_certificate', default=False,
  352. help='Suppress HTTPS certificate validation.')
  353. workarounds.add_option(
  354. '--prefer-insecure',
  355. '--prefer-unsecure', action='store_true', dest='prefer_insecure',
  356. help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
  357. workarounds.add_option(
  358. '--user-agent',
  359. metavar='UA', dest='user_agent',
  360. help='specify a custom user agent')
  361. workarounds.add_option(
  362. '--referer',
  363. metavar='URL', dest='referer', default=None,
  364. help='specify a custom referer, use if the video access is restricted to one domain',
  365. )
  366. workarounds.add_option(
  367. '--add-header',
  368. metavar='FIELD:VALUE', dest='headers', action='append',
  369. help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
  370. )
  371. workarounds.add_option(
  372. '--bidi-workaround',
  373. dest='bidi_workaround', action='store_true',
  374. help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
  375. verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
  376. verbosity.add_option(
  377. '-q', '--quiet',
  378. action='store_true', dest='quiet', default=False,
  379. help='activates quiet mode')
  380. verbosity.add_option(
  381. '--no-warnings',
  382. dest='no_warnings', action='store_true', default=False,
  383. help='Ignore warnings')
  384. verbosity.add_option(
  385. '-s', '--simulate',
  386. action='store_true', dest='simulate', default=False,
  387. help='do not download the video and do not write anything to disk',)
  388. verbosity.add_option(
  389. '--skip-download',
  390. action='store_true', dest='skip_download', default=False,
  391. help='do not download the video',)
  392. verbosity.add_option(
  393. '-g', '--get-url',
  394. action='store_true', dest='geturl', default=False,
  395. help='simulate, quiet but print URL')
  396. verbosity.add_option(
  397. '-e', '--get-title',
  398. action='store_true', dest='gettitle', default=False,
  399. help='simulate, quiet but print title')
  400. verbosity.add_option(
  401. '--get-id',
  402. action='store_true', dest='getid', default=False,
  403. help='simulate, quiet but print id')
  404. verbosity.add_option(
  405. '--get-thumbnail',
  406. action='store_true', dest='getthumbnail', default=False,
  407. help='simulate, quiet but print thumbnail URL')
  408. verbosity.add_option(
  409. '--get-description',
  410. action='store_true', dest='getdescription', default=False,
  411. help='simulate, quiet but print video description')
  412. verbosity.add_option(
  413. '--get-duration',
  414. action='store_true', dest='getduration', default=False,
  415. help='simulate, quiet but print video length')
  416. verbosity.add_option(
  417. '--get-filename',
  418. action='store_true', dest='getfilename', default=False,
  419. help='simulate, quiet but print output filename')
  420. verbosity.add_option(
  421. '--get-format',
  422. action='store_true', dest='getformat', default=False,
  423. help='simulate, quiet but print output format')
  424. verbosity.add_option(
  425. '-j', '--dump-json',
  426. action='store_true', dest='dumpjson', default=False,
  427. help='simulate, quiet but print JSON information. See --output for a description of available keys.')
  428. verbosity.add_option(
  429. '-J', '--dump-single-json',
  430. action='store_true', dest='dump_single_json', default=False,
  431. help='simulate, quiet but print JSON information for each command-line argument. If the URL refers to a playlist, dump the whole playlist information in a single line.')
  432. verbosity.add_option(
  433. '--print-json',
  434. action='store_true', dest='print_json', default=False,
  435. help='Be quiet and print the video information as JSON (video is still being downloaded).',
  436. )
  437. verbosity.add_option(
  438. '--newline',
  439. action='store_true', dest='progress_with_newline', default=False,
  440. help='output progress bar as new lines')
  441. verbosity.add_option(
  442. '--no-progress',
  443. action='store_true', dest='noprogress', default=False,
  444. help='do not print progress bar')
  445. verbosity.add_option(
  446. '--console-title',
  447. action='store_true', dest='consoletitle', default=False,
  448. help='display progress in console titlebar')
  449. verbosity.add_option(
  450. '-v', '--verbose',
  451. action='store_true', dest='verbose', default=False,
  452. help='print various debugging information')
  453. verbosity.add_option(
  454. '--dump-intermediate-pages',
  455. action='store_true', dest='dump_intermediate_pages', default=False,
  456. help='print downloaded pages to debug problems (very verbose)')
  457. verbosity.add_option(
  458. '--write-pages',
  459. action='store_true', dest='write_pages', default=False,
  460. help='Write downloaded intermediary pages to files in the current directory to debug problems')
  461. verbosity.add_option(
  462. '--youtube-print-sig-code',
  463. action='store_true', dest='youtube_print_sig_code', default=False,
  464. help=optparse.SUPPRESS_HELP)
  465. verbosity.add_option(
  466. '--print-traffic',
  467. dest='debug_printtraffic', action='store_true', default=False,
  468. help='Display sent and read HTTP traffic')
  469. filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
  470. filesystem.add_option(
  471. '-a', '--batch-file',
  472. dest='batchfile', metavar='FILE',
  473. help='file containing URLs to download (\'-\' for stdin)')
  474. filesystem.add_option(
  475. '--id', default=False,
  476. action='store_true', dest='useid', help='use only video ID in file name')
  477. filesystem.add_option(
  478. '-o', '--output',
  479. dest='outtmpl', metavar='TEMPLATE',
  480. help=('output filename template. Use %(title)s to get the title, '
  481. '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
  482. '%(autonumber)s to get an automatically incremented number, '
  483. '%(ext)s for the filename extension, '
  484. '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
  485. '%(format_id)s for the unique id of the format (like Youtube\'s itags: "137"), '
  486. '%(upload_date)s for the upload date (YYYYMMDD), '
  487. '%(extractor)s for the provider (youtube, metacafe, etc), '
  488. '%(id)s for the video id, '
  489. '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, '
  490. '%(playlist_index)s for the position in the playlist. '
  491. '%(height)s and %(width)s for the width and height of the video format. '
  492. '%(resolution)s for a textual description of the resolution of the video format. '
  493. '%% for a literal percent. '
  494. 'Use - to output to stdout. Can also be used to download to a different directory, '
  495. 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
  496. filesystem.add_option(
  497. '--autonumber-size',
  498. dest='autonumber_size', metavar='NUMBER',
  499. help='Specifies the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
  500. filesystem.add_option(
  501. '--restrict-filenames',
  502. action='store_true', dest='restrictfilenames', default=False,
  503. help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
  504. filesystem.add_option(
  505. '-A', '--auto-number',
  506. action='store_true', dest='autonumber', default=False,
  507. help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] number downloaded files starting from 00000')
  508. filesystem.add_option(
  509. '-t', '--title',
  510. action='store_true', dest='usetitle', default=False,
  511. help='[deprecated] use title in file name (default)')
  512. filesystem.add_option(
  513. '-l', '--literal', default=False,
  514. action='store_true', dest='usetitle',
  515. help='[deprecated] alias of --title')
  516. filesystem.add_option(
  517. '-w', '--no-overwrites',
  518. action='store_true', dest='nooverwrites', default=False,
  519. help='do not overwrite files')
  520. filesystem.add_option(
  521. '-c', '--continue',
  522. action='store_true', dest='continue_dl', default=True,
  523. help='force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
  524. filesystem.add_option(
  525. '--no-continue',
  526. action='store_false', dest='continue_dl',
  527. help='do not resume partially downloaded files (restart from beginning)')
  528. filesystem.add_option(
  529. '--no-part',
  530. action='store_true', dest='nopart', default=False,
  531. help='do not use .part files - write directly into output file')
  532. filesystem.add_option(
  533. '--no-mtime',
  534. action='store_false', dest='updatetime', default=True,
  535. help='do not use the Last-modified header to set the file modification time')
  536. filesystem.add_option(
  537. '--write-description',
  538. action='store_true', dest='writedescription', default=False,
  539. help='write video description to a .description file')
  540. filesystem.add_option(
  541. '--write-info-json',
  542. action='store_true', dest='writeinfojson', default=False,
  543. help='write video metadata to a .info.json file')
  544. filesystem.add_option(
  545. '--write-annotations',
  546. action='store_true', dest='writeannotations', default=False,
  547. help='write video annotations to a .annotation file')
  548. filesystem.add_option(
  549. '--write-thumbnail',
  550. action='store_true', dest='writethumbnail', default=False,
  551. help='write thumbnail image to disk')
  552. filesystem.add_option(
  553. '--load-info',
  554. dest='load_info_filename', metavar='FILE',
  555. help='json file containing the video information (created with the "--write-json" option)')
  556. filesystem.add_option(
  557. '--cookies',
  558. dest='cookiefile', metavar='FILE',
  559. help='file to read cookies from and dump cookie jar in')
  560. filesystem.add_option(
  561. '--cache-dir', dest='cachedir', default=None, metavar='DIR',
  562. help='Location in the filesystem where youtube-dl can store some downloaded information permanently. By default $XDG_CACHE_HOME/youtube-dl or ~/.cache/youtube-dl . At the moment, only YouTube player files (for videos with obfuscated signatures) are cached, but that may change.')
  563. filesystem.add_option(
  564. '--no-cache-dir', action='store_const', const=False, dest='cachedir',
  565. help='Disable filesystem caching')
  566. filesystem.add_option(
  567. '--rm-cache-dir',
  568. action='store_true', dest='rm_cachedir',
  569. help='Delete all filesystem cache files')
  570. postproc = optparse.OptionGroup(parser, 'Post-processing Options')
  571. postproc.add_option(
  572. '-x', '--extract-audio',
  573. action='store_true', dest='extractaudio', default=False,
  574. help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
  575. postproc.add_option(
  576. '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
  577. help='"best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
  578. postproc.add_option(
  579. '--audio-quality', metavar='QUALITY',
  580. dest='audioquality', default='5',
  581. help='ffmpeg/avconv audio quality specification, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)')
  582. postproc.add_option(
  583. '--recode-video',
  584. metavar='FORMAT', dest='recodevideo', default=None,
  585. help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv)')
  586. postproc.add_option(
  587. '-k', '--keep-video',
  588. action='store_true', dest='keepvideo', default=False,
  589. help='keeps the video file on disk after the post-processing; the video is erased by default')
  590. postproc.add_option(
  591. '--no-post-overwrites',
  592. action='store_true', dest='nopostoverwrites', default=False,
  593. help='do not overwrite post-processed files; the post-processed files are overwritten by default')
  594. postproc.add_option(
  595. '--embed-subs',
  596. action='store_true', dest='embedsubtitles', default=False,
  597. help='embed subtitles in the video (only for mp4 videos)')
  598. postproc.add_option(
  599. '--embed-thumbnail',
  600. action='store_true', dest='embedthumbnail', default=False,
  601. help='embed thumbnail in the audio as cover art')
  602. postproc.add_option(
  603. '--add-metadata',
  604. action='store_true', dest='addmetadata', default=False,
  605. help='write metadata to the video file')
  606. postproc.add_option(
  607. '--xattrs',
  608. action='store_true', dest='xattrs', default=False,
  609. help='write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
  610. postproc.add_option(
  611. '--fixup',
  612. metavar='POLICY', dest='fixup', default='detect_or_warn',
  613. help='(experimental) Automatically correct known faults of the file. '
  614. 'One of never (do nothing), warn (only emit a warning), '
  615. 'detect_or_warn(check whether we can do anything about it, warn '
  616. 'otherwise')
  617. postproc.add_option(
  618. '--prefer-avconv',
  619. action='store_false', dest='prefer_ffmpeg',
  620. help='Prefer avconv over ffmpeg for running the postprocessors (default)')
  621. postproc.add_option(
  622. '--prefer-ffmpeg',
  623. action='store_true', dest='prefer_ffmpeg',
  624. help='Prefer ffmpeg over avconv for running the postprocessors')
  625. postproc.add_option(
  626. '--exec',
  627. metavar='CMD', dest='exec_cmd',
  628. help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
  629. parser.add_option_group(general)
  630. parser.add_option_group(network)
  631. parser.add_option_group(selection)
  632. parser.add_option_group(downloader)
  633. parser.add_option_group(filesystem)
  634. parser.add_option_group(verbosity)
  635. parser.add_option_group(workarounds)
  636. parser.add_option_group(video_format)
  637. parser.add_option_group(subtitles)
  638. parser.add_option_group(authentication)
  639. parser.add_option_group(postproc)
  640. if overrideArguments is not None:
  641. opts, args = parser.parse_args(overrideArguments)
  642. if opts.verbose:
  643. write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
  644. else:
  645. commandLineConf = sys.argv[1:]
  646. if '--ignore-config' in commandLineConf:
  647. systemConf = []
  648. userConf = []
  649. else:
  650. systemConf = _readOptions('/etc/youtube-dl.conf')
  651. if '--ignore-config' in systemConf:
  652. userConf = []
  653. else:
  654. userConf = _readUserConf()
  655. argv = systemConf + userConf + commandLineConf
  656. opts, args = parser.parse_args(argv)
  657. if opts.verbose:
  658. write_string('[debug] System config: ' + repr(_hide_login_info(systemConf)) + '\n')
  659. write_string('[debug] User config: ' + repr(_hide_login_info(userConf)) + '\n')
  660. write_string('[debug] Command-line args: ' + repr(_hide_login_info(commandLineConf)) + '\n')
  661. return parser, opts, args