options.py 28 KB

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