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.

648 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 slashes: -f 22/17/18 . -f mp4 , -f m4a and -f flv are also supported. You can also use the special names "best", "bestvideo", "bestaudio", "worst", "worstvideo" and "worstaudio". By default, youtube-dl will pick the best quality. Use commas to download multiple audio formats, such as -f 136/137/mp4/bestvideo,140/m4a/bestaudio')
  241. video_format.add_option(
  242. '--all-formats',
  243. action='store_const', dest='format', const='all',
  244. help='download all available video formats')
  245. video_format.add_option(
  246. '--prefer-free-formats',
  247. action='store_true', dest='prefer_free_formats', default=False,
  248. help='prefer free video formats unless a specific one is requested')
  249. video_format.add_option(
  250. '--max-quality',
  251. action='store', dest='format_limit', metavar='FORMAT',
  252. help='highest quality format to download')
  253. video_format.add_option(
  254. '-F', '--list-formats',
  255. action='store_true', dest='listformats',
  256. help='list all available formats')
  257. video_format.add_option(
  258. '--youtube-include-dash-manifest',
  259. action='store_true', dest='youtube_include_dash_manifest', default=True,
  260. help=optparse.SUPPRESS_HELP)
  261. video_format.add_option(
  262. '--youtube-skip-dash-manifest',
  263. action='store_false', dest='youtube_include_dash_manifest',
  264. help='Do not download the DASH manifest on YouTube videos')
  265. subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
  266. subtitles.add_option(
  267. '--write-sub', '--write-srt',
  268. action='store_true', dest='writesubtitles', default=False,
  269. help='write subtitle file')
  270. subtitles.add_option(
  271. '--write-auto-sub', '--write-automatic-sub',
  272. action='store_true', dest='writeautomaticsub', default=False,
  273. help='write automatic subtitle file (youtube only)')
  274. subtitles.add_option(
  275. '--all-subs',
  276. action='store_true', dest='allsubtitles', default=False,
  277. help='downloads all the available subtitles of the video')
  278. subtitles.add_option(
  279. '--list-subs',
  280. action='store_true', dest='listsubtitles', default=False,
  281. help='lists all available subtitles for the video')
  282. subtitles.add_option(
  283. '--sub-format',
  284. action='store', dest='subtitlesformat', metavar='FORMAT', default='srt',
  285. help='subtitle format (default=srt) ([sbv/vtt] youtube only)')
  286. subtitles.add_option(
  287. '--sub-lang', '--sub-langs', '--srt-lang',
  288. action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
  289. default=[], callback=_comma_separated_values_options_callback,
  290. help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
  291. downloader = optparse.OptionGroup(parser, 'Download Options')
  292. downloader.add_option(
  293. '-r', '--rate-limit',
  294. dest='ratelimit', metavar='LIMIT',
  295. help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
  296. downloader.add_option(
  297. '-R', '--retries',
  298. dest='retries', metavar='RETRIES', default=10,
  299. help='number of retries (default is %default)')
  300. downloader.add_option(
  301. '--buffer-size',
  302. dest='buffersize', metavar='SIZE', default='1024',
  303. help='size of download buffer (e.g. 1024 or 16K) (default is %default)')
  304. downloader.add_option(
  305. '--no-resize-buffer',
  306. action='store_true', dest='noresizebuffer', default=False,
  307. help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
  308. downloader.add_option(
  309. '--test',
  310. action='store_true', dest='test', default=False,
  311. help=optparse.SUPPRESS_HELP)
  312. workarounds = optparse.OptionGroup(parser, 'Workarounds')
  313. workarounds.add_option(
  314. '--encoding',
  315. dest='encoding', metavar='ENCODING',
  316. help='Force the specified encoding (experimental)')
  317. workarounds.add_option(
  318. '--no-check-certificate',
  319. action='store_true', dest='no_check_certificate', default=False,
  320. help='Suppress HTTPS certificate validation.')
  321. workarounds.add_option(
  322. '--prefer-insecure',
  323. '--prefer-unsecure', action='store_true', dest='prefer_insecure',
  324. help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
  325. workarounds.add_option(
  326. '--user-agent',
  327. metavar='UA', dest='user_agent',
  328. help='specify a custom user agent')
  329. workarounds.add_option(
  330. '--referer',
  331. metavar='URL', dest='referer', default=None,
  332. help='specify a custom referer, use if the video access is restricted to one domain',
  333. )
  334. workarounds.add_option(
  335. '--add-header',
  336. metavar='FIELD:VALUE', dest='headers', action='append',
  337. help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
  338. )
  339. workarounds.add_option(
  340. '--bidi-workaround',
  341. dest='bidi_workaround', action='store_true',
  342. help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
  343. verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
  344. verbosity.add_option(
  345. '-q', '--quiet',
  346. action='store_true', dest='quiet', default=False,
  347. help='activates quiet mode')
  348. verbosity.add_option(
  349. '--no-warnings',
  350. dest='no_warnings', action='store_true', default=False,
  351. help='Ignore warnings')
  352. verbosity.add_option(
  353. '-s', '--simulate',
  354. action='store_true', dest='simulate', default=False,
  355. help='do not download the video and do not write anything to disk',)
  356. verbosity.add_option(
  357. '--skip-download',
  358. action='store_true', dest='skip_download', default=False,
  359. help='do not download the video',)
  360. verbosity.add_option(
  361. '-g', '--get-url',
  362. action='store_true', dest='geturl', default=False,
  363. help='simulate, quiet but print URL')
  364. verbosity.add_option(
  365. '-e', '--get-title',
  366. action='store_true', dest='gettitle', default=False,
  367. help='simulate, quiet but print title')
  368. verbosity.add_option(
  369. '--get-id',
  370. action='store_true', dest='getid', default=False,
  371. help='simulate, quiet but print id')
  372. verbosity.add_option(
  373. '--get-thumbnail',
  374. action='store_true', dest='getthumbnail', default=False,
  375. help='simulate, quiet but print thumbnail URL')
  376. verbosity.add_option(
  377. '--get-description',
  378. action='store_true', dest='getdescription', default=False,
  379. help='simulate, quiet but print video description')
  380. verbosity.add_option(
  381. '--get-duration',
  382. action='store_true', dest='getduration', default=False,
  383. help='simulate, quiet but print video length')
  384. verbosity.add_option(
  385. '--get-filename',
  386. action='store_true', dest='getfilename', default=False,
  387. help='simulate, quiet but print output filename')
  388. verbosity.add_option(
  389. '--get-format',
  390. action='store_true', dest='getformat', default=False,
  391. help='simulate, quiet but print output format')
  392. verbosity.add_option(
  393. '-j', '--dump-json',
  394. action='store_true', dest='dumpjson', default=False,
  395. help='simulate, quiet but print JSON information. See --output for a description of available keys.')
  396. verbosity.add_option(
  397. '-J', '--dump-single-json',
  398. action='store_true', dest='dump_single_json', default=False,
  399. 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.')
  400. verbosity.add_option(
  401. '--newline',
  402. action='store_true', dest='progress_with_newline', default=False,
  403. help='output progress bar as new lines')
  404. verbosity.add_option(
  405. '--no-progress',
  406. action='store_true', dest='noprogress', default=False,
  407. help='do not print progress bar')
  408. verbosity.add_option(
  409. '--console-title',
  410. action='store_true', dest='consoletitle', default=False,
  411. help='display progress in console titlebar')
  412. verbosity.add_option(
  413. '-v', '--verbose',
  414. action='store_true', dest='verbose', default=False,
  415. help='print various debugging information')
  416. verbosity.add_option(
  417. '--dump-intermediate-pages',
  418. action='store_true', dest='dump_intermediate_pages', default=False,
  419. help='print downloaded pages to debug problems (very verbose)')
  420. verbosity.add_option(
  421. '--write-pages',
  422. action='store_true', dest='write_pages', default=False,
  423. help='Write downloaded intermediary pages to files in the current directory to debug problems')
  424. verbosity.add_option(
  425. '--youtube-print-sig-code',
  426. action='store_true', dest='youtube_print_sig_code', default=False,
  427. help=optparse.SUPPRESS_HELP)
  428. verbosity.add_option(
  429. '--print-traffic',
  430. dest='debug_printtraffic', action='store_true', default=False,
  431. help='Display sent and read HTTP traffic')
  432. filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
  433. filesystem.add_option(
  434. '-a', '--batch-file',
  435. dest='batchfile', metavar='FILE',
  436. help='file containing URLs to download (\'-\' for stdin)')
  437. filesystem.add_option(
  438. '--id', default=False,
  439. action='store_true', dest='useid', help='use only video ID in file name')
  440. filesystem.add_option(
  441. '-A', '--auto-number',
  442. action='store_true', dest='autonumber', default=False,
  443. help='number downloaded files starting from 00000')
  444. filesystem.add_option(
  445. '-o', '--output',
  446. dest='outtmpl', metavar='TEMPLATE',
  447. help=('output filename template. Use %(title)s to get the title, '
  448. '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
  449. '%(autonumber)s to get an automatically incremented number, '
  450. '%(ext)s for the filename extension, '
  451. '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
  452. '%(format_id)s for the unique id of the format (like Youtube\'s itags: "137"), '
  453. '%(upload_date)s for the upload date (YYYYMMDD), '
  454. '%(extractor)s for the provider (youtube, metacafe, etc), '
  455. '%(id)s for the video id, %(playlist)s for the playlist the video is in, '
  456. '%(playlist_index)s for the position in the playlist and %% for a literal percent. '
  457. '%(height)s and %(width)s for the width and height of the video format. '
  458. '%(resolution)s for a textual description of the resolution of the video format. '
  459. 'Use - to output to stdout. Can also be used to download to a different directory, '
  460. 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
  461. filesystem.add_option(
  462. '--autonumber-size',
  463. dest='autonumber_size', metavar='NUMBER',
  464. help='Specifies the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
  465. filesystem.add_option(
  466. '--restrict-filenames',
  467. action='store_true', dest='restrictfilenames', default=False,
  468. help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
  469. filesystem.add_option(
  470. '-t', '--title',
  471. action='store_true', dest='usetitle', default=False,
  472. help='[deprecated] use title in file name (default)')
  473. filesystem.add_option(
  474. '-l', '--literal', default=False,
  475. action='store_true', dest='usetitle',
  476. help='[deprecated] alias of --title')
  477. filesystem.add_option(
  478. '-w', '--no-overwrites',
  479. action='store_true', dest='nooverwrites', default=False,
  480. help='do not overwrite files')
  481. filesystem.add_option(
  482. '-c', '--continue',
  483. action='store_true', dest='continue_dl', default=True,
  484. help='force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
  485. filesystem.add_option(
  486. '--no-continue',
  487. action='store_false', dest='continue_dl',
  488. help='do not resume partially downloaded files (restart from beginning)')
  489. filesystem.add_option(
  490. '--no-part',
  491. action='store_true', dest='nopart', default=False,
  492. help='do not use .part files - write directly into output file')
  493. filesystem.add_option(
  494. '--no-mtime',
  495. action='store_false', dest='updatetime', default=True,
  496. help='do not use the Last-modified header to set the file modification time')
  497. filesystem.add_option(
  498. '--write-description',
  499. action='store_true', dest='writedescription', default=False,
  500. help='write video description to a .description file')
  501. filesystem.add_option(
  502. '--write-info-json',
  503. action='store_true', dest='writeinfojson', default=False,
  504. help='write video metadata to a .info.json file')
  505. filesystem.add_option(
  506. '--write-annotations',
  507. action='store_true', dest='writeannotations', default=False,
  508. help='write video annotations to a .annotation file')
  509. filesystem.add_option(
  510. '--write-thumbnail',
  511. action='store_true', dest='writethumbnail', default=False,
  512. help='write thumbnail image to disk')
  513. filesystem.add_option(
  514. '--load-info',
  515. dest='load_info_filename', metavar='FILE',
  516. help='json file containing the video information (created with the "--write-json" option)')
  517. filesystem.add_option(
  518. '--cookies',
  519. dest='cookiefile', metavar='FILE',
  520. help='file to read cookies from and dump cookie jar in')
  521. filesystem.add_option(
  522. '--cache-dir', dest='cachedir', default=None, metavar='DIR',
  523. 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.')
  524. filesystem.add_option(
  525. '--no-cache-dir', action='store_const', const=False, dest='cachedir',
  526. help='Disable filesystem caching')
  527. filesystem.add_option(
  528. '--rm-cache-dir',
  529. action='store_true', dest='rm_cachedir',
  530. help='Delete all filesystem cache files')
  531. postproc = optparse.OptionGroup(parser, 'Post-processing Options')
  532. postproc.add_option(
  533. '-x', '--extract-audio',
  534. action='store_true', dest='extractaudio', default=False,
  535. help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
  536. postproc.add_option(
  537. '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
  538. help='"best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
  539. postproc.add_option(
  540. '--audio-quality', metavar='QUALITY',
  541. dest='audioquality', default='5',
  542. 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)')
  543. postproc.add_option(
  544. '--recode-video',
  545. metavar='FORMAT', dest='recodevideo', default=None,
  546. help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv)')
  547. postproc.add_option(
  548. '-k', '--keep-video',
  549. action='store_true', dest='keepvideo', default=False,
  550. help='keeps the video file on disk after the post-processing; the video is erased by default')
  551. postproc.add_option(
  552. '--no-post-overwrites',
  553. action='store_true', dest='nopostoverwrites', default=False,
  554. help='do not overwrite post-processed files; the post-processed files are overwritten by default')
  555. postproc.add_option(
  556. '--embed-subs',
  557. action='store_true', dest='embedsubtitles', default=False,
  558. help='embed subtitles in the video (only for mp4 videos)')
  559. postproc.add_option(
  560. '--embed-thumbnail',
  561. action='store_true', dest='embedthumbnail', default=False,
  562. help='embed thumbnail in the audio as cover art')
  563. postproc.add_option(
  564. '--add-metadata',
  565. action='store_true', dest='addmetadata', default=False,
  566. help='write metadata to the video file')
  567. postproc.add_option(
  568. '--xattrs',
  569. action='store_true', dest='xattrs', default=False,
  570. help='write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
  571. postproc.add_option(
  572. '--prefer-avconv',
  573. action='store_false', dest='prefer_ffmpeg',
  574. help='Prefer avconv over ffmpeg for running the postprocessors (default)')
  575. postproc.add_option(
  576. '--prefer-ffmpeg',
  577. action='store_true', dest='prefer_ffmpeg',
  578. help='Prefer ffmpeg over avconv for running the postprocessors')
  579. postproc.add_option(
  580. '--exec',
  581. metavar='CMD', dest='exec_cmd',
  582. help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'' )
  583. parser.add_option_group(general)
  584. parser.add_option_group(selection)
  585. parser.add_option_group(downloader)
  586. parser.add_option_group(filesystem)
  587. parser.add_option_group(verbosity)
  588. parser.add_option_group(workarounds)
  589. parser.add_option_group(video_format)
  590. parser.add_option_group(subtitles)
  591. parser.add_option_group(authentication)
  592. parser.add_option_group(postproc)
  593. if overrideArguments is not None:
  594. opts, args = parser.parse_args(overrideArguments)
  595. if opts.verbose:
  596. write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
  597. else:
  598. commandLineConf = sys.argv[1:]
  599. if '--ignore-config' in commandLineConf:
  600. systemConf = []
  601. userConf = []
  602. else:
  603. systemConf = _readOptions('/etc/youtube-dl.conf')
  604. if '--ignore-config' in systemConf:
  605. userConf = []
  606. else:
  607. userConf = _readUserConf()
  608. argv = systemConf + userConf + commandLineConf
  609. opts, args = parser.parse_args(argv)
  610. if opts.verbose:
  611. write_string('[debug] System config: ' + repr(_hide_login_info(systemConf)) + '\n')
  612. write_string('[debug] User config: ' + repr(_hide_login_info(userConf)) + '\n')
  613. write_string('[debug] Command-line args: ' + repr(_hide_login_info(commandLineConf)) + '\n')
  614. return parser, opts, args