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