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.

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