]>
Commit | Line | Data |
---|---|---|
2daabe49 PH |
1 | from __future__ import unicode_literals |
2 | ||
34a741a8 PH |
3 | import os.path |
4 | import optparse | |
34a741a8 PH |
5 | import sys |
6 | ||
222516d9 | 7 | from .downloader.external import list_external_downloaders |
8c25f81b | 8 | from .compat import ( |
4644ac55 | 9 | compat_expanduser, |
003c69a8 | 10 | compat_get_terminal_size, |
4644ac55 | 11 | compat_getenv, |
c7b0add8 | 12 | compat_kwargs, |
cab792ab | 13 | compat_shlex_split, |
8c25f81b PH |
14 | ) |
15 | from .utils import ( | |
ff556f5c | 16 | preferredencoding, |
34a741a8 PH |
17 | write_string, |
18 | ) | |
19 | from .version import __version__ | |
20 | ||
21 | ||
22 | def parseOpts(overrideArguments=None): | |
23 | def _readOptions(filename_bytes, default=[]): | |
24 | try: | |
25 | optionf = open(filename_bytes) | |
26 | except IOError: | |
27 | return default # silently skip if file is not present | |
28 | try: | |
9e29ef13 | 29 | res = compat_shlex_split(optionf.read(), comments=True) |
34a741a8 PH |
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 | 85 | |
611c1dd9 | 86 | return ''.join(opts) |
34a741a8 PH |
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 | 101 | # No need to wrap help messages if we're on a wide console |
003c69a8 | 102 | columns = compat_get_terminal_size().columns |
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', | |
17941321 | 122 | help='Print this help text and exit') |
8450c15c PH |
123 | general.add_option( |
124 | '-v', '--version', | |
125 | action='version', | |
17941321 | 126 | help='Print program version and exit') |
8450c15c PH |
127 | general.add_option( |
128 | '-U', '--update', | |
129 | action='store_true', dest='update_self', | |
17941321 | 130 | help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)') |
8450c15c PH |
131 | general.add_option( |
132 | '-i', '--ignore-errors', | |
133 | action='store_true', dest='ignoreerrors', default=False, | |
17941321 | 134 | help='Continue on download errors, for example to skip unavailable videos in a playlist') |
8450c15c PH |
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, | |
17941321 | 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, | |
9836cfb8 | 146 | help='List all supported extractors') |
8450c15c PH |
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') | |
d22dec74 S |
151 | general.add_option( |
152 | '--force-generic-extractor', | |
153 | action='store_true', dest='force_generic_extractor', default=False, | |
154 | help='Force extraction to use the generic extractor') | |
34a741a8 PH |
155 | general.add_option( |
156 | '--default-search', | |
157 | dest='default_search', metavar='PREFIX', | |
17941321 | 158 | 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.') |
34a741a8 PH |
159 | general.add_option( |
160 | '--ignore-config', | |
161 | action='store_true', | |
d4e06d4a PH |
162 | help='Do not read configuration files. ' |
163 | 'When given in the global configuration file /etc/youtube-dl.conf: ' | |
164 | 'Do not read the user configuration in ~/.config/youtube-dl/config ' | |
165 | '(%APPDATA%/youtube-dl/config.txt on Windows)') | |
057a5206 PH |
166 | general.add_option( |
167 | '--flat-playlist', | |
168 | action='store_const', dest='extract_flat', const='in_playlist', | |
169 | default=False, | |
170 | help='Do not extract the videos of a playlist, only list them.') | |
d77ab8e2 S |
171 | general.add_option( |
172 | '--mark-watched', | |
173 | action='store_true', dest='mark_watched', default=False, | |
174 | help='Mark videos watched (YouTube only)') | |
90f794c6 S |
175 | general.add_option( |
176 | '--no-mark-watched', | |
177 | action='store_false', dest='mark_watched', default=False, | |
178 | help='Do not mark videos watched (YouTube only)') | |
7e5db8c9 PH |
179 | general.add_option( |
180 | '--no-color', '--no-colors', | |
181 | action='store_true', dest='no_color', | |
182 | default=False, | |
17941321 | 183 | help='Do not emit color codes in output') |
34a741a8 | 184 | |
be4a824d PH |
185 | network = optparse.OptionGroup(parser, 'Network Options') |
186 | network.add_option( | |
187 | '--proxy', dest='proxy', | |
188 | default=None, metavar='URL', | |
6ddb4888 YCH |
189 | help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable experimental ' |
190 | 'SOCKS proxy, specify a proper scheme. For example ' | |
191 | 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") ' | |
192 | 'for direct connection') | |
be4a824d PH |
193 | network.add_option( |
194 | '--socket-timeout', | |
195 | dest='socket_timeout', type=float, default=None, metavar='SECONDS', | |
196 | help='Time to wait before giving up, in seconds') | |
197 | network.add_option( | |
198 | '--source-address', | |
199 | metavar='IP', dest='source_address', default=None, | |
200 | help='Client-side IP address to bind to (experimental)', | |
201 | ) | |
500b8b41 PH |
202 | network.add_option( |
203 | '-4', '--force-ipv4', | |
204 | action='store_const', const='0.0.0.0', dest='source_address', | |
205 | help='Make all connections via IPv4 (experimental)', | |
206 | ) | |
207 | network.add_option( | |
208 | '-6', '--force-ipv6', | |
209 | action='store_const', const='::', dest='source_address', | |
210 | help='Make all connections via IPv6 (experimental)', | |
211 | ) | |
38cce791 YCH |
212 | network.add_option( |
213 | '--geo-verification-proxy', | |
214 | dest='geo_verification_proxy', default=None, metavar='URL', | |
215 | help='Use this proxy to verify the IP address for some geo-restricted sites. ' | |
216 | 'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading. (experimental)' | |
217 | ) | |
91410c9b PH |
218 | network.add_option( |
219 | '--cn-verification-proxy', | |
220 | dest='cn_verification_proxy', default=None, metavar='URL', | |
38cce791 | 221 | help=optparse.SUPPRESS_HELP, |
91410c9b | 222 | ) |
be4a824d | 223 | |
8450c15c | 224 | selection = optparse.OptionGroup(parser, 'Video Selection') |
34a741a8 PH |
225 | selection.add_option( |
226 | '--playlist-start', | |
227 | dest='playliststart', metavar='NUMBER', default=1, type=int, | |
17941321 | 228 | help='Playlist video to start at (default is %default)') |
34a741a8 PH |
229 | selection.add_option( |
230 | '--playlist-end', | |
231 | dest='playlistend', metavar='NUMBER', default=None, type=int, | |
17941321 | 232 | help='Playlist video to end at (default is last)') |
c14e88f0 PH |
233 | selection.add_option( |
234 | '--playlist-items', | |
235 | dest='playlist_items', metavar='ITEM_SPEC', default=None, | |
4eb59a6b | 236 | help='Playlist video items to download. Specify indices of the videos in the playlist separated 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 | 237 | selection.add_option( |
8450c15c PH |
238 | '--match-title', |
239 | dest='matchtitle', metavar='REGEX', | |
17941321 | 240 | help='Download only matching titles (regex or caseless sub-string)') |
8450c15c PH |
241 | selection.add_option( |
242 | '--reject-title', | |
243 | dest='rejecttitle', metavar='REGEX', | |
17941321 | 244 | help='Skip download for matching titles (regex or caseless sub-string)') |
8450c15c PH |
245 | selection.add_option( |
246 | '--max-downloads', | |
247 | dest='max_downloads', metavar='NUMBER', type=int, default=None, | |
248 | help='Abort after downloading NUMBER files') | |
249 | selection.add_option( | |
250 | '--min-filesize', | |
251 | metavar='SIZE', dest='min_filesize', default=None, | |
252 | help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)') | |
253 | selection.add_option( | |
254 | '--max-filesize', | |
255 | metavar='SIZE', dest='max_filesize', default=None, | |
256 | help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)') | |
257 | selection.add_option( | |
258 | '--date', | |
259 | metavar='DATE', dest='date', default=None, | |
17941321 | 260 | help='Download only videos uploaded in this date') |
8450c15c PH |
261 | selection.add_option( |
262 | '--datebefore', | |
263 | metavar='DATE', dest='datebefore', default=None, | |
17941321 | 264 | help='Download only videos uploaded on or before this date (i.e. inclusive)') |
34a741a8 | 265 | selection.add_option( |
8450c15c PH |
266 | '--dateafter', |
267 | metavar='DATE', dest='dateafter', default=None, | |
17941321 | 268 | help='Download only videos uploaded on or after this date (i.e. inclusive)') |
34a741a8 | 269 | selection.add_option( |
8450c15c PH |
270 | '--min-views', |
271 | metavar='COUNT', dest='min_views', default=None, type=int, | |
17941321 | 272 | help='Do not download any videos with less than COUNT views') |
34a741a8 | 273 | selection.add_option( |
8450c15c PH |
274 | '--max-views', |
275 | metavar='COUNT', dest='max_views', default=None, type=int, | |
276 | help='Do not download any videos with more than COUNT views') | |
347de493 PH |
277 | selection.add_option( |
278 | '--match-filter', | |
279 | metavar='FILTER', dest='match_filter', default=None, | |
280 | help=( | |
17941321 | 281 | 'Generic video filter (experimental). ' |
347de493 PH |
282 | 'Specify any key (see help for -o for a list of available keys) to' |
283 | ' match if the key is present, ' | |
284 | '!key to check if the key is not present,' | |
285 | 'key > NUMBER (like "comment_count > 12", also works with ' | |
286 | '>=, <, <=, !=, =) to compare against a number, and ' | |
287 | '& to require multiple matches. ' | |
288 | 'Values which are not known are excluded unless you' | |
289 | ' put a question mark (?) after the operator.' | |
290 | 'For example, to only match videos that have been liked more than ' | |
291 | '100 times and disliked less than 50 times (or the dislike ' | |
292 | 'functionality is not available at the given service), but who ' | |
5495937f | 293 | 'also have a description, use --match-filter ' |
347de493 PH |
294 | '"like_count > 100 & dislike_count <? 50 & description" .' |
295 | )) | |
34a741a8 | 296 | selection.add_option( |
8450c15c PH |
297 | '--no-playlist', |
298 | action='store_true', dest='noplaylist', default=False, | |
17941321 | 299 | help='Download only the video, if the URL refers to a video and a playlist.') |
df4bd0d5 PH |
300 | selection.add_option( |
301 | '--yes-playlist', | |
302 | action='store_false', dest='noplaylist', default=False, | |
17941321 | 303 | help='Download the playlist, if the URL refers to a video and a playlist.') |
8450c15c PH |
304 | selection.add_option( |
305 | '--age-limit', | |
306 | metavar='YEARS', dest='age_limit', default=None, type=int, | |
17941321 | 307 | help='Download only videos suitable for the given age') |
8450c15c PH |
308 | selection.add_option( |
309 | '--download-archive', metavar='FILE', | |
310 | dest='download_archive', | |
311 | help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.') | |
312 | selection.add_option( | |
313 | '--include-ads', | |
314 | dest='include_ads', action='store_true', | |
34a741a8 | 315 | help='Download advertisements as well (experimental)') |
34a741a8 | 316 | |
8450c15c PH |
317 | authentication = optparse.OptionGroup(parser, 'Authentication Options') |
318 | authentication.add_option( | |
319 | '-u', '--username', | |
320 | dest='username', metavar='USERNAME', | |
17941321 | 321 | help='Login with this account ID') |
8450c15c PH |
322 | authentication.add_option( |
323 | '-p', '--password', | |
324 | dest='password', metavar='PASSWORD', | |
17941321 | 325 | help='Account password. If this option is left out, youtube-dl will ask interactively.') |
8450c15c PH |
326 | authentication.add_option( |
327 | '-2', '--twofactor', | |
328 | dest='twofactor', metavar='TWOFACTOR', | |
17941321 | 329 | help='Two-factor auth code') |
8450c15c PH |
330 | authentication.add_option( |
331 | '-n', '--netrc', | |
332 | action='store_true', dest='usenetrc', default=False, | |
17941321 | 333 | help='Use .netrc authentication data') |
8450c15c PH |
334 | authentication.add_option( |
335 | '--video-password', | |
336 | dest='videopassword', metavar='PASSWORD', | |
804c343a | 337 | help='Video password (vimeo, smotri, youku)') |
8450c15c PH |
338 | |
339 | video_format = optparse.OptionGroup(parser, 'Video Format Options') | |
340 | video_format.add_option( | |
341 | '-f', '--format', | |
342 | action='store', dest='format', metavar='FORMAT', default=None, | |
a3805092 | 343 | help='Video format code, see the "FORMAT SELECTION" for all the info') |
8450c15c PH |
344 | video_format.add_option( |
345 | '--all-formats', | |
346 | action='store_const', dest='format', const='all', | |
17941321 | 347 | help='Download all available video formats') |
8450c15c PH |
348 | video_format.add_option( |
349 | '--prefer-free-formats', | |
350 | action='store_true', dest='prefer_free_formats', default=False, | |
17941321 | 351 | help='Prefer free video formats unless a specific one is requested') |
8450c15c PH |
352 | video_format.add_option( |
353 | '-F', '--list-formats', | |
354 | action='store_true', dest='listformats', | |
4b3fbafd | 355 | help='List all available formats of requested videos') |
203fb43f PH |
356 | video_format.add_option( |
357 | '--youtube-include-dash-manifest', | |
358 | action='store_true', dest='youtube_include_dash_manifest', default=True, | |
359 | help=optparse.SUPPRESS_HELP) | |
360 | video_format.add_option( | |
361 | '--youtube-skip-dash-manifest', | |
362 | action='store_false', dest='youtube_include_dash_manifest', | |
b2575b38 | 363 | help='Do not download the DASH manifests and related data on YouTube videos') |
d120e901 | 364 | video_format.add_option( |
bd1a281e PH |
365 | '--merge-output-format', |
366 | action='store', dest='merge_output_format', metavar='FORMAT', default=None, | |
d120e901 | 367 | help=( |
00334d0d S |
368 | 'If a merge is required (e.g. bestvideo+bestaudio), ' |
369 | 'output to given container format. One of mkv, mp4, ogg, webm, flv. ' | |
d120e901 | 370 | 'Ignored if no merge is required')) |
8450c15c PH |
371 | |
372 | subtitles = optparse.OptionGroup(parser, 'Subtitle Options') | |
373 | subtitles.add_option( | |
374 | '--write-sub', '--write-srt', | |
375 | action='store_true', dest='writesubtitles', default=False, | |
17941321 | 376 | help='Write subtitle file') |
8450c15c PH |
377 | subtitles.add_option( |
378 | '--write-auto-sub', '--write-automatic-sub', | |
379 | action='store_true', dest='writeautomaticsub', default=False, | |
741dd8ea | 380 | help='Write automatically generated subtitle file (YouTube only)') |
8450c15c PH |
381 | subtitles.add_option( |
382 | '--all-subs', | |
383 | action='store_true', dest='allsubtitles', default=False, | |
17941321 | 384 | help='Download all the available subtitles of the video') |
8450c15c PH |
385 | subtitles.add_option( |
386 | '--list-subs', | |
387 | action='store_true', dest='listsubtitles', default=False, | |
17941321 | 388 | help='List all available subtitles for the video') |
8450c15c PH |
389 | subtitles.add_option( |
390 | '--sub-format', | |
a504ced0 | 391 | action='store', dest='subtitlesformat', metavar='FORMAT', default='best', |
4a3cdf81 | 392 | help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"') |
8450c15c PH |
393 | subtitles.add_option( |
394 | '--sub-lang', '--sub-langs', '--srt-lang', | |
395 | action='callback', dest='subtitleslangs', metavar='LANGS', type='str', | |
396 | default=[], callback=_comma_separated_values_options_callback, | |
1ca59dac | 397 | help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags') |
8450c15c PH |
398 | |
399 | downloader = optparse.OptionGroup(parser, 'Download Options') | |
400 | downloader.add_option( | |
8ec2b2c4 S |
401 | '-r', '--limit-rate', '--rate-limit', |
402 | dest='ratelimit', metavar='RATE', | |
17941321 | 403 | help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)') |
8450c15c PH |
404 | downloader.add_option( |
405 | '-R', '--retries', | |
406 | dest='retries', metavar='RETRIES', default=10, | |
17941321 | 407 | help='Number of retries (default is %default), or "infinite".') |
52bb437e S |
408 | downloader.add_option( |
409 | '--fragment-retries', | |
410 | dest='fragment_retries', metavar='RETRIES', default=10, | |
411 | help='Number of retries for a fragment (default is %default), or "infinite" (DASH only)') | |
8450c15c PH |
412 | downloader.add_option( |
413 | '--buffer-size', | |
414 | dest='buffersize', metavar='SIZE', default='1024', | |
17941321 | 415 | help='Size of download buffer (e.g. 1024 or 16K) (default is %default)') |
8450c15c PH |
416 | downloader.add_option( |
417 | '--no-resize-buffer', | |
418 | action='store_true', dest='noresizebuffer', default=False, | |
17941321 | 419 | help='Do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.') |
8450c15c PH |
420 | downloader.add_option( |
421 | '--test', | |
422 | action='store_true', dest='test', default=False, | |
423 | help=optparse.SUPPRESS_HELP) | |
ff815fe6 MS |
424 | downloader.add_option( |
425 | '--playlist-reverse', | |
426 | action='store_true', | |
427 | help='Download playlist videos in reverse order') | |
881e6a1f PH |
428 | downloader.add_option( |
429 | '--xattr-set-filesize', | |
430 | dest='xattr_set_filesize', action='store_true', | |
17941321 | 431 | help='Set file xattribute ytdl.filesize with expected filesize (experimental)') |
85729c51 PH |
432 | downloader.add_option( |
433 | '--hls-prefer-native', | |
bf09af3a | 434 | dest='hls_prefer_native', action='store_true', default=None, |
870d5258 | 435 | help='Use the native HLS downloader instead of ffmpeg') |
bf09af3a S |
436 | downloader.add_option( |
437 | '--hls-prefer-ffmpeg', | |
438 | dest='hls_prefer_native', action='store_false', default=None, | |
439 | help='Use ffmpeg instead of the native HLS downloader') | |
7d106a65 JMF |
440 | downloader.add_option( |
441 | '--hls-use-mpegts', | |
442 | dest='hls_use_mpegts', action='store_true', | |
443 | help='Use the mpegts container for HLS videos, allowing to play the ' | |
53be8894 | 444 | 'video while downloading (some players may not be able to play it)') |
222516d9 PH |
445 | downloader.add_option( |
446 | '--external-downloader', | |
447 | dest='external_downloader', metavar='COMMAND', | |
c75f0b36 | 448 | help='Use the specified external downloader. ' |
222516d9 | 449 | 'Currently supports %s' % ','.join(list_external_downloaders())) |
c75f0b36 PH |
450 | downloader.add_option( |
451 | '--external-downloader-args', | |
452 | dest='external_downloader_args', metavar='ARGS', | |
17941321 | 453 | help='Give these arguments to the external downloader') |
8450c15c PH |
454 | |
455 | workarounds = optparse.OptionGroup(parser, 'Workarounds') | |
34a741a8 | 456 | workarounds.add_option( |
8450c15c PH |
457 | '--encoding', |
458 | dest='encoding', metavar='ENCODING', | |
34a741a8 PH |
459 | help='Force the specified encoding (experimental)') |
460 | workarounds.add_option( | |
8450c15c PH |
461 | '--no-check-certificate', |
462 | action='store_true', dest='no_check_certificate', default=False, | |
17941321 | 463 | help='Suppress HTTPS certificate validation') |
34a741a8 | 464 | workarounds.add_option( |
8450c15c PH |
465 | '--prefer-insecure', |
466 | '--prefer-unsecure', action='store_true', dest='prefer_insecure', | |
34a741a8 PH |
467 | help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)') |
468 | workarounds.add_option( | |
8450c15c PH |
469 | '--user-agent', |
470 | metavar='UA', dest='user_agent', | |
17941321 | 471 | help='Specify a custom user agent') |
34a741a8 | 472 | workarounds.add_option( |
8450c15c PH |
473 | '--referer', |
474 | metavar='URL', dest='referer', default=None, | |
17941321 | 475 | help='Specify a custom referer, use if the video access is restricted to one domain', |
34a741a8 PH |
476 | ) |
477 | workarounds.add_option( | |
8450c15c PH |
478 | '--add-header', |
479 | metavar='FIELD:VALUE', dest='headers', action='append', | |
17941321 | 480 | help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times', |
34a741a8 PH |
481 | ) |
482 | workarounds.add_option( | |
8450c15c PH |
483 | '--bidi-workaround', |
484 | dest='bidi_workaround', action='store_true', | |
485 | help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH') | |
5f0d813d PH |
486 | workarounds.add_option( |
487 | '--sleep-interval', metavar='SECONDS', | |
649f7966 | 488 | dest='sleep_interval', type=float, |
5f0d813d | 489 | help='Number of seconds to sleep before each download.') |
34a741a8 | 490 | |
8450c15c PH |
491 | verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options') |
492 | verbosity.add_option( | |
493 | '-q', '--quiet', | |
494 | action='store_true', dest='quiet', default=False, | |
17941321 | 495 | help='Activate quiet mode') |
34a741a8 PH |
496 | verbosity.add_option( |
497 | '--no-warnings', | |
498 | dest='no_warnings', action='store_true', default=False, | |
499 | help='Ignore warnings') | |
8450c15c PH |
500 | verbosity.add_option( |
501 | '-s', '--simulate', | |
502 | action='store_true', dest='simulate', default=False, | |
17941321 | 503 | help='Do not download the video and do not write anything to disk') |
8450c15c PH |
504 | verbosity.add_option( |
505 | '--skip-download', | |
506 | action='store_true', dest='skip_download', default=False, | |
17941321 | 507 | help='Do not download the video') |
8450c15c PH |
508 | verbosity.add_option( |
509 | '-g', '--get-url', | |
510 | action='store_true', dest='geturl', default=False, | |
17941321 | 511 | help='Simulate, quiet but print URL') |
8450c15c PH |
512 | verbosity.add_option( |
513 | '-e', '--get-title', | |
514 | action='store_true', dest='gettitle', default=False, | |
17941321 | 515 | help='Simulate, quiet but print title') |
8450c15c PH |
516 | verbosity.add_option( |
517 | '--get-id', | |
518 | action='store_true', dest='getid', default=False, | |
17941321 | 519 | help='Simulate, quiet but print id') |
8450c15c PH |
520 | verbosity.add_option( |
521 | '--get-thumbnail', | |
522 | action='store_true', dest='getthumbnail', default=False, | |
17941321 | 523 | help='Simulate, quiet but print thumbnail URL') |
8450c15c PH |
524 | verbosity.add_option( |
525 | '--get-description', | |
526 | action='store_true', dest='getdescription', default=False, | |
17941321 | 527 | help='Simulate, quiet but print video description') |
8450c15c PH |
528 | verbosity.add_option( |
529 | '--get-duration', | |
530 | action='store_true', dest='getduration', default=False, | |
17941321 | 531 | help='Simulate, quiet but print video length') |
8450c15c PH |
532 | verbosity.add_option( |
533 | '--get-filename', | |
534 | action='store_true', dest='getfilename', default=False, | |
17941321 | 535 | help='Simulate, quiet but print output filename') |
8450c15c PH |
536 | verbosity.add_option( |
537 | '--get-format', | |
538 | action='store_true', dest='getformat', default=False, | |
17941321 | 539 | help='Simulate, quiet but print output format') |
8450c15c PH |
540 | verbosity.add_option( |
541 | '-j', '--dump-json', | |
542 | action='store_true', dest='dumpjson', default=False, | |
17941321 | 543 | help='Simulate, quiet but print JSON information. See --output for a description of available keys.') |
63e0be34 PH |
544 | verbosity.add_option( |
545 | '-J', '--dump-single-json', | |
546 | action='store_true', dest='dump_single_json', default=False, | |
17941321 | 547 | 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 |
548 | verbosity.add_option( |
549 | '--print-json', | |
550 | action='store_true', dest='print_json', default=False, | |
551 | help='Be quiet and print the video information as JSON (video is still being downloaded).', | |
552 | ) | |
8450c15c PH |
553 | verbosity.add_option( |
554 | '--newline', | |
555 | action='store_true', dest='progress_with_newline', default=False, | |
17941321 | 556 | help='Output progress bar as new lines') |
8450c15c PH |
557 | verbosity.add_option( |
558 | '--no-progress', | |
559 | action='store_true', dest='noprogress', default=False, | |
17941321 | 560 | help='Do not print progress bar') |
8450c15c PH |
561 | verbosity.add_option( |
562 | '--console-title', | |
563 | action='store_true', dest='consoletitle', default=False, | |
17941321 | 564 | help='Display progress in console titlebar') |
8450c15c PH |
565 | verbosity.add_option( |
566 | '-v', '--verbose', | |
567 | action='store_true', dest='verbose', default=False, | |
17941321 | 568 | help='Print various debugging information') |
8450c15c | 569 | verbosity.add_option( |
8bba753c | 570 | '--dump-pages', '--dump-intermediate-pages', |
8450c15c | 571 | action='store_true', dest='dump_intermediate_pages', default=False, |
79979c68 | 572 | help='Print downloaded pages encoded using base64 to debug problems (very verbose)') |
8450c15c PH |
573 | verbosity.add_option( |
574 | '--write-pages', | |
575 | action='store_true', dest='write_pages', default=False, | |
576 | help='Write downloaded intermediary pages to files in the current directory to debug problems') | |
577 | verbosity.add_option( | |
578 | '--youtube-print-sig-code', | |
579 | action='store_true', dest='youtube_print_sig_code', default=False, | |
580 | help=optparse.SUPPRESS_HELP) | |
581 | verbosity.add_option( | |
2f543a21 | 582 | '--print-traffic', '--dump-headers', |
8450c15c PH |
583 | dest='debug_printtraffic', action='store_true', default=False, |
584 | help='Display sent and read HTTP traffic') | |
58b1f00d PH |
585 | verbosity.add_option( |
586 | '-C', '--call-home', | |
587 | dest='call_home', action='store_true', default=False, | |
17941321 | 588 | help='Contact the youtube-dl server for debugging') |
8bfa7545 PH |
589 | verbosity.add_option( |
590 | '--no-call-home', | |
591 | dest='call_home', action='store_false', default=False, | |
17941321 | 592 | help='Do NOT contact the youtube-dl server for debugging') |
8450c15c PH |
593 | |
594 | filesystem = optparse.OptionGroup(parser, 'Filesystem Options') | |
595 | filesystem.add_option( | |
596 | '-a', '--batch-file', | |
597 | dest='batchfile', metavar='FILE', | |
17941321 | 598 | help='File containing URLs to download (\'-\' for stdin)') |
8450c15c PH |
599 | filesystem.add_option( |
600 | '--id', default=False, | |
17941321 | 601 | action='store_true', dest='useid', help='Use only video ID in file name') |
8450c15c PH |
602 | filesystem.add_option( |
603 | '-o', '--output', | |
604 | dest='outtmpl', metavar='TEMPLATE', | |
17941321 | 605 | help=('Output filename template. Use %(title)s to get the title, ' |
8450c15c PH |
606 | '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, ' |
607 | '%(autonumber)s to get an automatically incremented number, ' | |
608 | '%(ext)s for the filename extension, ' | |
609 | '%(format)s for the format description (like "22 - 1280x720" or "HD"), ' | |
17941321 | 610 | '%(format_id)s for the unique id of the format (like YouTube\'s itags: "137"), ' |
8450c15c | 611 | '%(upload_date)s for the upload date (YYYYMMDD), ' |
f0185581 | 612 | '%(extractor)s for the provider (youtube, metacafe, etc), ' |
a1cf99d0 PH |
613 | '%(id)s for the video id, ' |
614 | '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, ' | |
615 | '%(playlist_index)s for the position in the playlist. ' | |
8450c15c PH |
616 | '%(height)s and %(width)s for the width and height of the video format. ' |
617 | '%(resolution)s for a textual description of the resolution of the video format. ' | |
a1cf99d0 | 618 | '%% for a literal percent. ' |
8450c15c PH |
619 | 'Use - to output to stdout. Can also be used to download to a different directory, ' |
620 | 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .')) | |
621 | filesystem.add_option( | |
622 | '--autonumber-size', | |
623 | dest='autonumber_size', metavar='NUMBER', | |
17941321 | 624 | help='Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given') |
8450c15c PH |
625 | filesystem.add_option( |
626 | '--restrict-filenames', | |
627 | action='store_true', dest='restrictfilenames', default=False, | |
628 | help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames') | |
2865cf04 PH |
629 | filesystem.add_option( |
630 | '-A', '--auto-number', | |
631 | action='store_true', dest='autonumber', default=False, | |
5495937f | 632 | help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] Number downloaded files starting from 00000') |
8450c15c PH |
633 | filesystem.add_option( |
634 | '-t', '--title', | |
635 | action='store_true', dest='usetitle', default=False, | |
17941321 | 636 | help='[deprecated] Use title in file name (default)') |
8450c15c PH |
637 | filesystem.add_option( |
638 | '-l', '--literal', default=False, | |
639 | action='store_true', dest='usetitle', | |
17941321 | 640 | help='[deprecated] Alias of --title') |
8450c15c PH |
641 | filesystem.add_option( |
642 | '-w', '--no-overwrites', | |
643 | action='store_true', dest='nooverwrites', default=False, | |
17941321 | 644 | help='Do not overwrite files') |
8450c15c PH |
645 | filesystem.add_option( |
646 | '-c', '--continue', | |
647 | action='store_true', dest='continue_dl', default=True, | |
17941321 | 648 | help='Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.') |
8450c15c PH |
649 | filesystem.add_option( |
650 | '--no-continue', | |
651 | action='store_false', dest='continue_dl', | |
17941321 | 652 | help='Do not resume partially downloaded files (restart from beginning)') |
8450c15c PH |
653 | filesystem.add_option( |
654 | '--no-part', | |
655 | action='store_true', dest='nopart', default=False, | |
17941321 | 656 | help='Do not use .part files - write directly into output file') |
8450c15c PH |
657 | filesystem.add_option( |
658 | '--no-mtime', | |
659 | action='store_false', dest='updatetime', default=True, | |
17941321 | 660 | help='Do not use the Last-modified header to set the file modification time') |
8450c15c PH |
661 | filesystem.add_option( |
662 | '--write-description', | |
663 | action='store_true', dest='writedescription', default=False, | |
17941321 | 664 | help='Write video description to a .description file') |
8450c15c PH |
665 | filesystem.add_option( |
666 | '--write-info-json', | |
667 | action='store_true', dest='writeinfojson', default=False, | |
17941321 | 668 | help='Write video metadata to a .info.json file') |
8450c15c PH |
669 | filesystem.add_option( |
670 | '--write-annotations', | |
671 | action='store_true', dest='writeannotations', default=False, | |
0669c89c | 672 | help='Write video annotations to a .annotations.xml file') |
8450c15c | 673 | filesystem.add_option( |
244fe977 | 674 | '--load-info-json', '--load-info', |
8450c15c | 675 | dest='load_info_filename', metavar='FILE', |
1a48181a | 676 | help='JSON file containing the video information (created with the "--write-info-json" option)') |
8450c15c PH |
677 | filesystem.add_option( |
678 | '--cookies', | |
679 | dest='cookiefile', metavar='FILE', | |
17941321 | 680 | help='File to read cookies from and dump cookie jar in') |
34a741a8 PH |
681 | filesystem.add_option( |
682 | '--cache-dir', dest='cachedir', default=None, metavar='DIR', | |
683 | 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.') | |
684 | filesystem.add_option( | |
685 | '--no-cache-dir', action='store_const', const=False, dest='cachedir', | |
686 | help='Disable filesystem caching') | |
687 | filesystem.add_option( | |
8450c15c PH |
688 | '--rm-cache-dir', |
689 | action='store_true', dest='rm_cachedir', | |
34a741a8 PH |
690 | help='Delete all filesystem cache files') |
691 | ||
cfb56d1a PH |
692 | thumbnail = optparse.OptionGroup(parser, 'Thumbnail images') |
693 | thumbnail.add_option( | |
694 | '--write-thumbnail', | |
695 | action='store_true', dest='writethumbnail', default=False, | |
17941321 | 696 | help='Write thumbnail image to disk') |
ec82d85a PH |
697 | thumbnail.add_option( |
698 | '--write-all-thumbnails', | |
699 | action='store_true', dest='write_all_thumbnails', default=False, | |
17941321 | 700 | help='Write all thumbnail image formats to disk') |
cfb56d1a PH |
701 | thumbnail.add_option( |
702 | '--list-thumbnails', | |
703 | action='store_true', dest='list_thumbnails', default=False, | |
704 | help='Simulate and list all available thumbnail formats') | |
705 | ||
8450c15c PH |
706 | postproc = optparse.OptionGroup(parser, 'Post-processing Options') |
707 | postproc.add_option( | |
708 | '-x', '--extract-audio', | |
709 | action='store_true', dest='extractaudio', default=False, | |
17941321 | 710 | help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)') |
8450c15c PH |
711 | postproc.add_option( |
712 | '--audio-format', metavar='FORMAT', dest='audioformat', default='best', | |
17941321 | 713 | help='Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default') |
8450c15c PH |
714 | postproc.add_option( |
715 | '--audio-quality', metavar='QUALITY', | |
716 | dest='audioquality', default='5', | |
17941321 | 717 | help='Specify ffmpeg/avconv audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)') |
8450c15c PH |
718 | postproc.add_option( |
719 | '--recode-video', | |
720 | metavar='FORMAT', dest='recodevideo', default=None, | |
f72b0a60 | 721 | help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)') |
d84f1d14 | 722 | postproc.add_option( |
1866432d | 723 | '--postprocessor-args', |
f72b0a60 S |
724 | dest='postprocessor_args', metavar='ARGS', |
725 | help='Give these arguments to the postprocessor') | |
8450c15c PH |
726 | postproc.add_option( |
727 | '-k', '--keep-video', | |
728 | action='store_true', dest='keepvideo', default=False, | |
17941321 | 729 | help='Keep the video file on disk after the post-processing; the video is erased by default') |
8450c15c PH |
730 | postproc.add_option( |
731 | '--no-post-overwrites', | |
732 | action='store_true', dest='nopostoverwrites', default=False, | |
17941321 | 733 | help='Do not overwrite post-processed files; the post-processed files are overwritten by default') |
8450c15c PH |
734 | postproc.add_option( |
735 | '--embed-subs', | |
736 | action='store_true', dest='embedsubtitles', default=False, | |
40025ee2 | 737 | help='Embed subtitles in the video (only for mp4, webm and mkv videos)') |
8450c15c PH |
738 | postproc.add_option( |
739 | '--embed-thumbnail', | |
740 | action='store_true', dest='embedthumbnail', default=False, | |
17941321 | 741 | help='Embed thumbnail in the audio as cover art') |
8450c15c PH |
742 | postproc.add_option( |
743 | '--add-metadata', | |
744 | action='store_true', dest='addmetadata', default=False, | |
17941321 | 745 | help='Write metadata to the video file') |
e7db87f7 | 746 | postproc.add_option( |
747 | '--metadata-from-title', | |
748 | metavar='FORMAT', dest='metafromtitle', | |
17941321 | 749 | help='Parse additional metadata like song title / artist from the video title. ' |
e7db87f7 | 750 | 'The format syntax is the same as --output, ' |
88cf6fb3 | 751 | 'the parsed parameters replace existing values. ' |
663004ac | 752 | 'Additional templates: %(album)s, %(artist)s. ' |
e7db87f7 | 753 | 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like ' |
754 | '"Coldplay - Paradise"') | |
8450c15c PH |
755 | postproc.add_option( |
756 | '--xattrs', | |
757 | action='store_true', dest='xattrs', default=False, | |
17941321 | 758 | help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)') |
6271f1ca PH |
759 | postproc.add_option( |
760 | '--fixup', | |
761 | metavar='POLICY', dest='fixup', default='detect_or_warn', | |
9fffd046 | 762 | help='Automatically correct known faults of the file. ' |
6271f1ca | 763 | 'One of never (do nothing), warn (only emit a warning), ' |
5774ef35 | 764 | 'detect_or_warn (the default; fix file if we can, warn otherwise)') |
8450c15c PH |
765 | postproc.add_option( |
766 | '--prefer-avconv', | |
767 | action='store_false', dest='prefer_ffmpeg', | |
34a741a8 | 768 | help='Prefer avconv over ffmpeg for running the postprocessors (default)') |
8450c15c PH |
769 | postproc.add_option( |
770 | '--prefer-ffmpeg', | |
771 | action='store_true', dest='prefer_ffmpeg', | |
34a741a8 | 772 | help='Prefer ffmpeg over avconv for running the postprocessors') |
73fac4e9 PH |
773 | postproc.add_option( |
774 | '--ffmpeg-location', '--avconv-location', metavar='PATH', | |
775 | dest='ffmpeg_location', | |
776 | help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.') | |
34a741a8 | 777 | postproc.add_option( |
8450c15c PH |
778 | '--exec', |
779 | metavar='CMD', dest='exec_cmd', | |
5f6a1245 | 780 | help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'') |
e9fade72 | 781 | postproc.add_option( |
f5bc4b5f | 782 | '--convert-subs', '--convert-subtitles', |
e9fade72 JMF |
783 | metavar='FORMAT', dest='convertsubtitles', default=None, |
784 | help='Convert the subtitles to other format (currently supported: srt|ass|vtt)') | |
34a741a8 PH |
785 | |
786 | parser.add_option_group(general) | |
be4a824d | 787 | parser.add_option_group(network) |
34a741a8 PH |
788 | parser.add_option_group(selection) |
789 | parser.add_option_group(downloader) | |
790 | parser.add_option_group(filesystem) | |
cfb56d1a | 791 | parser.add_option_group(thumbnail) |
34a741a8 PH |
792 | parser.add_option_group(verbosity) |
793 | parser.add_option_group(workarounds) | |
794 | parser.add_option_group(video_format) | |
795 | parser.add_option_group(subtitles) | |
796 | parser.add_option_group(authentication) | |
797 | parser.add_option_group(postproc) | |
798 | ||
799 | if overrideArguments is not None: | |
800 | opts, args = parser.parse_args(overrideArguments) | |
801 | if opts.verbose: | |
8450c15c | 802 | write_string('[debug] Override config: ' + repr(overrideArguments) + '\n') |
34a741a8 | 803 | else: |
b04b94da S |
804 | def compat_conf(conf): |
805 | if sys.version_info < (3,): | |
806 | return [a.decode(preferredencoding(), 'replace') for a in conf] | |
807 | return conf | |
808 | ||
809 | command_line_conf = compat_conf(sys.argv[1:]) | |
f5e2efbb | 810 | |
c06a9fa3 PH |
811 | if '--ignore-config' in command_line_conf: |
812 | system_conf = [] | |
813 | user_conf = [] | |
34a741a8 | 814 | else: |
30d22dae | 815 | system_conf = _readOptions('/etc/youtube-dl.conf') |
c06a9fa3 PH |
816 | if '--ignore-config' in system_conf: |
817 | user_conf = [] | |
34a741a8 | 818 | else: |
30d22dae | 819 | user_conf = _readUserConf() |
c06a9fa3 | 820 | argv = system_conf + user_conf + command_line_conf |
34a741a8 PH |
821 | |
822 | opts, args = parser.parse_args(argv) | |
823 | if opts.verbose: | |
c06a9fa3 PH |
824 | write_string('[debug] System config: ' + repr(_hide_login_info(system_conf)) + '\n') |
825 | write_string('[debug] User config: ' + repr(_hide_login_info(user_conf)) + '\n') | |
826 | write_string('[debug] Command-line args: ' + repr(_hide_login_info(command_line_conf)) + '\n') | |
34a741a8 PH |
827 | |
828 | return parser, opts, args |