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.

481 lines
27 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(): opts.append(' %s' % option.metavar)
  66. return "".join(opts)
  67. def _comma_separated_values_options_callback(option, opt_str, value, parser):
  68. setattr(parser.values, option.dest, value.split(','))
  69. def _hide_login_info(opts):
  70. opts = list(opts)
  71. for private_opt in ['-p', '--password', '-u', '--username', '--video-password']:
  72. try:
  73. i = opts.index(private_opt)
  74. opts[i+1] = '<PRIVATE>'
  75. except ValueError:
  76. pass
  77. return opts
  78. max_width = 80
  79. max_help_position = 80
  80. # No need to wrap help messages if we're on a wide console
  81. columns = get_term_width()
  82. if columns: max_width = columns
  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. # option groups
  93. general = optparse.OptionGroup(parser, 'General Options')
  94. selection = optparse.OptionGroup(parser, 'Video Selection')
  95. authentication = optparse.OptionGroup(parser, 'Authentication Options')
  96. video_format = optparse.OptionGroup(parser, 'Video Format Options')
  97. subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
  98. downloader = optparse.OptionGroup(parser, 'Download Options')
  99. postproc = optparse.OptionGroup(parser, 'Post-processing Options')
  100. filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
  101. workarounds = optparse.OptionGroup(parser, 'Workarounds')
  102. verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
  103. general.add_option('-h', '--help',
  104. action='help', help='print this help text and exit')
  105. general.add_option('-v', '--version',
  106. action='version', help='print program version and exit')
  107. general.add_option('-U', '--update',
  108. action='store_true', dest='update_self', help='update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
  109. general.add_option('-i', '--ignore-errors',
  110. action='store_true', dest='ignoreerrors', help='continue on download errors, for example to skip unavailable videos in a playlist', default=False)
  111. general.add_option('--abort-on-error',
  112. action='store_false', dest='ignoreerrors',
  113. help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
  114. general.add_option('--dump-user-agent',
  115. action='store_true', dest='dump_user_agent',
  116. help='display the current browser identification', default=False)
  117. general.add_option('--list-extractors',
  118. action='store_true', dest='list_extractors',
  119. help='List all supported extractors and the URLs they would handle', default=False)
  120. general.add_option('--extractor-descriptions',
  121. action='store_true', dest='list_extractor_descriptions',
  122. help='Output descriptions of all supported extractors', default=False)
  123. general.add_option(
  124. '--proxy', dest='proxy', default=None, metavar='URL',
  125. help='Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy "") for direct connection')
  126. general.add_option(
  127. '--socket-timeout', dest='socket_timeout',
  128. type=float, default=None, help=u'Time to wait before giving up, in seconds')
  129. general.add_option(
  130. '--default-search',
  131. dest='default_search', metavar='PREFIX',
  132. 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.')
  133. general.add_option(
  134. '--ignore-config',
  135. action='store_true',
  136. 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)')
  137. selection.add_option(
  138. '--playlist-start',
  139. dest='playliststart', metavar='NUMBER', default=1, type=int,
  140. help='playlist video to start at (default is %default)')
  141. selection.add_option(
  142. '--playlist-end',
  143. dest='playlistend', metavar='NUMBER', default=None, type=int,
  144. help='playlist video to end at (default is last)')
  145. selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)')
  146. selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)')
  147. selection.add_option('--max-downloads', metavar='NUMBER',
  148. dest='max_downloads', type=int, default=None,
  149. help='Abort after downloading NUMBER files')
  150. selection.add_option('--min-filesize', metavar='SIZE', dest='min_filesize', help="Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)", default=None)
  151. selection.add_option('--max-filesize', metavar='SIZE', dest='max_filesize', help="Do not download any videos larger than SIZE (e.g. 50k or 44.6m)", default=None)
  152. selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None)
  153. selection.add_option(
  154. '--datebefore', metavar='DATE', dest='datebefore', default=None,
  155. help='download only videos uploaded on or before this date (i.e. inclusive)')
  156. selection.add_option(
  157. '--dateafter', metavar='DATE', dest='dateafter', default=None,
  158. help='download only videos uploaded on or after this date (i.e. inclusive)')
  159. selection.add_option(
  160. '--min-views', metavar='COUNT', dest='min_views',
  161. default=None, type=int,
  162. help="Do not download any videos with less than COUNT views",)
  163. selection.add_option(
  164. '--max-views', metavar='COUNT', dest='max_views',
  165. default=None, type=int,
  166. help="Do not download any videos with more than COUNT views",)
  167. selection.add_option('--no-playlist', action='store_true', dest='noplaylist', help='download only the currently playing video', default=False)
  168. selection.add_option('--age-limit', metavar='YEARS', dest='age_limit',
  169. help='download only videos suitable for the given age',
  170. default=None, type=int)
  171. selection.add_option('--download-archive', metavar='FILE',
  172. dest='download_archive',
  173. help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
  174. selection.add_option(
  175. '--include-ads', dest='include_ads',
  176. action='store_true',
  177. help='Download advertisements as well (experimental)')
  178. selection.add_option(
  179. '--youtube-include-dash-manifest', action='store_true',
  180. dest='youtube_include_dash_manifest', default=False,
  181. help='Try to download the DASH manifest on YouTube videos (experimental)')
  182. authentication.add_option('-u', '--username',
  183. dest='username', metavar='USERNAME', help='account username')
  184. authentication.add_option('-p', '--password',
  185. dest='password', metavar='PASSWORD', help='account password')
  186. authentication.add_option('-2', '--twofactor',
  187. dest='twofactor', metavar='TWOFACTOR', help='two-factor auth code')
  188. authentication.add_option('-n', '--netrc',
  189. action='store_true', dest='usenetrc', help='use .netrc authentication data', default=False)
  190. authentication.add_option('--video-password',
  191. dest='videopassword', metavar='PASSWORD', help='video password (vimeo, smotri)')
  192. video_format.add_option('-f', '--format',
  193. action='store', dest='format', metavar='FORMAT', default=None,
  194. 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')
  195. video_format.add_option('--all-formats',
  196. action='store_const', dest='format', help='download all available video formats', const='all')
  197. video_format.add_option('--prefer-free-formats',
  198. action='store_true', dest='prefer_free_formats', default=False, help='prefer free video formats unless a specific one is requested')
  199. video_format.add_option('--max-quality',
  200. action='store', dest='format_limit', metavar='FORMAT', help='highest quality format to download')
  201. video_format.add_option('-F', '--list-formats',
  202. action='store_true', dest='listformats', help='list all available formats')
  203. subtitles.add_option('--write-sub', '--write-srt',
  204. action='store_true', dest='writesubtitles',
  205. help='write subtitle file', default=False)
  206. subtitles.add_option('--write-auto-sub', '--write-automatic-sub',
  207. action='store_true', dest='writeautomaticsub',
  208. help='write automatic subtitle file (youtube only)', default=False)
  209. subtitles.add_option('--all-subs',
  210. action='store_true', dest='allsubtitles',
  211. help='downloads all the available subtitles of the video', default=False)
  212. subtitles.add_option('--list-subs',
  213. action='store_true', dest='listsubtitles',
  214. help='lists all available subtitles for the video', default=False)
  215. subtitles.add_option('--sub-format',
  216. action='store', dest='subtitlesformat', metavar='FORMAT',
  217. help='subtitle format (default=srt) ([sbv/vtt] youtube only)', default='srt')
  218. subtitles.add_option('--sub-lang', '--sub-langs', '--srt-lang',
  219. action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
  220. default=[], callback=_comma_separated_values_options_callback,
  221. help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
  222. downloader.add_option('-r', '--rate-limit',
  223. dest='ratelimit', metavar='LIMIT', help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
  224. downloader.add_option('-R', '--retries',
  225. dest='retries', metavar='RETRIES', help='number of retries (default is %default)', default=10)
  226. downloader.add_option('--buffer-size',
  227. dest='buffersize', metavar='SIZE', help='size of download buffer (e.g. 1024 or 16K) (default is %default)', default="1024")
  228. downloader.add_option('--no-resize-buffer',
  229. action='store_true', dest='noresizebuffer',
  230. help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.', default=False)
  231. downloader.add_option('--test', action='store_true', dest='test', default=False, help=optparse.SUPPRESS_HELP)
  232. workarounds.add_option(
  233. '--encoding', dest='encoding', metavar='ENCODING',
  234. help='Force the specified encoding (experimental)')
  235. workarounds.add_option(
  236. '--no-check-certificate', action='store_true',
  237. dest='no_check_certificate', default=False,
  238. help='Suppress HTTPS certificate validation.')
  239. workarounds.add_option(
  240. '--prefer-insecure', '--prefer-unsecure', action='store_true', dest='prefer_insecure',
  241. help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
  242. workarounds.add_option(
  243. '--user-agent', metavar='UA',
  244. dest='user_agent', help='specify a custom user agent')
  245. workarounds.add_option(
  246. '--referer', metavar='REF',
  247. dest='referer', default=None,
  248. help='specify a custom referer, use if the video access is restricted to one domain',
  249. )
  250. workarounds.add_option(
  251. '--add-header', metavar='FIELD:VALUE',
  252. dest='headers', action='append',
  253. help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
  254. )
  255. workarounds.add_option(
  256. '--bidi-workaround', dest='bidi_workaround', action='store_true',
  257. help=u'Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
  258. verbosity.add_option('-q', '--quiet',
  259. action='store_true', dest='quiet', help='activates quiet mode', default=False)
  260. verbosity.add_option(
  261. '--no-warnings',
  262. dest='no_warnings', action='store_true', default=False,
  263. help='Ignore warnings')
  264. verbosity.add_option('-s', '--simulate',
  265. action='store_true', dest='simulate', help='do not download the video and do not write anything to disk', default=False)
  266. verbosity.add_option('--skip-download',
  267. action='store_true', dest='skip_download', help='do not download the video', default=False)
  268. verbosity.add_option('-g', '--get-url',
  269. action='store_true', dest='geturl', help='simulate, quiet but print URL', default=False)
  270. verbosity.add_option('-e', '--get-title',
  271. action='store_true', dest='gettitle', help='simulate, quiet but print title', default=False)
  272. verbosity.add_option('--get-id',
  273. action='store_true', dest='getid', help='simulate, quiet but print id', default=False)
  274. verbosity.add_option('--get-thumbnail',
  275. action='store_true', dest='getthumbnail',
  276. help='simulate, quiet but print thumbnail URL', default=False)
  277. verbosity.add_option('--get-description',
  278. action='store_true', dest='getdescription',
  279. help='simulate, quiet but print video description', default=False)
  280. verbosity.add_option('--get-duration',
  281. action='store_true', dest='getduration',
  282. help='simulate, quiet but print video length', default=False)
  283. verbosity.add_option('--get-filename',
  284. action='store_true', dest='getfilename',
  285. help='simulate, quiet but print output filename', default=False)
  286. verbosity.add_option('--get-format',
  287. action='store_true', dest='getformat',
  288. help='simulate, quiet but print output format', default=False)
  289. verbosity.add_option('-j', '--dump-json',
  290. action='store_true', dest='dumpjson',
  291. help='simulate, quiet but print JSON information. See --output for a description of available keys.', default=False)
  292. verbosity.add_option('--newline',
  293. action='store_true', dest='progress_with_newline', help='output progress bar as new lines', default=False)
  294. verbosity.add_option('--no-progress',
  295. action='store_true', dest='noprogress', help='do not print progress bar', default=False)
  296. verbosity.add_option('--console-title',
  297. action='store_true', dest='consoletitle',
  298. help='display progress in console titlebar', default=False)
  299. verbosity.add_option('-v', '--verbose',
  300. action='store_true', dest='verbose', help='print various debugging information', default=False)
  301. verbosity.add_option('--dump-intermediate-pages',
  302. action='store_true', dest='dump_intermediate_pages', default=False,
  303. help='print downloaded pages to debug problems (very verbose)')
  304. verbosity.add_option('--write-pages',
  305. action='store_true', dest='write_pages', default=False,
  306. help='Write downloaded intermediary pages to files in the current directory to debug problems')
  307. verbosity.add_option('--youtube-print-sig-code',
  308. action='store_true', dest='youtube_print_sig_code', default=False,
  309. help=optparse.SUPPRESS_HELP)
  310. verbosity.add_option('--print-traffic',
  311. dest='debug_printtraffic', action='store_true', default=False,
  312. help='Display sent and read HTTP traffic')
  313. filesystem.add_option('-a', '--batch-file',
  314. dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)')
  315. filesystem.add_option('--id',
  316. action='store_true', dest='useid', help='use only video ID in file name', default=False)
  317. filesystem.add_option('-A', '--auto-number',
  318. action='store_true', dest='autonumber',
  319. help='number downloaded files starting from 00000', default=False)
  320. filesystem.add_option('-o', '--output',
  321. dest='outtmpl', metavar='TEMPLATE',
  322. help=('output filename template. Use %(title)s to get the title, '
  323. '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
  324. '%(autonumber)s to get an automatically incremented number, '
  325. '%(ext)s for the filename extension, '
  326. '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
  327. '%(format_id)s for the unique id of the format (like Youtube\'s itags: "137"), '
  328. '%(upload_date)s for the upload date (YYYYMMDD), '
  329. '%(extractor)s for the provider (youtube, metacafe, etc), '
  330. '%(id)s for the video id, %(playlist)s for the playlist the video is in, '
  331. '%(playlist_index)s for the position in the playlist and %% for a literal percent. '
  332. '%(height)s and %(width)s for the width and height of the video format. '
  333. '%(resolution)s for a textual description of the resolution of the video format. '
  334. 'Use - to output to stdout. Can also be used to download to a different directory, '
  335. 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
  336. filesystem.add_option('--autonumber-size',
  337. dest='autonumber_size', metavar='NUMBER',
  338. help='Specifies the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
  339. filesystem.add_option('--restrict-filenames',
  340. action='store_true', dest='restrictfilenames',
  341. help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames', default=False)
  342. filesystem.add_option('-t', '--title',
  343. action='store_true', dest='usetitle', help='[deprecated] use title in file name (default)', default=False)
  344. filesystem.add_option('-l', '--literal',
  345. action='store_true', dest='usetitle', help='[deprecated] alias of --title', default=False)
  346. filesystem.add_option('-w', '--no-overwrites',
  347. action='store_true', dest='nooverwrites', help='do not overwrite files', default=False)
  348. filesystem.add_option('-c', '--continue',
  349. action='store_true', dest='continue_dl', help='force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.', default=True)
  350. filesystem.add_option('--no-continue',
  351. action='store_false', dest='continue_dl',
  352. help='do not resume partially downloaded files (restart from beginning)')
  353. filesystem.add_option('--no-part',
  354. action='store_true', dest='nopart', help='do not use .part files', default=False)
  355. filesystem.add_option('--no-mtime',
  356. action='store_false', dest='updatetime',
  357. help='do not use the Last-modified header to set the file modification time', default=True)
  358. filesystem.add_option('--write-description',
  359. action='store_true', dest='writedescription',
  360. help='write video description to a .description file', default=False)
  361. filesystem.add_option('--write-info-json',
  362. action='store_true', dest='writeinfojson',
  363. help='write video metadata to a .info.json file', default=False)
  364. filesystem.add_option('--write-annotations',
  365. action='store_true', dest='writeannotations',
  366. help='write video annotations to a .annotation file', default=False)
  367. filesystem.add_option('--write-thumbnail',
  368. action='store_true', dest='writethumbnail',
  369. help='write thumbnail image to disk', default=False)
  370. filesystem.add_option('--load-info',
  371. dest='load_info_filename', metavar='FILE',
  372. help='json file containing the video information (created with the "--write-json" option)')
  373. filesystem.add_option('--cookies',
  374. dest='cookiefile', metavar='FILE', help='file to read cookies from and dump cookie jar in')
  375. filesystem.add_option(
  376. '--cache-dir', dest='cachedir', default=None, metavar='DIR',
  377. 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.')
  378. filesystem.add_option(
  379. '--no-cache-dir', action='store_const', const=False, dest='cachedir',
  380. help='Disable filesystem caching')
  381. filesystem.add_option(
  382. '--rm-cache-dir', action='store_true', dest='rm_cachedir',
  383. help='Delete all filesystem cache files')
  384. postproc.add_option('-x', '--extract-audio', action='store_true', dest='extractaudio', default=False,
  385. help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
  386. postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best',
  387. help='"best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; best by default')
  388. postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='5',
  389. help='ffmpeg/avconv audio quality specification, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default 5)')
  390. postproc.add_option('--recode-video', metavar='FORMAT', dest='recodevideo', default=None,
  391. help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv)')
  392. postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False,
  393. help='keeps the video file on disk after the post-processing; the video is erased by default')
  394. postproc.add_option('--no-post-overwrites', action='store_true', dest='nopostoverwrites', default=False,
  395. help='do not overwrite post-processed files; the post-processed files are overwritten by default')
  396. postproc.add_option('--embed-subs', action='store_true', dest='embedsubtitles', default=False,
  397. help='embed subtitles in the video (only for mp4 videos)')
  398. postproc.add_option('--embed-thumbnail', action='store_true', dest='embedthumbnail', default=False,
  399. help='embed thumbnail in the audio as cover art')
  400. postproc.add_option('--add-metadata', action='store_true', dest='addmetadata', default=False,
  401. help='write metadata to the video file')
  402. postproc.add_option('--xattrs', action='store_true', dest='xattrs', default=False,
  403. help='write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
  404. postproc.add_option('--prefer-avconv', action='store_false', dest='prefer_ffmpeg',
  405. help='Prefer avconv over ffmpeg for running the postprocessors (default)')
  406. postproc.add_option('--prefer-ffmpeg', action='store_true', dest='prefer_ffmpeg',
  407. help='Prefer ffmpeg over avconv for running the postprocessors')
  408. postproc.add_option(
  409. '--exec', metavar='CMD', dest='exec_cmd',
  410. help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'' )
  411. parser.add_option_group(general)
  412. parser.add_option_group(selection)
  413. parser.add_option_group(downloader)
  414. parser.add_option_group(filesystem)
  415. parser.add_option_group(verbosity)
  416. parser.add_option_group(workarounds)
  417. parser.add_option_group(video_format)
  418. parser.add_option_group(subtitles)
  419. parser.add_option_group(authentication)
  420. parser.add_option_group(postproc)
  421. if overrideArguments is not None:
  422. opts, args = parser.parse_args(overrideArguments)
  423. if opts.verbose:
  424. write_string(u'[debug] Override config: ' + repr(overrideArguments) + '\n')
  425. else:
  426. commandLineConf = sys.argv[1:]
  427. if '--ignore-config' in commandLineConf:
  428. systemConf = []
  429. userConf = []
  430. else:
  431. systemConf = _readOptions('/etc/youtube-dl.conf')
  432. if '--ignore-config' in systemConf:
  433. userConf = []
  434. else:
  435. userConf = _readUserConf()
  436. argv = systemConf + userConf + commandLineConf
  437. opts, args = parser.parse_args(argv)
  438. if opts.verbose:
  439. write_string(u'[debug] System config: ' + repr(_hide_login_info(systemConf)) + '\n')
  440. write_string(u'[debug] User config: ' + repr(_hide_login_info(userConf)) + '\n')
  441. write_string(u'[debug] Command-line args: ' + repr(_hide_login_info(commandLineConf)) + '\n')
  442. return parser, opts, args