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.

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