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.

729 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. If this option is left out, youtube-dl will ask interactively.')
  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. ' You can filter the video results by putting a condition in'
  268. ' brackets, as in -f "best[height=720]"'
  269. ' (or -f "[filesize>10M]"). '
  270. ' This works for filesize, height, width, tbr, abr, and vbr'
  271. ' and the comparisons <, <=, >, >=, =, != .'
  272. ' Formats for which the value is not known are excluded unless you'
  273. ' put a question mark (?) after the operator.'
  274. ' You can combine format filters, so '
  275. '-f "[height <=? 720][tbr>500]" '
  276. 'selects up to 720p videos (or videos where the height is not '
  277. 'known) with a bitrate of at least 500 KBit/s.'
  278. ' By default, youtube-dl will pick the best quality.'
  279. ' Use commas to download multiple audio formats, such as'
  280. ' -f 136/137/mp4/bestvideo,140/m4a/bestaudio.'
  281. ' You can merge the video and audio of two formats into a single'
  282. ' file using -f <video-format>+<audio-format> (requires ffmpeg or'
  283. ' avconv), for example -f bestvideo+bestaudio.'))
  284. video_format.add_option(
  285. '--all-formats',
  286. action='store_const', dest='format', const='all',
  287. help='download all available video formats')
  288. video_format.add_option(
  289. '--prefer-free-formats',
  290. action='store_true', dest='prefer_free_formats', default=False,
  291. help='prefer free video formats unless a specific one is requested')
  292. video_format.add_option(
  293. '--max-quality',
  294. action='store', dest='format_limit', metavar='FORMAT',
  295. help='highest quality format to download')
  296. video_format.add_option(
  297. '-F', '--list-formats',
  298. action='store_true', dest='listformats',
  299. help='list all available formats')
  300. video_format.add_option(
  301. '--youtube-include-dash-manifest',
  302. action='store_true', dest='youtube_include_dash_manifest', default=True,
  303. help=optparse.SUPPRESS_HELP)
  304. video_format.add_option(
  305. '--youtube-skip-dash-manifest',
  306. action='store_false', dest='youtube_include_dash_manifest',
  307. help='Do not download the DASH manifest on YouTube videos')
  308. video_format.add_option(
  309. '--merge-output-format',
  310. action='store', dest='merge_output_format', metavar='FORMAT', default=None,
  311. help=(
  312. 'If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv.'
  313. 'Ignored if no merge is required'))
  314. subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
  315. subtitles.add_option(
  316. '--write-sub', '--write-srt',
  317. action='store_true', dest='writesubtitles', default=False,
  318. help='write subtitle file')
  319. subtitles.add_option(
  320. '--write-auto-sub', '--write-automatic-sub',
  321. action='store_true', dest='writeautomaticsub', default=False,
  322. help='write automatic subtitle file (youtube only)')
  323. subtitles.add_option(
  324. '--all-subs',
  325. action='store_true', dest='allsubtitles', default=False,
  326. help='downloads all the available subtitles of the video')
  327. subtitles.add_option(
  328. '--list-subs',
  329. action='store_true', dest='listsubtitles', default=False,
  330. help='lists all available subtitles for the video')
  331. subtitles.add_option(
  332. '--sub-format',
  333. action='store', dest='subtitlesformat', metavar='FORMAT', default='srt',
  334. help='subtitle format (default=srt) ([sbv/vtt] youtube only)')
  335. subtitles.add_option(
  336. '--sub-lang', '--sub-langs', '--srt-lang',
  337. action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
  338. default=[], callback=_comma_separated_values_options_callback,
  339. help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
  340. downloader = optparse.OptionGroup(parser, 'Download Options')
  341. downloader.add_option(
  342. '-r', '--rate-limit',
  343. dest='ratelimit', metavar='LIMIT',
  344. help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
  345. downloader.add_option(
  346. '-R', '--retries',
  347. dest='retries', metavar='RETRIES', default=10,
  348. help='number of retries (default is %default)')
  349. downloader.add_option(
  350. '--buffer-size',
  351. dest='buffersize', metavar='SIZE', default='1024',
  352. help='size of download buffer (e.g. 1024 or 16K) (default is %default)')
  353. downloader.add_option(
  354. '--no-resize-buffer',
  355. action='store_true', dest='noresizebuffer', default=False,
  356. help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
  357. downloader.add_option(
  358. '--test',
  359. action='store_true', dest='test', default=False,
  360. help=optparse.SUPPRESS_HELP)
  361. downloader.add_option(
  362. '--playlist-reverse',
  363. action='store_true',
  364. help='Download playlist videos in reverse order')
  365. workarounds = optparse.OptionGroup(parser, 'Workarounds')
  366. workarounds.add_option(
  367. '--encoding',
  368. dest='encoding', metavar='ENCODING',
  369. help='Force the specified encoding (experimental)')
  370. workarounds.add_option(
  371. '--no-check-certificate',
  372. action='store_true', dest='no_check_certificate', default=False,
  373. help='Suppress HTTPS certificate validation.')
  374. workarounds.add_option(
  375. '--prefer-insecure',
  376. '--prefer-unsecure', action='store_true', dest='prefer_insecure',
  377. help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
  378. workarounds.add_option(
  379. '--user-agent',
  380. metavar='UA', dest='user_agent',
  381. help='specify a custom user agent')
  382. workarounds.add_option(
  383. '--referer',
  384. metavar='URL', dest='referer', default=None,
  385. help='specify a custom referer, use if the video access is restricted to one domain',
  386. )
  387. workarounds.add_option(
  388. '--add-header',
  389. metavar='FIELD:VALUE', dest='headers', action='append',
  390. help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
  391. )
  392. workarounds.add_option(
  393. '--bidi-workaround',
  394. dest='bidi_workaround', action='store_true',
  395. help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
  396. workarounds.add_option(
  397. '--sleep-interval', metavar='SECONDS',
  398. dest='sleep_interval', type=float,
  399. help='Number of seconds to sleep before each download.')
  400. verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
  401. verbosity.add_option(
  402. '-q', '--quiet',
  403. action='store_true', dest='quiet', default=False,
  404. help='activates quiet mode')
  405. verbosity.add_option(
  406. '--no-warnings',
  407. dest='no_warnings', action='store_true', default=False,
  408. help='Ignore warnings')
  409. verbosity.add_option(
  410. '-s', '--simulate',
  411. action='store_true', dest='simulate', default=False,
  412. help='do not download the video and do not write anything to disk',)
  413. verbosity.add_option(
  414. '--skip-download',
  415. action='store_true', dest='skip_download', default=False,
  416. help='do not download the video',)
  417. verbosity.add_option(
  418. '-g', '--get-url',
  419. action='store_true', dest='geturl', default=False,
  420. help='simulate, quiet but print URL')
  421. verbosity.add_option(
  422. '-e', '--get-title',
  423. action='store_true', dest='gettitle', default=False,
  424. help='simulate, quiet but print title')
  425. verbosity.add_option(
  426. '--get-id',
  427. action='store_true', dest='getid', default=False,
  428. help='simulate, quiet but print id')
  429. verbosity.add_option(
  430. '--get-thumbnail',
  431. action='store_true', dest='getthumbnail', default=False,
  432. help='simulate, quiet but print thumbnail URL')
  433. verbosity.add_option(
  434. '--get-description',
  435. action='store_true', dest='getdescription', default=False,
  436. help='simulate, quiet but print video description')
  437. verbosity.add_option(
  438. '--get-duration',
  439. action='store_true', dest='getduration', default=False,
  440. help='simulate, quiet but print video length')
  441. verbosity.add_option(
  442. '--get-filename',
  443. action='store_true', dest='getfilename', default=False,
  444. help='simulate, quiet but print output filename')
  445. verbosity.add_option(
  446. '--get-format',
  447. action='store_true', dest='getformat', default=False,
  448. help='simulate, quiet but print output format')
  449. verbosity.add_option(
  450. '-j', '--dump-json',
  451. action='store_true', dest='dumpjson', default=False,
  452. help='simulate, quiet but print JSON information. See --output for a description of available keys.')
  453. verbosity.add_option(
  454. '-J', '--dump-single-json',
  455. action='store_true', dest='dump_single_json', default=False,
  456. 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.')
  457. verbosity.add_option(
  458. '--print-json',
  459. action='store_true', dest='print_json', default=False,
  460. help='Be quiet and print the video information as JSON (video is still being downloaded).',
  461. )
  462. verbosity.add_option(
  463. '--newline',
  464. action='store_true', dest='progress_with_newline', default=False,
  465. help='output progress bar as new lines')
  466. verbosity.add_option(
  467. '--no-progress',
  468. action='store_true', dest='noprogress', default=False,
  469. help='do not print progress bar')
  470. verbosity.add_option(
  471. '--console-title',
  472. action='store_true', dest='consoletitle', default=False,
  473. help='display progress in console titlebar')
  474. verbosity.add_option(
  475. '-v', '--verbose',
  476. action='store_true', dest='verbose', default=False,
  477. help='print various debugging information')
  478. verbosity.add_option(
  479. '--dump-intermediate-pages',
  480. action='store_true', dest='dump_intermediate_pages', default=False,
  481. help='print downloaded pages to debug problems (very verbose)')
  482. verbosity.add_option(
  483. '--write-pages',
  484. action='store_true', dest='write_pages', default=False,
  485. help='Write downloaded intermediary pages to files in the current directory to debug problems')
  486. verbosity.add_option(
  487. '--youtube-print-sig-code',
  488. action='store_true', dest='youtube_print_sig_code', default=False,
  489. help=optparse.SUPPRESS_HELP)
  490. verbosity.add_option(
  491. '--print-traffic',
  492. dest='debug_printtraffic', action='store_true', default=False,
  493. help='Display sent and read HTTP traffic')
  494. verbosity.add_option(
  495. '-C', '--call-home',
  496. dest='call_home', action='store_true', default=False,
  497. help='Contact the youtube-dl server for debugging.')
  498. verbosity.add_option(
  499. '--no-call-home',
  500. dest='call_home', action='store_false', default=False,
  501. help='Do NOT contact the youtube-dl server for debugging.')
  502. filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
  503. filesystem.add_option(
  504. '-a', '--batch-file',
  505. dest='batchfile', metavar='FILE',
  506. help='file containing URLs to download (\'-\' for stdin)')
  507. filesystem.add_option(
  508. '--id', default=False,
  509. action='store_true', dest='useid', help='use only video ID in file name')
  510. filesystem.add_option(
  511. '-o', '--output',
  512. dest='outtmpl', metavar='TEMPLATE',
  513. help=('output filename template. Use %(title)s to get the title, '
  514. '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
  515. '%(autonumber)s to get an automatically incremented number, '
  516. '%(ext)s for the filename extension, '
  517. '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
  518. '%(format_id)s for the unique id of the format (like Youtube\'s itags: "137"), '
  519. '%(upload_date)s for the upload date (YYYYMMDD), '
  520. '%(extractor)s for the provider (youtube, metacafe, etc), '
  521. '%(id)s for the video id, '
  522. '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, '
  523. '%(playlist_index)s for the position in the playlist. '
  524. '%(height)s and %(width)s for the width and height of the video format. '
  525. '%(resolution)s for a textual description of the resolution of the video format. '
  526. '%% for a literal percent. '
  527. 'Use - to output to stdout. Can also be used to download to a different directory, '
  528. 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
  529. filesystem.add_option(
  530. '--autonumber-size',
  531. dest='autonumber_size', metavar='NUMBER',
  532. help='Specifies the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
  533. filesystem.add_option(
  534. '--restrict-filenames',
  535. action='store_true', dest='restrictfilenames', default=False,
  536. help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
  537. filesystem.add_option(
  538. '-A', '--auto-number',
  539. action='store_true', dest='autonumber', default=False,
  540. help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] number downloaded files starting from 00000')
  541. filesystem.add_option(
  542. '-t', '--title',
  543. action='store_true', dest='usetitle', default=False,
  544. help='[deprecated] use title in file name (default)')
  545. filesystem.add_option(
  546. '-l', '--literal', default=False,
  547. action='store_true', dest='usetitle',
  548. help='[deprecated] alias of --title')
  549. filesystem.add_option(
  550. '-w', '--no-overwrites',
  551. action='store_true', dest='nooverwrites', default=False,
  552. help='do not overwrite files')
  553. filesystem.add_option(
  554. '-c', '--continue',
  555. action='store_true', dest='continue_dl', default=True,
  556. help='force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
  557. filesystem.add_option(
  558. '--no-continue',
  559. action='store_false', dest='continue_dl',
  560. help='do not resume partially downloaded files (restart from beginning)')
  561. filesystem.add_option(
  562. '--no-part',
  563. action='store_true', dest='nopart', default=False,
  564. help='do not use .part files - write directly into output file')
  565. filesystem.add_option(
  566. '--no-mtime',
  567. action='store_false', dest='updatetime', default=True,
  568. help='do not use the Last-modified header to set the file modification time')
  569. filesystem.add_option(
  570. '--write-description',
  571. action='store_true', dest='writedescription', default=False,
  572. help='write video description to a .description file')
  573. filesystem.add_option(
  574. '--write-info-json',
  575. action='store_true', dest='writeinfojson', default=False,
  576. help='write video metadata to a .info.json file')
  577. filesystem.add_option(
  578. '--write-annotations',
  579. action='store_true', dest='writeannotations', default=False,
  580. help='write video annotations to a .annotation file')
  581. filesystem.add_option(
  582. '--write-thumbnail',
  583. action='store_true', dest='writethumbnail', default=False,
  584. help='write thumbnail image to disk')
  585. filesystem.add_option(
  586. '--load-info',
  587. dest='load_info_filename', metavar='FILE',
  588. help='json file containing the video information (created with the "--write-json" option)')
  589. filesystem.add_option(
  590. '--cookies',
  591. dest='cookiefile', metavar='FILE',
  592. help='file to read cookies from and dump cookie jar in')
  593. filesystem.add_option(
  594. '--cache-dir', dest='cachedir', default=None, metavar='DIR',
  595. 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.')
  596. filesystem.add_option(
  597. '--no-cache-dir', action='store_const', const=False, dest='cachedir',
  598. help='Disable filesystem caching')
  599. filesystem.add_option(
  600. '--rm-cache-dir',
  601. action='store_true', dest='rm_cachedir',
  602. help='Delete all filesystem cache files')
  603. postproc = optparse.OptionGroup(parser, 'Post-processing Options')
  604. postproc.add_option(
  605. '-x', '--extract-audio',
  606. action='store_true', dest='extractaudio', default=False,
  607. help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
  608. postproc.add_option(
  609. '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
  610. help='"best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
  611. postproc.add_option(
  612. '--audio-quality', metavar='QUALITY',
  613. dest='audioquality', default='5',
  614. 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)')
  615. postproc.add_option(
  616. '--recode-video',
  617. metavar='FORMAT', dest='recodevideo', default=None,
  618. help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv)')
  619. postproc.add_option(
  620. '-k', '--keep-video',
  621. action='store_true', dest='keepvideo', default=False,
  622. help='keeps the video file on disk after the post-processing; the video is erased by default')
  623. postproc.add_option(
  624. '--no-post-overwrites',
  625. action='store_true', dest='nopostoverwrites', default=False,
  626. help='do not overwrite post-processed files; the post-processed files are overwritten by default')
  627. postproc.add_option(
  628. '--embed-subs',
  629. action='store_true', dest='embedsubtitles', default=False,
  630. help='embed subtitles in the video (only for mp4 videos)')
  631. postproc.add_option(
  632. '--embed-thumbnail',
  633. action='store_true', dest='embedthumbnail', default=False,
  634. help='embed thumbnail in the audio as cover art')
  635. postproc.add_option(
  636. '--add-metadata',
  637. action='store_true', dest='addmetadata', default=False,
  638. help='write metadata to the video file')
  639. postproc.add_option(
  640. '--xattrs',
  641. action='store_true', dest='xattrs', default=False,
  642. help='write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
  643. postproc.add_option(
  644. '--fixup',
  645. metavar='POLICY', dest='fixup', default='detect_or_warn',
  646. help='(experimental) Automatically correct known faults of the file. '
  647. 'One of never (do nothing), warn (only emit a warning), '
  648. 'detect_or_warn(check whether we can do anything about it, warn '
  649. 'otherwise')
  650. postproc.add_option(
  651. '--prefer-avconv',
  652. action='store_false', dest='prefer_ffmpeg',
  653. help='Prefer avconv over ffmpeg for running the postprocessors (default)')
  654. postproc.add_option(
  655. '--prefer-ffmpeg',
  656. action='store_true', dest='prefer_ffmpeg',
  657. help='Prefer ffmpeg over avconv for running the postprocessors')
  658. postproc.add_option(
  659. '--exec',
  660. metavar='CMD', dest='exec_cmd',
  661. help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
  662. parser.add_option_group(general)
  663. parser.add_option_group(network)
  664. parser.add_option_group(selection)
  665. parser.add_option_group(downloader)
  666. parser.add_option_group(filesystem)
  667. parser.add_option_group(verbosity)
  668. parser.add_option_group(workarounds)
  669. parser.add_option_group(video_format)
  670. parser.add_option_group(subtitles)
  671. parser.add_option_group(authentication)
  672. parser.add_option_group(postproc)
  673. if overrideArguments is not None:
  674. opts, args = parser.parse_args(overrideArguments)
  675. if opts.verbose:
  676. write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
  677. else:
  678. commandLineConf = sys.argv[1:]
  679. if '--ignore-config' in commandLineConf:
  680. systemConf = []
  681. userConf = []
  682. else:
  683. systemConf = _readOptions('/etc/youtube-dl.conf')
  684. if '--ignore-config' in systemConf:
  685. userConf = []
  686. else:
  687. userConf = _readUserConf()
  688. argv = systemConf + userConf + commandLineConf
  689. opts, args = parser.parse_args(argv)
  690. if opts.verbose:
  691. write_string('[debug] System config: ' + repr(_hide_login_info(systemConf)) + '\n')
  692. write_string('[debug] User config: ' + repr(_hide_login_info(userConf)) + '\n')
  693. write_string('[debug] Command-line args: ' + repr(_hide_login_info(commandLineConf)) + '\n')
  694. return parser, opts, args