You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

659 lines
29 KiB

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