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.

635 lines
28 KiB

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