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.

479 lines
27 KiB

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