options.py 27 KB

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