rezo 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/index.cjs +6 -6
- package/dist/cache/index.cjs +9 -9
- package/dist/crawler/index.cjs +40 -40
- package/dist/entries/crawler.cjs +4 -4
- package/dist/index.cjs +27 -27
- package/dist/internal/agents/index.cjs +10 -10
- package/dist/proxy/index.cjs +4 -4
- package/dist/queue/index.cjs +8 -8
- package/dist/responses/universal/index.cjs +11 -11
- package/dist/wget/asset-extractor.cjs +556 -0
- package/dist/wget/asset-extractor.js +553 -0
- package/dist/wget/asset-organizer.cjs +230 -0
- package/dist/wget/asset-organizer.js +227 -0
- package/dist/wget/download-cache.cjs +221 -0
- package/dist/wget/download-cache.js +218 -0
- package/dist/wget/downloader.cjs +607 -0
- package/dist/wget/downloader.js +604 -0
- package/dist/wget/file-writer.cjs +349 -0
- package/dist/wget/file-writer.js +346 -0
- package/dist/wget/filter-lists.cjs +1330 -0
- package/dist/wget/filter-lists.js +1330 -0
- package/dist/wget/index.cjs +633 -0
- package/dist/wget/index.d.ts +8494 -0
- package/dist/wget/index.js +614 -0
- package/dist/wget/link-converter.cjs +342 -0
- package/dist/wget/link-converter.js +339 -0
- package/dist/wget/progress.cjs +271 -0
- package/dist/wget/progress.js +266 -0
- package/dist/wget/resume.cjs +166 -0
- package/dist/wget/resume.js +163 -0
- package/dist/wget/robots.cjs +303 -0
- package/dist/wget/robots.js +300 -0
- package/dist/wget/types.cjs +200 -0
- package/dist/wget/types.js +197 -0
- package/dist/wget/url-filter.cjs +351 -0
- package/dist/wget/url-filter.js +348 -0
- package/package.json +6 -1
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
const _mod_1sms7v = require('./types.cjs');
|
|
2
|
+
exports.WgetError = _mod_1sms7v.WgetError;;
|
|
3
|
+
const _mod_9nj1wb = require('./asset-extractor.cjs');
|
|
4
|
+
exports.AssetExtractor = _mod_9nj1wb.AssetExtractor;;
|
|
5
|
+
const _mod_fk10p5 = require('./url-filter.cjs');
|
|
6
|
+
exports.UrlFilter = _mod_fk10p5.UrlFilter;;
|
|
7
|
+
const _mod_mdmjap = require('./file-writer.cjs');
|
|
8
|
+
exports.FileWriter = _mod_mdmjap.FileWriter;;
|
|
9
|
+
const _mod_h74gd7 = require('./robots.cjs');
|
|
10
|
+
exports.RobotsHandler = _mod_h74gd7.RobotsHandler;;
|
|
11
|
+
const _mod_fi4008 = require('./resume.cjs');
|
|
12
|
+
exports.ResumeHandler = _mod_fi4008.ResumeHandler;;
|
|
13
|
+
const _mod_2oq0rl = require('./progress.cjs');
|
|
14
|
+
exports.ProgressReporter = _mod_2oq0rl.ProgressReporter;
|
|
15
|
+
exports.ProgressTracker = _mod_2oq0rl.ProgressTracker;
|
|
16
|
+
exports.parseSize = _mod_2oq0rl.parseSize;;
|
|
17
|
+
const _mod_mctdil = require('./link-converter.cjs');
|
|
18
|
+
exports.LinkConverter = _mod_mctdil.LinkConverter;;
|
|
19
|
+
const _mod_w0wki7 = require('./downloader.cjs');
|
|
20
|
+
exports.Downloader = _mod_w0wki7.Downloader;;
|
|
21
|
+
const _mod_sq65jo = require('./asset-organizer.cjs');
|
|
22
|
+
exports.AssetOrganizer = _mod_sq65jo.AssetOrganizer;
|
|
23
|
+
exports.DEFAULT_ASSET_FOLDERS = _mod_sq65jo.DEFAULT_ASSET_FOLDERS;;
|
|
24
|
+
const _mod_iafdrn = require('./download-cache.cjs');
|
|
25
|
+
exports.DownloadCache = _mod_iafdrn.DownloadCache;;
|
|
26
|
+
const _mod_dgbc2q = require('./filter-lists.cjs');
|
|
27
|
+
exports.EXECUTABLE_EXTENSIONS = _mod_dgbc2q.EXECUTABLE_EXTENSIONS;
|
|
28
|
+
exports.ARCHIVE_EXTENSIONS = _mod_dgbc2q.ARCHIVE_EXTENSIONS;
|
|
29
|
+
exports.DOCUMENT_EXTENSIONS = _mod_dgbc2q.DOCUMENT_EXTENSIONS;
|
|
30
|
+
exports.IMAGE_EXTENSIONS = _mod_dgbc2q.IMAGE_EXTENSIONS;
|
|
31
|
+
exports.VIDEO_EXTENSIONS = _mod_dgbc2q.VIDEO_EXTENSIONS;
|
|
32
|
+
exports.AUDIO_EXTENSIONS = _mod_dgbc2q.AUDIO_EXTENSIONS;
|
|
33
|
+
exports.FONT_EXTENSIONS = _mod_dgbc2q.FONT_EXTENSIONS;
|
|
34
|
+
exports.WEB_ASSET_EXTENSIONS = _mod_dgbc2q.WEB_ASSET_EXTENSIONS;
|
|
35
|
+
exports.DATA_EXTENSIONS = _mod_dgbc2q.DATA_EXTENSIONS;
|
|
36
|
+
exports.EXECUTABLE_MIME_TYPES = _mod_dgbc2q.EXECUTABLE_MIME_TYPES;
|
|
37
|
+
exports.ARCHIVE_MIME_TYPES = _mod_dgbc2q.ARCHIVE_MIME_TYPES;
|
|
38
|
+
exports.DOCUMENT_MIME_TYPES = _mod_dgbc2q.DOCUMENT_MIME_TYPES;
|
|
39
|
+
exports.IMAGE_MIME_TYPES = _mod_dgbc2q.IMAGE_MIME_TYPES;
|
|
40
|
+
exports.VIDEO_MIME_TYPES = _mod_dgbc2q.VIDEO_MIME_TYPES;
|
|
41
|
+
exports.AUDIO_MIME_TYPES = _mod_dgbc2q.AUDIO_MIME_TYPES;
|
|
42
|
+
exports.FONT_MIME_TYPES = _mod_dgbc2q.FONT_MIME_TYPES;
|
|
43
|
+
exports.WEB_ASSET_MIME_TYPES = _mod_dgbc2q.WEB_ASSET_MIME_TYPES;
|
|
44
|
+
exports.DATA_MIME_TYPES = _mod_dgbc2q.DATA_MIME_TYPES;
|
|
45
|
+
exports.SAFE_WEB_PRESET = _mod_dgbc2q.SAFE_WEB_PRESET;
|
|
46
|
+
exports.DOCUMENTS_ONLY_PRESET = _mod_dgbc2q.DOCUMENTS_ONLY_PRESET;
|
|
47
|
+
exports.NO_MEDIA_PRESET = _mod_dgbc2q.NO_MEDIA_PRESET;
|
|
48
|
+
exports.MINIMAL_MIRROR_PRESET = _mod_dgbc2q.MINIMAL_MIRROR_PRESET;
|
|
49
|
+
exports.TEXT_ONLY_PRESET = _mod_dgbc2q.TEXT_ONLY_PRESET;;
|
|
50
|
+
const { Downloader } = require('./downloader.cjs');
|
|
51
|
+
const rezo = require('../index.cjs');
|
|
52
|
+
const { promises: fs } = require("node:fs");
|
|
53
|
+
const { flattenWgetOptions } = require('./types.cjs');
|
|
54
|
+
const { parseProxyString } = require('../proxy/parse.cjs');
|
|
55
|
+
|
|
56
|
+
class Wget {
|
|
57
|
+
options = {};
|
|
58
|
+
downloader = null;
|
|
59
|
+
eventHandlers = new Map;
|
|
60
|
+
http;
|
|
61
|
+
constructor(options = {}) {
|
|
62
|
+
this.options = JSON.parse(JSON.stringify(options));
|
|
63
|
+
this.options.proxy = this.parseProxyString(this.options.proxy || "");
|
|
64
|
+
const timeout = this.options.download?.timeout ?? 30;
|
|
65
|
+
const maxRedirects = this.options.http?.maxRedirects;
|
|
66
|
+
const userAgent = this.options.http?.userAgent ?? "Rezo-Wget/1.0";
|
|
67
|
+
const headers = this.options.http?.headers ?? {};
|
|
68
|
+
const noCheckCert = this.options.http?.noCheckCertificate ?? false;
|
|
69
|
+
const proxyConfig = this.options.proxy;
|
|
70
|
+
const concurrency = this.options.download?.concurrency ?? 1;
|
|
71
|
+
const wait = this.options.download?.wait ?? 0;
|
|
72
|
+
this.http = rezo.create({
|
|
73
|
+
timeout: timeout * 1000,
|
|
74
|
+
maxRedirects,
|
|
75
|
+
headers: {
|
|
76
|
+
"User-Agent": userAgent,
|
|
77
|
+
...headers
|
|
78
|
+
},
|
|
79
|
+
rejectUnauthorized: !noCheckCert,
|
|
80
|
+
proxy: proxyConfig,
|
|
81
|
+
queueOptions: {
|
|
82
|
+
enable: true,
|
|
83
|
+
options: {
|
|
84
|
+
concurrency,
|
|
85
|
+
...wait > 0 ? {
|
|
86
|
+
interval: wait * 1000,
|
|
87
|
+
intervalCap: 1
|
|
88
|
+
} : {}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
parseProxyString(proxy) {
|
|
94
|
+
if (!proxy)
|
|
95
|
+
return;
|
|
96
|
+
if (typeof proxy === "string") {
|
|
97
|
+
return parseProxyString(proxy) || undefined;
|
|
98
|
+
}
|
|
99
|
+
return proxy;
|
|
100
|
+
}
|
|
101
|
+
on(event, handler) {
|
|
102
|
+
if (!this.eventHandlers.has(event)) {
|
|
103
|
+
this.eventHandlers.set(event, []);
|
|
104
|
+
}
|
|
105
|
+
this.eventHandlers.get(event).push(handler);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
off(event, handler) {
|
|
109
|
+
const handlers = this.eventHandlers.get(event);
|
|
110
|
+
if (handlers) {
|
|
111
|
+
const index = handlers.indexOf(handler);
|
|
112
|
+
if (index !== -1) {
|
|
113
|
+
handlers.splice(index, 1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
onProgress(callback) {
|
|
119
|
+
return this.on("progress", callback);
|
|
120
|
+
}
|
|
121
|
+
onDownload(callback) {
|
|
122
|
+
return this.on("complete", callback);
|
|
123
|
+
}
|
|
124
|
+
onError(callback) {
|
|
125
|
+
return this.on("error", (event) => callback(event.error, event.url));
|
|
126
|
+
}
|
|
127
|
+
onComplete(callback) {
|
|
128
|
+
return this.on("finish", (event) => callback(event.stats));
|
|
129
|
+
}
|
|
130
|
+
async get(url, options) {
|
|
131
|
+
const mergedOptions = this.mergeOptions(this.options, options);
|
|
132
|
+
const flatOptions = flattenWgetOptions(mergedOptions);
|
|
133
|
+
this.downloader = new Downloader(flatOptions, this.http);
|
|
134
|
+
this.attachEventHandlers();
|
|
135
|
+
return this.downloader.download(url);
|
|
136
|
+
}
|
|
137
|
+
async getAll(urls, options) {
|
|
138
|
+
const mergedOptions = this.mergeOptions(this.options, options);
|
|
139
|
+
const flatOptions = flattenWgetOptions(mergedOptions);
|
|
140
|
+
this.downloader = new Downloader(flatOptions, this.http);
|
|
141
|
+
this.attachEventHandlers();
|
|
142
|
+
return this.downloader.download(urls);
|
|
143
|
+
}
|
|
144
|
+
async mirror(url, options) {
|
|
145
|
+
const mirrorOptions = {
|
|
146
|
+
recursive: {
|
|
147
|
+
enabled: true,
|
|
148
|
+
mirror: true,
|
|
149
|
+
depth: 1 / 0
|
|
150
|
+
},
|
|
151
|
+
download: {
|
|
152
|
+
timestamping: true
|
|
153
|
+
},
|
|
154
|
+
...options
|
|
155
|
+
};
|
|
156
|
+
return this.get(url, mirrorOptions);
|
|
157
|
+
}
|
|
158
|
+
async fromFile(inputFile, options) {
|
|
159
|
+
const content = await fs.readFile(inputFile, "utf-8");
|
|
160
|
+
const urls = content.split(`
|
|
161
|
+
`).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
162
|
+
return this.getAll(urls, options);
|
|
163
|
+
}
|
|
164
|
+
recursive(depth) {
|
|
165
|
+
this.options.recursive = { ...this.options.recursive, enabled: true };
|
|
166
|
+
if (depth !== undefined) {
|
|
167
|
+
this.options.recursive.depth = depth;
|
|
168
|
+
}
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
depth(depth) {
|
|
172
|
+
this.options.recursive = { ...this.options.recursive, depth };
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
pageRequisites() {
|
|
176
|
+
this.options.recursive = { ...this.options.recursive, pageRequisites: true };
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
convertLinks() {
|
|
180
|
+
this.options.recursive = { ...this.options.recursive, convertLinks: true };
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
noParent() {
|
|
184
|
+
this.options.filter = { ...this.options.filter, noParent: true };
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
domains(...domains) {
|
|
188
|
+
this.options.filter = { ...this.options.filter, domains, spanHosts: true };
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
accept(...patterns) {
|
|
192
|
+
this.options.filter = { ...this.options.filter, accept: patterns };
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
reject(...patterns) {
|
|
196
|
+
this.options.filter = { ...this.options.filter, reject: patterns };
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
wait(seconds) {
|
|
200
|
+
this.options.download = { ...this.options.download, wait: seconds };
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
randomWait() {
|
|
204
|
+
this.options.download = { ...this.options.download, randomWait: true };
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
limitRate(rate) {
|
|
208
|
+
this.options.download = { ...this.options.download, limitRate: rate };
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
userAgent(ua) {
|
|
212
|
+
this.options.http = { ...this.options.http, userAgent: ua };
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
header(name, value) {
|
|
216
|
+
const headers = { ...this.options.http?.headers, [name]: value };
|
|
217
|
+
this.options.http = { ...this.options.http, headers };
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
outputDir(dir) {
|
|
221
|
+
this.options.download = { ...this.options.download, outputDir: dir };
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
output(filename) {
|
|
225
|
+
this.options.download = { ...this.options.download, output: filename };
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
continue() {
|
|
229
|
+
this.options.download = { ...this.options.download, continue: true };
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
timestamping() {
|
|
233
|
+
this.options.download = { ...this.options.download, timestamping: true };
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
concurrency(n) {
|
|
237
|
+
this.options.download = { ...this.options.download, concurrency: n };
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
noRobots() {
|
|
241
|
+
this.options.robots = { ...this.options.robots, enabled: false };
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
quiet() {
|
|
245
|
+
this.options.logging = { ...this.options.logging, quiet: true };
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
verbose() {
|
|
249
|
+
this.options.logging = { ...this.options.logging, verbose: true };
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
debug() {
|
|
253
|
+
this.options.logging = { ...this.options.logging, debug: true };
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
setProxy(proxy) {
|
|
257
|
+
this.options.proxy = this.parseProxyString(proxy || "");
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
timeout(seconds) {
|
|
261
|
+
this.options.download = { ...this.options.download, timeout: seconds };
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
tries(n) {
|
|
265
|
+
this.options.download = { ...this.options.download, tries: n };
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
spanHosts() {
|
|
269
|
+
this.options.filter = { ...this.options.filter, spanHosts: true };
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
noCheckCertificate() {
|
|
273
|
+
this.options.http = { ...this.options.http, noCheckCertificate: true };
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
cache(enabled = true) {
|
|
277
|
+
this.options.cache = enabled;
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
noCache() {
|
|
281
|
+
this.options.cache = false;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
organizeAssets(enabled = true) {
|
|
285
|
+
this.options.directories = { ...this.options.directories, organizeAssets: enabled };
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
assetFolders(folders) {
|
|
289
|
+
this.options.directories = { ...this.options.directories, assetFolders: folders };
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
excludeDirectories(directories) {
|
|
293
|
+
this.options.filter = { ...this.options.filter, excludeDirectories: directories };
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
includeDirectories(directories) {
|
|
297
|
+
this.options.filter = { ...this.options.filter, includeDirectories: directories };
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
excludeExtensions(extensions) {
|
|
301
|
+
this.options.filter = { ...this.options.filter, excludeExtensions: extensions };
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
excludeMimeTypes(mimeTypes) {
|
|
305
|
+
this.options.filter = { ...this.options.filter, excludeMimeTypes: mimeTypes };
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
includeTypes(types) {
|
|
309
|
+
this.options.filter = { ...this.options.filter, acceptAssetTypes: types };
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
excludeTypes(types) {
|
|
313
|
+
this.options.filter = { ...this.options.filter, rejectAssetTypes: types };
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
maxFileSize(bytes) {
|
|
317
|
+
this.options.filter = { ...this.options.filter, maxFileSize: bytes };
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
minFileSize(bytes) {
|
|
321
|
+
this.options.filter = { ...this.options.filter, minFileSize: bytes };
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
abort() {
|
|
325
|
+
if (this.downloader) {
|
|
326
|
+
this.downloader.abort();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
getOptions() {
|
|
330
|
+
return { ...this.options };
|
|
331
|
+
}
|
|
332
|
+
getUrlMap() {
|
|
333
|
+
return this.downloader?.getUrlMap() || null;
|
|
334
|
+
}
|
|
335
|
+
async destroy() {
|
|
336
|
+
if (this.downloader) {
|
|
337
|
+
await this.downloader.destroy();
|
|
338
|
+
this.downloader = null;
|
|
339
|
+
}
|
|
340
|
+
this.eventHandlers.clear();
|
|
341
|
+
}
|
|
342
|
+
attachEventHandlers() {
|
|
343
|
+
if (!this.downloader)
|
|
344
|
+
return;
|
|
345
|
+
for (const [event, handlers] of Array.from(this.eventHandlers.entries())) {
|
|
346
|
+
for (const handler of handlers) {
|
|
347
|
+
this.downloader.on(event, handler);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
mergeOptions(base, override) {
|
|
352
|
+
if (!override)
|
|
353
|
+
return { ...base };
|
|
354
|
+
const result = {};
|
|
355
|
+
const categories = [
|
|
356
|
+
"logging",
|
|
357
|
+
"download",
|
|
358
|
+
"directories",
|
|
359
|
+
"http",
|
|
360
|
+
"recursive",
|
|
361
|
+
"filter",
|
|
362
|
+
"robots",
|
|
363
|
+
"proxy",
|
|
364
|
+
"network",
|
|
365
|
+
"input",
|
|
366
|
+
"misc"
|
|
367
|
+
];
|
|
368
|
+
for (const cat of categories) {
|
|
369
|
+
const baseVal = base[cat];
|
|
370
|
+
const overrideVal = override[cat];
|
|
371
|
+
if (baseVal || overrideVal) {
|
|
372
|
+
result[cat] = {
|
|
373
|
+
...baseVal || {},
|
|
374
|
+
...overrideVal || {}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async function wget(url, options) {
|
|
382
|
+
const instance = new Wget(options);
|
|
383
|
+
return instance.get(url);
|
|
384
|
+
}
|
|
385
|
+
async function wgetAll(urls, options) {
|
|
386
|
+
const instance = new Wget(options);
|
|
387
|
+
return instance.getAll(urls);
|
|
388
|
+
}
|
|
389
|
+
function parseWgetArgs(args) {
|
|
390
|
+
const options = {
|
|
391
|
+
logging: {},
|
|
392
|
+
download: {},
|
|
393
|
+
directories: {},
|
|
394
|
+
http: {},
|
|
395
|
+
recursive: {},
|
|
396
|
+
filter: {},
|
|
397
|
+
robots: {},
|
|
398
|
+
proxy: undefined,
|
|
399
|
+
network: {},
|
|
400
|
+
input: {},
|
|
401
|
+
misc: {}
|
|
402
|
+
};
|
|
403
|
+
const urls = [];
|
|
404
|
+
for (let i = 0;i < args.length; i++) {
|
|
405
|
+
const arg = args[i];
|
|
406
|
+
if (!arg.startsWith("-")) {
|
|
407
|
+
urls.push(arg);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (arg.includes("=")) {
|
|
411
|
+
const [key, value] = arg.split("=");
|
|
412
|
+
setOption(options, key, value);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
switch (arg) {
|
|
416
|
+
case "-r":
|
|
417
|
+
case "--recursive":
|
|
418
|
+
options.recursive.enabled = true;
|
|
419
|
+
break;
|
|
420
|
+
case "-l":
|
|
421
|
+
case "--level":
|
|
422
|
+
options.recursive.depth = parseInt(args[++i], 10);
|
|
423
|
+
break;
|
|
424
|
+
case "-p":
|
|
425
|
+
case "--page-requisites":
|
|
426
|
+
options.recursive.pageRequisites = true;
|
|
427
|
+
break;
|
|
428
|
+
case "-k":
|
|
429
|
+
case "--convert-links":
|
|
430
|
+
options.recursive.convertLinks = true;
|
|
431
|
+
break;
|
|
432
|
+
case "-K":
|
|
433
|
+
case "--backup-converted":
|
|
434
|
+
options.recursive.backupConverted = true;
|
|
435
|
+
break;
|
|
436
|
+
case "-m":
|
|
437
|
+
case "--mirror":
|
|
438
|
+
options.recursive.mirror = true;
|
|
439
|
+
break;
|
|
440
|
+
case "-c":
|
|
441
|
+
case "--continue":
|
|
442
|
+
options.download.continue = true;
|
|
443
|
+
break;
|
|
444
|
+
case "-N":
|
|
445
|
+
case "--timestamping":
|
|
446
|
+
options.download.timestamping = true;
|
|
447
|
+
break;
|
|
448
|
+
case "-w":
|
|
449
|
+
case "--wait":
|
|
450
|
+
options.download.wait = parseFloat(args[++i]);
|
|
451
|
+
break;
|
|
452
|
+
case "--random-wait":
|
|
453
|
+
options.download.randomWait = true;
|
|
454
|
+
break;
|
|
455
|
+
case "-T":
|
|
456
|
+
case "--timeout":
|
|
457
|
+
options.download.timeout = parseInt(args[++i], 10);
|
|
458
|
+
break;
|
|
459
|
+
case "-t":
|
|
460
|
+
case "--tries":
|
|
461
|
+
options.download.tries = parseInt(args[++i], 10);
|
|
462
|
+
break;
|
|
463
|
+
case "-O":
|
|
464
|
+
case "--output-document":
|
|
465
|
+
options.download.output = args[++i];
|
|
466
|
+
break;
|
|
467
|
+
case "-P":
|
|
468
|
+
case "--directory-prefix":
|
|
469
|
+
options.download.outputDir = args[++i];
|
|
470
|
+
break;
|
|
471
|
+
case "-nc":
|
|
472
|
+
case "--no-clobber":
|
|
473
|
+
options.download.noClobber = true;
|
|
474
|
+
break;
|
|
475
|
+
case "-E":
|
|
476
|
+
case "--adjust-extension":
|
|
477
|
+
options.download.adjustExtension = true;
|
|
478
|
+
break;
|
|
479
|
+
case "-np":
|
|
480
|
+
case "--no-parent":
|
|
481
|
+
options.filter.noParent = true;
|
|
482
|
+
break;
|
|
483
|
+
case "-H":
|
|
484
|
+
case "--span-hosts":
|
|
485
|
+
options.filter.spanHosts = true;
|
|
486
|
+
break;
|
|
487
|
+
case "-A":
|
|
488
|
+
case "--accept":
|
|
489
|
+
options.filter.accept = args[++i];
|
|
490
|
+
break;
|
|
491
|
+
case "-R":
|
|
492
|
+
case "--reject":
|
|
493
|
+
options.filter.reject = args[++i];
|
|
494
|
+
break;
|
|
495
|
+
case "-D":
|
|
496
|
+
case "--domains":
|
|
497
|
+
options.filter.domains = args[++i];
|
|
498
|
+
break;
|
|
499
|
+
case "-q":
|
|
500
|
+
case "--quiet":
|
|
501
|
+
options.logging.quiet = true;
|
|
502
|
+
break;
|
|
503
|
+
case "-v":
|
|
504
|
+
case "--verbose":
|
|
505
|
+
options.logging.verbose = true;
|
|
506
|
+
break;
|
|
507
|
+
case "-d":
|
|
508
|
+
case "--debug":
|
|
509
|
+
options.logging.debug = true;
|
|
510
|
+
break;
|
|
511
|
+
case "-nv":
|
|
512
|
+
case "--no-verbose":
|
|
513
|
+
options.logging.noVerbose = true;
|
|
514
|
+
break;
|
|
515
|
+
case "-nd":
|
|
516
|
+
case "--no-directories":
|
|
517
|
+
options.directories.noDirectories = true;
|
|
518
|
+
break;
|
|
519
|
+
case "-x":
|
|
520
|
+
case "--force-directories":
|
|
521
|
+
options.directories.forceDirectories = true;
|
|
522
|
+
break;
|
|
523
|
+
case "-nH":
|
|
524
|
+
case "--no-host-directories":
|
|
525
|
+
options.directories.noHostDirectories = true;
|
|
526
|
+
break;
|
|
527
|
+
case "--no-check-certificate":
|
|
528
|
+
options.http.noCheckCertificate = true;
|
|
529
|
+
break;
|
|
530
|
+
case "-U":
|
|
531
|
+
case "--user-agent":
|
|
532
|
+
options.http.userAgent = args[++i];
|
|
533
|
+
break;
|
|
534
|
+
case "-i":
|
|
535
|
+
case "--input-file":
|
|
536
|
+
options.input.file = args[++i];
|
|
537
|
+
break;
|
|
538
|
+
default:
|
|
539
|
+
setOption(options, arg, args[++i]);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
for (const key of Object.keys(options)) {
|
|
543
|
+
if (options[key] && Object.keys(options[key]).length === 0) {
|
|
544
|
+
delete options[key];
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return { options, urls };
|
|
548
|
+
}
|
|
549
|
+
function setOption(options, key, value) {
|
|
550
|
+
const cleanKey = key.replace(/^--?/, "");
|
|
551
|
+
options.download = options.download || {};
|
|
552
|
+
options.recursive = options.recursive || {};
|
|
553
|
+
options.directories = options.directories || {};
|
|
554
|
+
options.http = options.http || {};
|
|
555
|
+
options.filter = options.filter || {};
|
|
556
|
+
options.proxy = options.proxy;
|
|
557
|
+
options.input = options.input || {};
|
|
558
|
+
switch (cleanKey) {
|
|
559
|
+
case "limit-rate":
|
|
560
|
+
options.download.limitRate = value;
|
|
561
|
+
break;
|
|
562
|
+
case "wait":
|
|
563
|
+
options.download.wait = parseFloat(value);
|
|
564
|
+
break;
|
|
565
|
+
case "timeout":
|
|
566
|
+
options.download.timeout = parseInt(value, 10);
|
|
567
|
+
break;
|
|
568
|
+
case "tries":
|
|
569
|
+
options.download.tries = parseInt(value, 10);
|
|
570
|
+
break;
|
|
571
|
+
case "quota":
|
|
572
|
+
options.download.quota = value;
|
|
573
|
+
break;
|
|
574
|
+
case "output-document":
|
|
575
|
+
options.download.output = value;
|
|
576
|
+
break;
|
|
577
|
+
case "directory-prefix":
|
|
578
|
+
options.download.outputDir = value;
|
|
579
|
+
break;
|
|
580
|
+
case "level":
|
|
581
|
+
options.recursive.depth = parseInt(value, 10);
|
|
582
|
+
break;
|
|
583
|
+
case "cut-dirs":
|
|
584
|
+
options.directories.cutDirs = parseInt(value, 10);
|
|
585
|
+
break;
|
|
586
|
+
case "user-agent":
|
|
587
|
+
options.http.userAgent = value;
|
|
588
|
+
break;
|
|
589
|
+
case "referer":
|
|
590
|
+
options.http.referer = value;
|
|
591
|
+
break;
|
|
592
|
+
case "http-user":
|
|
593
|
+
options.http.user = value;
|
|
594
|
+
break;
|
|
595
|
+
case "http-password":
|
|
596
|
+
options.http.password = value;
|
|
597
|
+
break;
|
|
598
|
+
case "accept":
|
|
599
|
+
options.filter.accept = value;
|
|
600
|
+
break;
|
|
601
|
+
case "reject":
|
|
602
|
+
options.filter.reject = value;
|
|
603
|
+
break;
|
|
604
|
+
case "domains":
|
|
605
|
+
options.filter.domains = value;
|
|
606
|
+
break;
|
|
607
|
+
case "exclude-domains":
|
|
608
|
+
options.filter.excludeDomains = value.split(",");
|
|
609
|
+
break;
|
|
610
|
+
case "include-directories":
|
|
611
|
+
options.filter.includeDirectories = value.split(",");
|
|
612
|
+
break;
|
|
613
|
+
case "exclude-directories":
|
|
614
|
+
options.filter.excludeDirectories = value.split(",");
|
|
615
|
+
break;
|
|
616
|
+
case "proxy":
|
|
617
|
+
options.proxy = value;
|
|
618
|
+
break;
|
|
619
|
+
case "input-file":
|
|
620
|
+
options.input.file = value;
|
|
621
|
+
break;
|
|
622
|
+
case "base":
|
|
623
|
+
options.input.base = value;
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
exports.Wget = Wget;
|
|
629
|
+
exports.wget = wget;
|
|
630
|
+
exports.wgetAll = wgetAll;
|
|
631
|
+
exports.parseWgetArgs = parseWgetArgs;
|
|
632
|
+
exports.default = Wget;
|
|
633
|
+
module.exports = Object.assign(Wget, exports);
|