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.

646 lines
29 KiB

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