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