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.

661 lines
29 KiB

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