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.

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