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