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