@coflyn/mori 1.0.1 → 1.2.0
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/CHANGELOG.md +38 -0
- package/README.md +3 -1
- package/engine.js +1339 -76
- package/index.js +1471 -216
- package/package.json +2 -3
- package/bundle.js +0 -11
- package/scrapers-version.json +0 -7
package/engine.js
CHANGED
|
@@ -3,8 +3,10 @@ import os from "os";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { exec, execSync } from "child_process";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
+
import { createRequire } from "module";
|
|
6
7
|
import { DOMParser } from "linkedom";
|
|
7
8
|
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
8
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
11
|
const ROOT_DIR = path.resolve(__dirname, "..");
|
|
10
12
|
|
|
@@ -59,15 +61,81 @@ function cleanUrl(u) {
|
|
|
59
61
|
return u ? u.split("?")[0] : "";
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
const SAFARI_MOBILE_UA = CHROME_MOBILE_UA;
|
|
65
|
+
|
|
66
|
+
function decodeSnapSave(data) {
|
|
67
|
+
try {
|
|
68
|
+
const regex =
|
|
69
|
+
/eval\(function\(h,u,n,t,e,r\)\{.*?\}\("(.*?)",(\d+),"(.*?)",(\d+),(\d+),(\d+)\)\)/;
|
|
70
|
+
const match = data.match(regex);
|
|
71
|
+
if (match) {
|
|
72
|
+
const h = match[1],
|
|
73
|
+
u = parseInt(match[2]),
|
|
74
|
+
n = match[3],
|
|
75
|
+
t = parseInt(match[4]),
|
|
76
|
+
e = parseInt(match[5]);
|
|
77
|
+
const delimiter = n[e],
|
|
78
|
+
parts = h.split(delimiter);
|
|
79
|
+
let decoded = "";
|
|
80
|
+
for (let s of parts) {
|
|
81
|
+
if (s === "") continue;
|
|
82
|
+
let val = 0;
|
|
83
|
+
for (let j = 0; j < s.length; j++)
|
|
84
|
+
val += n.indexOf(s[j]) * Math.pow(e, s.length - 1 - j);
|
|
85
|
+
decoded += String.fromCharCode(val - t);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return decodeURIComponent(escape(decoded));
|
|
89
|
+
} catch {
|
|
90
|
+
return Buffer.from(decoded, "binary").toString("utf-8");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return data;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function extractFinalUrl(input) {
|
|
100
|
+
if (!input) return null;
|
|
101
|
+
let raw = input.trim().replace(/^["'\\]+|["'\\]+$/g, ""),
|
|
102
|
+
isRender = false;
|
|
103
|
+
if (raw.includes("get_progressApi") || raw.includes("get_progress")) {
|
|
104
|
+
isRender = true;
|
|
105
|
+
const tokenMatch = raw.match(/token=([^&'"]+)/);
|
|
106
|
+
if (tokenMatch) raw = tokenMatch[1];
|
|
107
|
+
}
|
|
108
|
+
if (raw.includes(".") && !raw.startsWith("http")) {
|
|
109
|
+
try {
|
|
110
|
+
const payloadPart = raw.split(".")[1];
|
|
111
|
+
if (payloadPart) {
|
|
112
|
+
const payload = JSON.parse(
|
|
113
|
+
Buffer.from(payloadPart, "base64").toString("utf-8")
|
|
114
|
+
);
|
|
115
|
+
if (payload.video_url)
|
|
116
|
+
return { url: payload.video_url, isRender: true };
|
|
117
|
+
if (payload.url) return { url: payload.url, isRender: false };
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {}
|
|
120
|
+
}
|
|
121
|
+
if (raw.startsWith("//")) return { url: "https:" + raw, isRender };
|
|
122
|
+
if (raw.startsWith("/"))
|
|
123
|
+
return { url: "https://snapsave.app" + raw, isRender };
|
|
124
|
+
return { url: raw, isRender };
|
|
125
|
+
}
|
|
126
|
+
|
|
62
127
|
globalThis.window.__moriDeps = {
|
|
63
128
|
utils: {
|
|
64
129
|
CHROME_UA,
|
|
65
130
|
CHROME_DESKTOP_UA,
|
|
66
131
|
CHROME_MOBILE_UA,
|
|
132
|
+
SAFARI_MOBILE_UA,
|
|
67
133
|
getUserAgent,
|
|
68
134
|
cleanUrl,
|
|
69
135
|
getCookiesFromHeaders,
|
|
70
136
|
serializeData,
|
|
137
|
+
decodeSnapSave,
|
|
138
|
+
extractFinalUrl,
|
|
71
139
|
},
|
|
72
140
|
urlUtils: {
|
|
73
141
|
getCleanUrl: (u) => (u ? u.trim() : ""),
|
|
@@ -144,6 +212,30 @@ export function readClipboard() {
|
|
|
144
212
|
});
|
|
145
213
|
}
|
|
146
214
|
|
|
215
|
+
export function writeClipboard(text) {
|
|
216
|
+
if (!text) return Promise.resolve(false);
|
|
217
|
+
const plat = process.platform;
|
|
218
|
+
return new Promise((resolve) => {
|
|
219
|
+
let proc;
|
|
220
|
+
if (plat === "darwin") {
|
|
221
|
+
proc = exec("pbcopy", (err) => resolve(!err));
|
|
222
|
+
} else if (plat === "win32") {
|
|
223
|
+
proc = exec("clip", (err) => resolve(!err));
|
|
224
|
+
} else {
|
|
225
|
+
proc = exec(
|
|
226
|
+
"which wl-copy >/dev/null 2>&1 && wl-copy || xclip -selection clipboard 2>/dev/null || xsel -b -i 2>/dev/null",
|
|
227
|
+
(err) => resolve(!err),
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
if (proc && proc.stdin) {
|
|
231
|
+
proc.stdin.write(String(text));
|
|
232
|
+
proc.stdin.end();
|
|
233
|
+
} else {
|
|
234
|
+
resolve(false);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
147
239
|
export function decodeHtmlEntities(str) {
|
|
148
240
|
if (!str || typeof str !== "string") return "";
|
|
149
241
|
return str
|
|
@@ -224,34 +316,51 @@ export function clearHistory() {
|
|
|
224
316
|
}
|
|
225
317
|
}
|
|
226
318
|
|
|
227
|
-
export function
|
|
319
|
+
export function deleteHistoryItems(indices, deleteFile = true) {
|
|
228
320
|
try {
|
|
229
321
|
const list = getHistory(200);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
fs.
|
|
239
|
-
|
|
240
|
-
|
|
322
|
+
const sortedIndices = [...new Set(indices)].sort((a, b) => b - a);
|
|
323
|
+
const deletedItems = [];
|
|
324
|
+
let filesDeletedCount = 0;
|
|
325
|
+
|
|
326
|
+
for (const idx of sortedIndices) {
|
|
327
|
+
if (idx >= 0 && idx < list.length) {
|
|
328
|
+
const [removed] = list.splice(idx, 1);
|
|
329
|
+
let fileDeleted = false;
|
|
330
|
+
if (deleteFile && removed.path && fs.existsSync(removed.path)) {
|
|
331
|
+
try {
|
|
332
|
+
fs.unlinkSync(removed.path);
|
|
333
|
+
fileDeleted = true;
|
|
334
|
+
filesDeletedCount++;
|
|
335
|
+
} catch (_) {}
|
|
336
|
+
}
|
|
337
|
+
deletedItems.push({ item: removed, fileDeleted });
|
|
338
|
+
}
|
|
241
339
|
}
|
|
242
340
|
|
|
243
341
|
fs.writeFileSync(HISTORY_PATH, JSON.stringify(list, null, 2), "utf8");
|
|
244
342
|
|
|
245
343
|
return {
|
|
246
344
|
success: true,
|
|
247
|
-
|
|
248
|
-
|
|
345
|
+
count: deletedItems.length,
|
|
346
|
+
filesDeletedCount,
|
|
347
|
+
deletedItems,
|
|
249
348
|
};
|
|
250
349
|
} catch (err) {
|
|
251
350
|
return { success: false, error: err.message };
|
|
252
351
|
}
|
|
253
352
|
}
|
|
254
353
|
|
|
354
|
+
export function deleteHistoryItem(index, deleteFile = true) {
|
|
355
|
+
const res = deleteHistoryItems([index], deleteFile);
|
|
356
|
+
if (!res.success) return res;
|
|
357
|
+
return {
|
|
358
|
+
success: true,
|
|
359
|
+
item: res.deletedItems[0]?.item,
|
|
360
|
+
fileDeleted: res.deletedItems[0]?.fileDeleted || false,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
255
364
|
export function getStats() {
|
|
256
365
|
const items = getHistory(200);
|
|
257
366
|
const totalDownloads = items.length;
|
|
@@ -287,18 +396,42 @@ export function getStats() {
|
|
|
287
396
|
};
|
|
288
397
|
}
|
|
289
398
|
|
|
290
|
-
// 3. OTA Hot-Patching Engine
|
|
399
|
+
// 3. OTA Hot-Patching Engine (Mori Core + Scrapr Engine)
|
|
291
400
|
const GITHUB_REPO = "coflyn/Mori";
|
|
292
401
|
const OTA_DIR = CONFIG_DIR;
|
|
293
402
|
export const OTA_BUNDLE_PATH = path.join(OTA_DIR, "scrapers-bundle.js");
|
|
294
403
|
export const OTA_META_PATH = path.join(OTA_DIR, "scrapers-meta.json");
|
|
295
404
|
|
|
405
|
+
export const SCRAPR_DIR = path.join(CONFIG_DIR, "scrapr");
|
|
406
|
+
export const SCRAPR_BUNDLE_PATH = path.join(SCRAPR_DIR, "scrapr-bundle.cjs");
|
|
407
|
+
export const SCRAPR_META_PATH = path.join(SCRAPR_DIR, "version.json");
|
|
408
|
+
export const SCRAPR_VERSION_URL =
|
|
409
|
+
"https://raw.githubusercontent.com/coflyn/scrapr/main/package.json";
|
|
410
|
+
export const SCRAPR_BUNDLE_URL =
|
|
411
|
+
"https://raw.githubusercontent.com/coflyn/scrapr/main/bundle.cjs";
|
|
412
|
+
const SCRAPR_FALLBACK_VERSION = "1.3.1";
|
|
413
|
+
|
|
414
|
+
export function isNewerSemver(latest, current) {
|
|
415
|
+
if (!latest || !current) return false;
|
|
416
|
+
const l = String(latest).replace(/^v/, "").split(".").map(Number);
|
|
417
|
+
const c = String(current).replace(/^v/, "").split(".").map(Number);
|
|
418
|
+
for (let i = 0; i < 3; i++) {
|
|
419
|
+
const lPart = l[i] || 0;
|
|
420
|
+
const cPart = c[i] || 0;
|
|
421
|
+
if (lPart > cPart) return true;
|
|
422
|
+
if (lPart < cPart) return false;
|
|
423
|
+
}
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
|
|
296
427
|
export function resetMori() {
|
|
297
428
|
const filesToDelete = [
|
|
298
429
|
CONFIG_PATH,
|
|
299
430
|
HISTORY_PATH,
|
|
300
431
|
OTA_BUNDLE_PATH,
|
|
301
432
|
OTA_META_PATH,
|
|
433
|
+
SCRAPR_BUNDLE_PATH,
|
|
434
|
+
SCRAPR_META_PATH,
|
|
302
435
|
];
|
|
303
436
|
for (const f of filesToDelete) {
|
|
304
437
|
if (fs.existsSync(f)) {
|
|
@@ -312,40 +445,331 @@ export function resetMori() {
|
|
|
312
445
|
export const OTA_VERSION_URL = `https://raw.githubusercontent.com/${GITHUB_REPO}/main/public/scrapers-version.json`;
|
|
313
446
|
export const OTA_BUNDLE_URL = `https://raw.githubusercontent.com/${GITHUB_REPO}/main/public/js/scrapers/bundle.js`;
|
|
314
447
|
|
|
315
|
-
function
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
448
|
+
export function isMoriInstalled() {
|
|
449
|
+
return fs.existsSync(OTA_BUNDLE_PATH);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function isScraprInstalled() {
|
|
453
|
+
return fs.existsSync(SCRAPR_BUNDLE_PATH);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export function getActiveScraperVersion() {
|
|
457
|
+
if (fs.existsSync(OTA_META_PATH)) {
|
|
458
|
+
try {
|
|
459
|
+
const meta = JSON.parse(fs.readFileSync(OTA_META_PATH, "utf8"));
|
|
460
|
+
return meta.scraperVersion || null;
|
|
461
|
+
} catch (_) {}
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
321
465
|
|
|
322
|
-
|
|
466
|
+
export function getActiveScraprVersion() {
|
|
467
|
+
if (fs.existsSync(SCRAPR_META_PATH)) {
|
|
323
468
|
try {
|
|
324
|
-
const
|
|
325
|
-
return
|
|
469
|
+
const meta = JSON.parse(fs.readFileSync(SCRAPR_META_PATH, "utf8"));
|
|
470
|
+
return meta.version || null;
|
|
326
471
|
} catch (_) {}
|
|
327
472
|
}
|
|
328
|
-
return
|
|
473
|
+
return null;
|
|
329
474
|
}
|
|
330
475
|
|
|
331
|
-
|
|
476
|
+
/**
|
|
477
|
+
* Downloads and installs Mori Core Engine into ~/.mori/
|
|
478
|
+
*/
|
|
479
|
+
export async function downloadMoriEngine(onProgress) {
|
|
480
|
+
if (onProgress) onProgress("Fetching Mori version metadata...");
|
|
481
|
+
const metaRes = await fetch(OTA_VERSION_URL, {
|
|
482
|
+
signal: AbortSignal.timeout(10000),
|
|
483
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
484
|
+
});
|
|
485
|
+
if (!metaRes.ok) throw new Error(`Failed to fetch Mori version (HTTP ${metaRes.status})`);
|
|
486
|
+
const meta = await metaRes.json();
|
|
487
|
+
|
|
488
|
+
if (onProgress) onProgress("Downloading Mori Engine bundle (~80 KB)...");
|
|
489
|
+
const bundleRes = await fetch(OTA_BUNDLE_URL, {
|
|
490
|
+
signal: AbortSignal.timeout(30000),
|
|
491
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
492
|
+
});
|
|
493
|
+
if (!bundleRes.ok) throw new Error(`Failed to download Mori bundle (HTTP ${bundleRes.status})`);
|
|
494
|
+
const bundleText = await bundleRes.text();
|
|
495
|
+
if (!bundleText || bundleText.length < 5000) {
|
|
496
|
+
throw new Error("Invalid Mori bundle payload received.");
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (!fs.existsSync(OTA_DIR)) {
|
|
500
|
+
fs.mkdirSync(OTA_DIR, { recursive: true });
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
fs.writeFileSync(OTA_BUNDLE_PATH, bundleText, "utf8");
|
|
504
|
+
fs.writeFileSync(
|
|
505
|
+
OTA_META_PATH,
|
|
506
|
+
JSON.stringify(
|
|
507
|
+
{
|
|
508
|
+
scraperVersion: meta.scraperVersion || "1.0.0",
|
|
509
|
+
updatedAt: Date.now(),
|
|
510
|
+
sourceHash: meta.sourceHash || "",
|
|
511
|
+
changelog: meta.changelog || "",
|
|
512
|
+
},
|
|
513
|
+
null,
|
|
514
|
+
2,
|
|
515
|
+
),
|
|
516
|
+
"utf8",
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
cachedMoriScrapers = null;
|
|
520
|
+
return { success: true, version: meta.scraperVersion || "1.0.0" };
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Downloads and installs Scrapr Engine into ~/.mori/scrapr/
|
|
525
|
+
*/
|
|
526
|
+
export async function downloadScraprEngine(onProgress) {
|
|
527
|
+
if (onProgress) onProgress("Fetching Scrapr metadata...");
|
|
528
|
+
let version = SCRAPR_FALLBACK_VERSION;
|
|
529
|
+
try {
|
|
530
|
+
const metaRes = await fetch(SCRAPR_VERSION_URL, {
|
|
531
|
+
signal: AbortSignal.timeout(10000),
|
|
532
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
533
|
+
});
|
|
534
|
+
if (metaRes.ok) {
|
|
535
|
+
const meta = await metaRes.json();
|
|
536
|
+
if (meta.version) version = meta.version;
|
|
537
|
+
}
|
|
538
|
+
} catch (_) {}
|
|
539
|
+
|
|
540
|
+
if (onProgress) onProgress("Downloading Scrapr Engine bundle (~2.7 MB)...");
|
|
541
|
+
let bundleText = "";
|
|
542
|
+
|
|
543
|
+
// 1. Try remote GitHub raw URL
|
|
544
|
+
try {
|
|
545
|
+
const bundleRes = await fetch(SCRAPR_BUNDLE_URL, {
|
|
546
|
+
signal: AbortSignal.timeout(45000),
|
|
547
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
548
|
+
});
|
|
549
|
+
if (bundleRes.ok) {
|
|
550
|
+
bundleText = await bundleRes.text();
|
|
551
|
+
}
|
|
552
|
+
} catch (_) {}
|
|
553
|
+
|
|
554
|
+
// 2. Local fallback during development if remote is not yet pushed
|
|
555
|
+
if (!bundleText || bundleText.length < 50000) {
|
|
556
|
+
const localDevScrapr = path.resolve(__dirname, "../../../scrapr/bundle.cjs");
|
|
557
|
+
if (fs.existsSync(localDevScrapr)) {
|
|
558
|
+
bundleText = fs.readFileSync(localDevScrapr, "utf8");
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (!bundleText || bundleText.length < 50000) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
"Failed to download Scrapr bundle. Ensure bundle.cjs is published or pushed to coflyn/scrapr.",
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (!fs.existsSync(SCRAPR_DIR)) {
|
|
569
|
+
fs.mkdirSync(SCRAPR_DIR, { recursive: true });
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
fs.writeFileSync(SCRAPR_BUNDLE_PATH, bundleText, "utf8");
|
|
573
|
+
fs.writeFileSync(
|
|
574
|
+
SCRAPR_META_PATH,
|
|
575
|
+
JSON.stringify(
|
|
576
|
+
{
|
|
577
|
+
version,
|
|
578
|
+
updatedAt: Date.now(),
|
|
579
|
+
},
|
|
580
|
+
null,
|
|
581
|
+
2,
|
|
582
|
+
),
|
|
583
|
+
"utf8",
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
cachedScrapr = null;
|
|
587
|
+
return { success: true, version };
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export function uninstallMoriEngine() {
|
|
591
|
+
if (fs.existsSync(OTA_BUNDLE_PATH)) {
|
|
592
|
+
try { fs.unlinkSync(OTA_BUNDLE_PATH); } catch (_) {}
|
|
593
|
+
}
|
|
332
594
|
if (fs.existsSync(OTA_META_PATH)) {
|
|
595
|
+
try { fs.unlinkSync(OTA_META_PATH); } catch (_) {}
|
|
596
|
+
}
|
|
597
|
+
cachedMoriScrapers = null;
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export function uninstallScraprEngine() {
|
|
602
|
+
if (fs.existsSync(SCRAPR_BUNDLE_PATH)) {
|
|
603
|
+
try { fs.unlinkSync(SCRAPR_BUNDLE_PATH); } catch (_) {}
|
|
604
|
+
}
|
|
605
|
+
if (fs.existsSync(SCRAPR_META_PATH)) {
|
|
606
|
+
try { fs.unlinkSync(SCRAPR_META_PATH); } catch (_) {}
|
|
607
|
+
}
|
|
608
|
+
cachedScrapr = null;
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export async function fetchMoriEngineHistory() {
|
|
613
|
+
try {
|
|
614
|
+
const res = await fetch(
|
|
615
|
+
`https://api.github.com/repos/${GITHUB_REPO}/commits?path=public/js/scrapers/bundle.js&per_page=15`,
|
|
616
|
+
{
|
|
617
|
+
signal: AbortSignal.timeout(10000),
|
|
618
|
+
headers: { "User-Agent": "Mori-CLI" },
|
|
619
|
+
},
|
|
620
|
+
);
|
|
621
|
+
if (!res.ok) return [];
|
|
622
|
+
const commits = await res.json();
|
|
623
|
+
if (!Array.isArray(commits)) return [];
|
|
624
|
+
return commits.map((c) => ({
|
|
625
|
+
sha: c.sha.slice(0, 7),
|
|
626
|
+
fullSha: c.sha,
|
|
627
|
+
message: (c.commit?.message || "").split("\n")[0].trim(),
|
|
628
|
+
date: c.commit?.author?.date || "",
|
|
629
|
+
}));
|
|
630
|
+
} catch (_) {
|
|
631
|
+
return [];
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export async function downloadMoriEngineByCommit(commitSha, onProgress) {
|
|
636
|
+
const shortSha = commitSha.slice(0, 7);
|
|
637
|
+
if (onProgress) onProgress(`Fetching Mori Core bundle at commit ${shortSha}...`);
|
|
638
|
+
|
|
639
|
+
const bundleUrl = `https://raw.githubusercontent.com/${GITHUB_REPO}/${commitSha}/public/js/scrapers/bundle.js`;
|
|
640
|
+
const metaUrl = `https://raw.githubusercontent.com/${GITHUB_REPO}/${commitSha}/public/scrapers-version.json`;
|
|
641
|
+
|
|
642
|
+
const [bundleRes, metaRes] = await Promise.all([
|
|
643
|
+
fetch(bundleUrl, {
|
|
644
|
+
signal: AbortSignal.timeout(30000),
|
|
645
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
646
|
+
}),
|
|
647
|
+
fetch(metaUrl, {
|
|
648
|
+
signal: AbortSignal.timeout(15000),
|
|
649
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
650
|
+
}).catch(() => null),
|
|
651
|
+
]);
|
|
652
|
+
|
|
653
|
+
if (!bundleRes.ok) {
|
|
654
|
+
throw new Error(`Failed to fetch bundle at commit ${shortSha}: HTTP ${bundleRes.status}`);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const bundleText = await bundleRes.text();
|
|
658
|
+
if (!bundleText || bundleText.length < 5000) {
|
|
659
|
+
throw new Error("Downloaded bundle is empty or invalid.");
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
let meta = { scraperVersion: shortSha };
|
|
663
|
+
if (metaRes && metaRes.ok) {
|
|
333
664
|
try {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
665
|
+
meta = await metaRes.json();
|
|
666
|
+
} catch (_) {}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
if (!fs.existsSync(OTA_DIR)) {
|
|
670
|
+
fs.mkdirSync(OTA_DIR, { recursive: true });
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
fs.writeFileSync(OTA_BUNDLE_PATH, bundleText, "utf8");
|
|
674
|
+
fs.writeFileSync(
|
|
675
|
+
OTA_META_PATH,
|
|
676
|
+
JSON.stringify(
|
|
677
|
+
{
|
|
678
|
+
scraperVersion: meta.scraperVersion || shortSha,
|
|
679
|
+
updatedAt: Date.now(),
|
|
680
|
+
sourceHash: meta.sourceHash || "",
|
|
681
|
+
changelog: meta.changelog || "",
|
|
682
|
+
commitSha: shortSha,
|
|
683
|
+
},
|
|
684
|
+
null,
|
|
685
|
+
2,
|
|
686
|
+
),
|
|
687
|
+
"utf8",
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
cachedMoriScrapers = null;
|
|
691
|
+
return { success: true, version: meta.scraperVersion || shortSha };
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export async function fetchScraprEngineVersions() {
|
|
695
|
+
try {
|
|
696
|
+
const res = await fetch("https://registry.npmjs.org/@coflyn/scrapr", {
|
|
697
|
+
signal: AbortSignal.timeout(10000),
|
|
698
|
+
headers: { "User-Agent": "Mori-CLI" },
|
|
699
|
+
});
|
|
700
|
+
if (!res.ok) return [];
|
|
701
|
+
const data = await res.json();
|
|
702
|
+
const versions = Object.keys(data.versions || {});
|
|
703
|
+
return versions.reverse();
|
|
704
|
+
} catch (_) {
|
|
705
|
+
return [];
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
export async function downloadScraprEngineVersion(targetVersion, onProgress) {
|
|
710
|
+
if (onProgress) onProgress(`Downloading Scrapr Engine v${targetVersion}...`);
|
|
711
|
+
let bundleText = "";
|
|
712
|
+
|
|
713
|
+
const urls = [
|
|
714
|
+
`https://unpkg.com/@coflyn/scrapr@${targetVersion}/bundle.cjs`,
|
|
715
|
+
`https://cdn.jsdelivr.net/npm/@coflyn/scrapr@${targetVersion}/bundle.cjs`,
|
|
716
|
+
`https://raw.githubusercontent.com/coflyn/scrapr/v${targetVersion}/bundle.cjs`,
|
|
717
|
+
`https://raw.githubusercontent.com/coflyn/scrapr/main/bundle.cjs`,
|
|
718
|
+
];
|
|
719
|
+
|
|
720
|
+
for (const u of urls) {
|
|
721
|
+
try {
|
|
722
|
+
const res = await fetch(u, {
|
|
723
|
+
signal: AbortSignal.timeout(30000),
|
|
724
|
+
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
725
|
+
});
|
|
726
|
+
if (res.ok) {
|
|
727
|
+
bundleText = await res.text();
|
|
728
|
+
if (bundleText && bundleText.length > 50000) break;
|
|
337
729
|
}
|
|
338
730
|
} catch (_) {}
|
|
339
731
|
}
|
|
340
|
-
|
|
732
|
+
|
|
733
|
+
if (!bundleText || bundleText.length < 50000) {
|
|
734
|
+
const localDevScrapr = path.resolve(__dirname, "../../../scrapr/bundle.cjs");
|
|
735
|
+
if (fs.existsSync(localDevScrapr)) {
|
|
736
|
+
bundleText = fs.readFileSync(localDevScrapr, "utf8");
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (!bundleText || bundleText.length < 50000) {
|
|
741
|
+
throw new Error(`Failed to download Scrapr v${targetVersion} bundle.`);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (!fs.existsSync(SCRAPR_DIR)) {
|
|
745
|
+
fs.mkdirSync(SCRAPR_DIR, { recursive: true });
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
fs.writeFileSync(SCRAPR_BUNDLE_PATH, bundleText, "utf8");
|
|
749
|
+
fs.writeFileSync(
|
|
750
|
+
SCRAPR_META_PATH,
|
|
751
|
+
JSON.stringify(
|
|
752
|
+
{
|
|
753
|
+
version: targetVersion,
|
|
754
|
+
updatedAt: Date.now(),
|
|
755
|
+
},
|
|
756
|
+
null,
|
|
757
|
+
2,
|
|
758
|
+
),
|
|
759
|
+
"utf8",
|
|
760
|
+
);
|
|
761
|
+
|
|
762
|
+
cachedScrapr = null;
|
|
763
|
+
return { success: true, version: targetVersion };
|
|
341
764
|
}
|
|
342
765
|
|
|
343
766
|
/**
|
|
344
|
-
* Checks for OTA updates from GitHub raw.
|
|
345
|
-
* If force=true, checks immediately and throws on failure.
|
|
346
|
-
* If force=false, checks silently with low timeout (2s).
|
|
767
|
+
* Checks for Mori Core OTA updates from GitHub raw.
|
|
347
768
|
*/
|
|
348
769
|
export async function checkForOtaUpdate(force = false) {
|
|
770
|
+
if (!isMoriInstalled()) {
|
|
771
|
+
return { updated: false, notInstalled: true };
|
|
772
|
+
}
|
|
349
773
|
try {
|
|
350
774
|
const metaRes = await fetch(OTA_VERSION_URL, {
|
|
351
775
|
signal: AbortSignal.timeout(force ? 8000 : 2500),
|
|
@@ -357,7 +781,6 @@ export async function checkForOtaUpdate(force = false) {
|
|
|
357
781
|
const currentVer = getActiveScraperVersion();
|
|
358
782
|
|
|
359
783
|
if (remoteMeta.scraperVersion && remoteMeta.scraperVersion > currentVer) {
|
|
360
|
-
// Pull new bundle
|
|
361
784
|
const bundleRes = await fetch(OTA_BUNDLE_URL, {
|
|
362
785
|
signal: AbortSignal.timeout(15000),
|
|
363
786
|
headers: { "User-Agent": "Mori-CLI-OTA", "Cache-Control": "no-cache" },
|
|
@@ -390,6 +813,8 @@ export async function checkForOtaUpdate(force = false) {
|
|
|
390
813
|
"utf8",
|
|
391
814
|
);
|
|
392
815
|
|
|
816
|
+
cachedMoriScrapers = null;
|
|
817
|
+
|
|
393
818
|
return {
|
|
394
819
|
updated: true,
|
|
395
820
|
oldVersion: currentVer,
|
|
@@ -405,53 +830,234 @@ export async function checkForOtaUpdate(force = false) {
|
|
|
405
830
|
}
|
|
406
831
|
}
|
|
407
832
|
|
|
408
|
-
|
|
409
|
-
|
|
833
|
+
/**
|
|
834
|
+
* Checks for Scrapr Engine OTA updates from GitHub raw.
|
|
835
|
+
*/
|
|
836
|
+
export async function checkForScraprOtaUpdate(force = false) {
|
|
837
|
+
if (!isScraprInstalled()) {
|
|
838
|
+
return { updated: false, notInstalled: true };
|
|
839
|
+
}
|
|
840
|
+
try {
|
|
841
|
+
const metaRes = await fetch(SCRAPR_VERSION_URL, {
|
|
842
|
+
signal: AbortSignal.timeout(force ? 8000 : 2500),
|
|
843
|
+
headers: { "User-Agent": "Mori-CLI-OTA", "Cache-Control": "no-cache" },
|
|
844
|
+
});
|
|
845
|
+
if (!metaRes.ok) return { updated: false, reason: "Fetch error" };
|
|
846
|
+
|
|
847
|
+
const remoteMeta = await metaRes.json();
|
|
848
|
+
const currentVer = getActiveScraprVersion();
|
|
849
|
+
|
|
850
|
+
if (remoteMeta.version && isNewerSemver(remoteMeta.version, currentVer)) {
|
|
851
|
+
const bundleRes = await fetch(SCRAPR_BUNDLE_URL, {
|
|
852
|
+
signal: AbortSignal.timeout(30000),
|
|
853
|
+
headers: { "User-Agent": "Mori-CLI-OTA", "Cache-Control": "no-cache" },
|
|
854
|
+
});
|
|
855
|
+
if (!bundleRes.ok)
|
|
856
|
+
return { updated: false, reason: "Scrapr bundle download error" };
|
|
857
|
+
|
|
858
|
+
const bundleText = await bundleRes.text();
|
|
859
|
+
if (!bundleText || bundleText.length < 50000) {
|
|
860
|
+
return { updated: false, reason: "Invalid Scrapr bundle payload" };
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
if (!fs.existsSync(SCRAPR_DIR)) {
|
|
864
|
+
fs.mkdirSync(SCRAPR_DIR, { recursive: true });
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
fs.writeFileSync(SCRAPR_BUNDLE_PATH, bundleText, "utf8");
|
|
868
|
+
fs.writeFileSync(
|
|
869
|
+
SCRAPR_META_PATH,
|
|
870
|
+
JSON.stringify(
|
|
871
|
+
{
|
|
872
|
+
version: remoteMeta.version,
|
|
873
|
+
updatedAt: Date.now(),
|
|
874
|
+
},
|
|
875
|
+
null,
|
|
876
|
+
2,
|
|
877
|
+
),
|
|
878
|
+
"utf8",
|
|
879
|
+
);
|
|
880
|
+
|
|
881
|
+
cachedScrapr = null;
|
|
882
|
+
|
|
883
|
+
return {
|
|
884
|
+
updated: true,
|
|
885
|
+
oldVersion: currentVer,
|
|
886
|
+
newVersion: remoteMeta.version,
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
return { updated: false, currentVersion: currentVer, latest: true };
|
|
891
|
+
} catch (err) {
|
|
892
|
+
if (force) throw err;
|
|
893
|
+
return { updated: false, error: err.message };
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// 3. Load Scraper Core (Mori Engine)
|
|
898
|
+
let cachedMoriScrapers = null;
|
|
899
|
+
|
|
900
|
+
export function loadScraperEngine() {
|
|
901
|
+
if (cachedMoriScrapers) return cachedMoriScrapers;
|
|
902
|
+
|
|
410
903
|
const localBundlePath = path.join(__dirname, "bundle.js");
|
|
411
904
|
const rootBundlePath = path.join(ROOT_DIR, "public/js/scrapers/bundle.js");
|
|
412
|
-
const bundledBundlePath = fs.existsSync(localBundlePath)
|
|
413
|
-
? localBundlePath
|
|
414
|
-
: rootBundlePath;
|
|
415
905
|
|
|
416
|
-
//
|
|
417
|
-
if (fs.existsSync(OTA_BUNDLE_PATH)
|
|
906
|
+
// Priority 1: ~/.mori/scrapers-bundle.js
|
|
907
|
+
if (fs.existsSync(OTA_BUNDLE_PATH)) {
|
|
418
908
|
try {
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return globalThis.__MoriCoreScrapers;
|
|
425
|
-
}
|
|
909
|
+
const patchCode = fs.readFileSync(OTA_BUNDLE_PATH, "utf8");
|
|
910
|
+
(0, eval)(patchCode);
|
|
911
|
+
if (globalThis.__MoriCoreScrapers) {
|
|
912
|
+
cachedMoriScrapers = globalThis.__MoriCoreScrapers;
|
|
913
|
+
return cachedMoriScrapers;
|
|
426
914
|
}
|
|
427
|
-
} catch (
|
|
428
|
-
// Safe-mode recovery: patch corrupted, delete it and fallback
|
|
915
|
+
} catch (_) {
|
|
429
916
|
try {
|
|
430
917
|
fs.unlinkSync(OTA_BUNDLE_PATH);
|
|
431
|
-
fs.unlinkSync(OTA_META_PATH);
|
|
918
|
+
if (fs.existsSync(OTA_META_PATH)) fs.unlinkSync(OTA_META_PATH);
|
|
432
919
|
} catch (_) {}
|
|
433
920
|
}
|
|
434
921
|
}
|
|
435
922
|
|
|
436
|
-
//
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
923
|
+
// Priority 2: Dev path fallback
|
|
924
|
+
const devPath = fs.existsSync(localBundlePath)
|
|
925
|
+
? localBundlePath
|
|
926
|
+
: fs.existsSync(rootBundlePath)
|
|
927
|
+
? rootBundlePath
|
|
928
|
+
: null;
|
|
929
|
+
|
|
930
|
+
if (devPath) {
|
|
931
|
+
try {
|
|
932
|
+
const bundleCode = fs.readFileSync(devPath, "utf8");
|
|
933
|
+
(0, eval)(bundleCode);
|
|
934
|
+
if (globalThis.__MoriCoreScrapers) {
|
|
935
|
+
cachedMoriScrapers = globalThis.__MoriCoreScrapers;
|
|
936
|
+
return cachedMoriScrapers;
|
|
937
|
+
}
|
|
938
|
+
} catch (_) {}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
throw new Error("Mori Engine not installed. Use /engine to install.");
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// 3b. Load Scrapr Engine (Engine 2)
|
|
945
|
+
let cachedScrapr = null;
|
|
946
|
+
|
|
947
|
+
export function loadScraprEngine() {
|
|
948
|
+
if (cachedScrapr) return cachedScrapr;
|
|
949
|
+
|
|
950
|
+
const localBundlePath = path.join(__dirname, "scrapr-bundle.cjs");
|
|
951
|
+
const devScraprPath = path.resolve(__dirname, "../../../scrapr/bundle.cjs");
|
|
952
|
+
|
|
953
|
+
// Priority 1: ~/.mori/scrapr/scrapr-bundle.cjs
|
|
954
|
+
if (fs.existsSync(SCRAPR_BUNDLE_PATH)) {
|
|
955
|
+
try {
|
|
956
|
+
cachedScrapr = require(SCRAPR_BUNDLE_PATH);
|
|
957
|
+
if (cachedScrapr && cachedScrapr.resolver) {
|
|
958
|
+
return cachedScrapr;
|
|
959
|
+
}
|
|
960
|
+
} catch (_) {
|
|
961
|
+
try {
|
|
962
|
+
fs.unlinkSync(SCRAPR_BUNDLE_PATH);
|
|
963
|
+
if (fs.existsSync(SCRAPR_META_PATH)) fs.unlinkSync(SCRAPR_META_PATH);
|
|
964
|
+
} catch (_) {}
|
|
965
|
+
}
|
|
441
966
|
}
|
|
442
967
|
|
|
443
|
-
|
|
444
|
-
|
|
968
|
+
// Priority 2: Dev path fallback
|
|
969
|
+
const fallback = fs.existsSync(localBundlePath)
|
|
970
|
+
? localBundlePath
|
|
971
|
+
: fs.existsSync(devScraprPath)
|
|
972
|
+
? devScraprPath
|
|
973
|
+
: null;
|
|
445
974
|
|
|
446
|
-
if (
|
|
447
|
-
|
|
975
|
+
if (fallback) {
|
|
976
|
+
try {
|
|
977
|
+
cachedScrapr = require(fallback);
|
|
978
|
+
if (cachedScrapr && cachedScrapr.resolver) {
|
|
979
|
+
return cachedScrapr;
|
|
980
|
+
}
|
|
981
|
+
} catch (_) {}
|
|
448
982
|
}
|
|
449
|
-
|
|
983
|
+
|
|
984
|
+
throw new Error("Scrapr Engine not installed. Use /engine to install.");
|
|
450
985
|
}
|
|
451
986
|
|
|
452
|
-
|
|
987
|
+
function getScraperFetch() {
|
|
988
|
+
try {
|
|
989
|
+
const s = loadScraperEngine();
|
|
990
|
+
if (s?.scraperFetch) return s.scraperFetch;
|
|
991
|
+
} catch (_) {}
|
|
992
|
+
return async function (opts) {
|
|
993
|
+
const res = await fetch(opts.url, {
|
|
994
|
+
method: opts.method || (opts.data ? "POST" : "GET"),
|
|
995
|
+
headers: opts.headers || {},
|
|
996
|
+
body: typeof opts.data === "object" ? JSON.stringify(opts.data) : opts.data,
|
|
997
|
+
});
|
|
998
|
+
const text = await res.text();
|
|
999
|
+
return opts.rawResponse
|
|
1000
|
+
? {
|
|
1001
|
+
status: res.status,
|
|
1002
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
1003
|
+
data: text,
|
|
1004
|
+
url: res.url,
|
|
1005
|
+
}
|
|
1006
|
+
: text;
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
453
1009
|
|
|
454
1010
|
// 4. Platform Detection
|
|
1011
|
+
export const SCRAPR_ONLY_PLATFORMS = new Set([
|
|
1012
|
+
"soundcloud",
|
|
1013
|
+
"mediafire",
|
|
1014
|
+
"sfile",
|
|
1015
|
+
"pixeldrain",
|
|
1016
|
+
"catbox",
|
|
1017
|
+
"krakenfiles",
|
|
1018
|
+
"gdrive",
|
|
1019
|
+
"doodstream",
|
|
1020
|
+
"safelinku",
|
|
1021
|
+
"sub2unlock",
|
|
1022
|
+
"rekonise",
|
|
1023
|
+
"unshorten",
|
|
1024
|
+
// Comic & Manga (Engine 2)
|
|
1025
|
+
"kiryuu",
|
|
1026
|
+
"komikcast",
|
|
1027
|
+
"mangadex",
|
|
1028
|
+
"komikindo",
|
|
1029
|
+
"komiku",
|
|
1030
|
+
"bacakomik",
|
|
1031
|
+
"manhwaindo",
|
|
1032
|
+
"asurascans",
|
|
1033
|
+
"mangabats",
|
|
1034
|
+
// Anime (Engine 2)
|
|
1035
|
+
"otakudesu",
|
|
1036
|
+
"nimegami",
|
|
1037
|
+
"gogoanime",
|
|
1038
|
+
"animetosho",
|
|
1039
|
+
]);
|
|
1040
|
+
|
|
1041
|
+
export const RESOLVER_LINK_PLATFORMS = new Set([
|
|
1042
|
+
"catbox",
|
|
1043
|
+
"pixeldrain",
|
|
1044
|
+
"safelinku",
|
|
1045
|
+
"sfile",
|
|
1046
|
+
"mediafire",
|
|
1047
|
+
"krakenfiles",
|
|
1048
|
+
"gdrive",
|
|
1049
|
+
"sub2unlock",
|
|
1050
|
+
"rekonise",
|
|
1051
|
+
"unshorten",
|
|
1052
|
+
]);
|
|
1053
|
+
|
|
1054
|
+
export const SHORTLINK_PLATFORMS = new Set([
|
|
1055
|
+
"safelinku",
|
|
1056
|
+
"sub2unlock",
|
|
1057
|
+
"rekonise",
|
|
1058
|
+
"unshorten",
|
|
1059
|
+
]);
|
|
1060
|
+
|
|
455
1061
|
export function detectPlatform(rawUrl) {
|
|
456
1062
|
if (!rawUrl || typeof rawUrl !== "string") return null;
|
|
457
1063
|
const url = rawUrl.toLowerCase();
|
|
@@ -467,6 +1073,8 @@ export function detectPlatform(rawUrl) {
|
|
|
467
1073
|
)
|
|
468
1074
|
return "twitter";
|
|
469
1075
|
if (url.includes("spotify.com")) return "spotify";
|
|
1076
|
+
if (url.includes("soundcloud.com") || url.includes("on.soundcloud.com"))
|
|
1077
|
+
return "soundcloud";
|
|
470
1078
|
if (url.includes("pinterest.com") || url.includes("pin.it"))
|
|
471
1079
|
return "pinterest";
|
|
472
1080
|
if (url.includes("music.apple.com")) return "applemusic";
|
|
@@ -502,10 +1110,113 @@ export function detectPlatform(rawUrl) {
|
|
|
502
1110
|
url.includes("tibibox")
|
|
503
1111
|
)
|
|
504
1112
|
return "terabox";
|
|
1113
|
+
// File hosts & Resolvers (Engine 2: Scrapr)
|
|
1114
|
+
if (url.includes("mediafire.com")) return "mediafire";
|
|
1115
|
+
if (url.includes("sfile.mobi") || url.includes("sfile.co")) return "sfile";
|
|
1116
|
+
if (url.includes("pixeldrain.com")) return "pixeldrain";
|
|
1117
|
+
if (
|
|
1118
|
+
url.includes("catbox.moe") ||
|
|
1119
|
+
url.includes("litterbox.catbox.moe") ||
|
|
1120
|
+
url.includes("litter.catbox.moe")
|
|
1121
|
+
)
|
|
1122
|
+
return "catbox";
|
|
1123
|
+
if (url.includes("krakenfiles.com")) return "krakenfiles";
|
|
1124
|
+
if (url.includes("drive.google.com") || url.includes("docs.google.com/file"))
|
|
1125
|
+
return "gdrive";
|
|
1126
|
+
if (
|
|
1127
|
+
/(?:doodstream\.com|ds2play\.com|doods\.pro|dood\.(?:to|so|ws|pm|wf|cx|sh|watch))/i.test(
|
|
1128
|
+
url,
|
|
1129
|
+
)
|
|
1130
|
+
)
|
|
1131
|
+
return "doodstream";
|
|
1132
|
+
if (
|
|
1133
|
+
url.includes("safelinku.com") ||
|
|
1134
|
+
url.includes("sfl.gl") ||
|
|
1135
|
+
url.includes("semawur.com") ||
|
|
1136
|
+
url.includes("safelink.id") ||
|
|
1137
|
+
url.includes("sfl.inc") ||
|
|
1138
|
+
url.includes("khaddavi.net")
|
|
1139
|
+
)
|
|
1140
|
+
return "safelinku";
|
|
1141
|
+
if (
|
|
1142
|
+
url.includes("sub2unlock.com") ||
|
|
1143
|
+
url.includes("sub2unlock.net") ||
|
|
1144
|
+
url.includes("sub2unlock.io") ||
|
|
1145
|
+
url.includes("sub2unlock.me") ||
|
|
1146
|
+
url.includes("sub4unlock.com") ||
|
|
1147
|
+
url.includes("sub4unlock.io") ||
|
|
1148
|
+
url.includes("sub4unlock.net")
|
|
1149
|
+
)
|
|
1150
|
+
return "sub2unlock";
|
|
1151
|
+
if (url.includes("rekonise.com")) return "rekonise";
|
|
1152
|
+
if (
|
|
1153
|
+
url.includes("bit.ly") ||
|
|
1154
|
+
url.includes("tinyurl.com") ||
|
|
1155
|
+
url.includes("dub.sh") ||
|
|
1156
|
+
url.includes("cutt.ly") ||
|
|
1157
|
+
url.includes("t.co/") ||
|
|
1158
|
+
url.includes("shorturl.at") ||
|
|
1159
|
+
url.includes("aka.ms")
|
|
1160
|
+
)
|
|
1161
|
+
return "unshorten";
|
|
1162
|
+
// Comic & Manga (Engine 2: Scrapr)
|
|
1163
|
+
if (url.includes("kiryuu.to") || url.includes("kiryuu.id")) return "kiryuu";
|
|
1164
|
+
if (
|
|
1165
|
+
url.includes("komikcast.info") ||
|
|
1166
|
+
url.includes("komikcast.ch") ||
|
|
1167
|
+
url.includes("komikcast.me") ||
|
|
1168
|
+
url.includes("komikcast.cz")
|
|
1169
|
+
)
|
|
1170
|
+
return "komikcast";
|
|
1171
|
+
if (url.includes("mangadex.org")) return "mangadex";
|
|
1172
|
+
if (
|
|
1173
|
+
url.includes("komikindo.ch") ||
|
|
1174
|
+
url.includes("komikindo.org") ||
|
|
1175
|
+
url.includes("komikindo.tv")
|
|
1176
|
+
)
|
|
1177
|
+
return "komikindo";
|
|
1178
|
+
if (url.includes("komiku.org") || url.includes("komiku.id")) return "komiku";
|
|
1179
|
+
if (
|
|
1180
|
+
url.includes("bacakomik.my") ||
|
|
1181
|
+
url.includes("bacakomik.co") ||
|
|
1182
|
+
url.includes("bacakomik.one")
|
|
1183
|
+
)
|
|
1184
|
+
return "bacakomik";
|
|
1185
|
+
if (
|
|
1186
|
+
url.includes("manhwaindo.my") ||
|
|
1187
|
+
url.includes("manhwaindo.id") ||
|
|
1188
|
+
url.includes("manhwaindo.org")
|
|
1189
|
+
)
|
|
1190
|
+
return "manhwaindo";
|
|
1191
|
+
if (
|
|
1192
|
+
url.includes("asurascans.com") ||
|
|
1193
|
+
url.includes("asuracomic.net") ||
|
|
1194
|
+
url.includes("asura.gg")
|
|
1195
|
+
)
|
|
1196
|
+
return "asurascans";
|
|
1197
|
+
if (url.includes("mangabats.com") || url.includes("mangabat.com"))
|
|
1198
|
+
return "mangabats";
|
|
1199
|
+
|
|
1200
|
+
// Anime (Engine 2: Scrapr)
|
|
1201
|
+
if (
|
|
1202
|
+
url.includes("otakudesu.blog") ||
|
|
1203
|
+
url.includes("otakudesu.cloud") ||
|
|
1204
|
+
url.includes("otakudesu.tube") ||
|
|
1205
|
+
url.includes("otakudesu.info")
|
|
1206
|
+
)
|
|
1207
|
+
return "otakudesu";
|
|
1208
|
+
if (url.includes("nimegami.id")) return "nimegami";
|
|
1209
|
+
if (
|
|
1210
|
+
url.includes("gogoanime") ||
|
|
1211
|
+
url.includes("gogoanimes") ||
|
|
1212
|
+
url.includes("anitaku")
|
|
1213
|
+
)
|
|
1214
|
+
return "gogoanime";
|
|
1215
|
+
if (url.includes("animetosho.org")) return "animetosho";
|
|
505
1216
|
return null;
|
|
506
1217
|
}
|
|
507
1218
|
|
|
508
|
-
export const
|
|
1219
|
+
export const MORI_PLATFORM_SERVERS = {
|
|
509
1220
|
tiktok: [
|
|
510
1221
|
{ id: "auto", name: "Auto (Server 1 → Server 2 fallback)" },
|
|
511
1222
|
{ id: "server1", name: "Server 1 (TikTokIO)" },
|
|
@@ -533,34 +1244,98 @@ export const PLATFORM_SERVERS = {
|
|
|
533
1244
|
],
|
|
534
1245
|
};
|
|
535
1246
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
1247
|
+
export const SCRAPR_PLATFORM_SERVERS = {
|
|
1248
|
+
tiktok: [
|
|
1249
|
+
{ id: "auto", name: "Auto (Cascade all 5 servers)" },
|
|
1250
|
+
{ id: "tiktokio", name: "TikTokIO (Fast, HD)" },
|
|
1251
|
+
{ id: "tikdownloader", name: "TikDownloader (Direct HD)" },
|
|
1252
|
+
{ id: "snaptik", name: "SnapTik (Popular, No Watermark)" },
|
|
1253
|
+
{ id: "savetik", name: "SaveTik (Alternative)" },
|
|
1254
|
+
{ id: "ssstik", name: "SSSTik (Fallback)" },
|
|
1255
|
+
],
|
|
1256
|
+
instagram: [
|
|
1257
|
+
{ id: "auto", name: "Auto (Cascade all 4 servers)" },
|
|
1258
|
+
{ id: "indown", name: "InDown (Fast, High Quality)" },
|
|
1259
|
+
{ id: "snapsave", name: "SnapSave (Reels/Stories/Posts)" },
|
|
1260
|
+
{ id: "snapinsta", name: "SnapInsta (Alternative)" },
|
|
1261
|
+
{ id: "direct", name: "Direct (Public Posts)" },
|
|
1262
|
+
],
|
|
1263
|
+
youtube: [
|
|
1264
|
+
{ id: "auto", name: "Auto (ytmp3.gg → ytmp3 fallback)" },
|
|
1265
|
+
{ id: "ytmp3gg", name: "ytmp3.gg (Fast, 1080p/720p/MP3)" },
|
|
1266
|
+
{ id: "ytmp3", name: "ytmp3 (Alternative)" },
|
|
1267
|
+
],
|
|
1268
|
+
twitter: [
|
|
1269
|
+
{ id: "auto", name: "Auto (Cascade all 4 servers)" },
|
|
1270
|
+
{ id: "tvd", name: "TwitterVideoDownloader (HD)" },
|
|
1271
|
+
{ id: "savetwt", name: "SaveTWT (Fast)" },
|
|
1272
|
+
{ id: "tweeload", name: "TweeLoad (Alternative)" },
|
|
1273
|
+
{ id: "direct", name: "Direct FXTwitter" },
|
|
1274
|
+
],
|
|
1275
|
+
spotify: [
|
|
1276
|
+
{ id: "auto", name: "Auto (Cascade all 4 servers)" },
|
|
1277
|
+
{ id: "spotidown", name: "SpotiDown (Fast 320kbps)" },
|
|
1278
|
+
{ id: "soundloaders", name: "SoundLoaders (Reliable)" },
|
|
1279
|
+
{ id: "spotmate", name: "SpotMate" },
|
|
1280
|
+
{ id: "spotisaver", name: "SpotiSaver" },
|
|
1281
|
+
],
|
|
1282
|
+
facebook: [
|
|
1283
|
+
{ id: "auto", name: "Auto (SnapSave → FDown fallback)" },
|
|
1284
|
+
{ id: "snapsave", name: "SnapSave (HD)" },
|
|
1285
|
+
{ id: "fdown", name: "FDown (Alternative)" },
|
|
1286
|
+
],
|
|
1287
|
+
pinterest: [
|
|
1288
|
+
{ id: "auto", name: "Auto (PinDown → Direct fallback)" },
|
|
1289
|
+
{ id: "pindown", name: "PinDown" },
|
|
1290
|
+
{ id: "direct", name: "Direct" },
|
|
1291
|
+
],
|
|
1292
|
+
bandcamp: [
|
|
1293
|
+
{ id: "auto", name: "Auto (Direct → BandcampDownloader fallback)" },
|
|
1294
|
+
{ id: "direct", name: "Direct Stream" },
|
|
1295
|
+
{ id: "bandcampdownloader", name: "BandcampDownloader" },
|
|
1296
|
+
],
|
|
1297
|
+
};
|
|
1298
|
+
|
|
1299
|
+
export function getPlatformServers(platform, engine = "auto") {
|
|
1300
|
+
if (engine === "scrapr") {
|
|
1301
|
+
return SCRAPR_PLATFORM_SERVERS[platform] || null;
|
|
541
1302
|
}
|
|
1303
|
+
if (engine === "mori") {
|
|
1304
|
+
return MORI_PLATFORM_SERVERS[platform] || null;
|
|
1305
|
+
}
|
|
1306
|
+
return SCRAPR_PLATFORM_SERVERS[platform] || MORI_PLATFORM_SERVERS[platform] || null;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
export const PLATFORM_SERVERS = MORI_PLATFORM_SERVERS;
|
|
542
1310
|
|
|
543
|
-
|
|
1311
|
+
// 5a. Engine 1: Mori Scraper Core
|
|
1312
|
+
export async function scrapeWithMori(url, platform, serverPreference = "auto") {
|
|
1313
|
+
const scrapers = loadScraperEngine();
|
|
544
1314
|
let srv = serverPreference;
|
|
545
1315
|
if (srv === "1") srv = "server1";
|
|
546
1316
|
if (srv === "2") srv = "server2";
|
|
547
1317
|
|
|
548
1318
|
let res = null;
|
|
1319
|
+
let usedServer = "";
|
|
549
1320
|
|
|
550
1321
|
switch (platform) {
|
|
551
1322
|
case "tiktok": {
|
|
552
1323
|
if (srv === "server2") {
|
|
553
1324
|
scrapers.setTikTokSource("tikdownloader");
|
|
554
1325
|
res = await scrapers.scrapeTikTok(url);
|
|
1326
|
+
usedServer = "TikDownloader";
|
|
555
1327
|
} else if (srv === "server1") {
|
|
556
1328
|
scrapers.setTikTokSource("tiktokio");
|
|
557
1329
|
res = await scrapers.scrapeTikTok(url);
|
|
1330
|
+
usedServer = "TikTokIO";
|
|
558
1331
|
} else {
|
|
559
1332
|
scrapers.setTikTokSource("tiktokio");
|
|
560
1333
|
res = await scrapers.scrapeTikTok(url);
|
|
1334
|
+
usedServer = "TikTokIO";
|
|
561
1335
|
if (!res?.status) {
|
|
562
1336
|
scrapers.setTikTokSource("tikdownloader");
|
|
563
1337
|
res = await scrapers.scrapeTikTok(url);
|
|
1338
|
+
usedServer = "TikDownloader";
|
|
564
1339
|
}
|
|
565
1340
|
}
|
|
566
1341
|
break;
|
|
@@ -569,15 +1344,19 @@ export async function scrapeUrl(url, serverPreference = "auto") {
|
|
|
569
1344
|
if (srv === "server2") {
|
|
570
1345
|
scrapers.setInstagramSource("savevid");
|
|
571
1346
|
res = await scrapers.scrapeInstagram(url);
|
|
1347
|
+
usedServer = "SaveVid";
|
|
572
1348
|
} else if (srv === "server1") {
|
|
573
1349
|
scrapers.setInstagramSource("indown");
|
|
574
1350
|
res = await scrapers.scrapeInstagram(url);
|
|
1351
|
+
usedServer = "InDown";
|
|
575
1352
|
} else {
|
|
576
1353
|
scrapers.setInstagramSource("indown");
|
|
577
1354
|
res = await scrapers.scrapeInstagram(url);
|
|
1355
|
+
usedServer = "InDown";
|
|
578
1356
|
if (!res?.status) {
|
|
579
1357
|
scrapers.setInstagramSource("savevid");
|
|
580
1358
|
res = await scrapers.scrapeInstagram(url);
|
|
1359
|
+
usedServer = "SaveVid";
|
|
581
1360
|
}
|
|
582
1361
|
}
|
|
583
1362
|
break;
|
|
@@ -586,15 +1365,19 @@ export async function scrapeUrl(url, serverPreference = "auto") {
|
|
|
586
1365
|
if (srv === "server2") {
|
|
587
1366
|
scrapers.setYouTubeSource("mobi");
|
|
588
1367
|
res = await scrapers.scrapeYouTube(url);
|
|
1368
|
+
usedServer = "ytmp3.mobi";
|
|
589
1369
|
} else if (srv === "server1") {
|
|
590
1370
|
scrapers.setYouTubeSource("gg");
|
|
591
1371
|
res = await scrapers.scrapeYouTube(url);
|
|
1372
|
+
usedServer = "ytmp3.gg";
|
|
592
1373
|
} else {
|
|
593
1374
|
scrapers.setYouTubeSource("gg");
|
|
594
1375
|
res = await scrapers.scrapeYouTube(url);
|
|
1376
|
+
usedServer = "ytmp3.gg";
|
|
595
1377
|
if (!res?.status) {
|
|
596
1378
|
scrapers.setYouTubeSource("mobi");
|
|
597
1379
|
res = await scrapers.scrapeYouTube(url);
|
|
1380
|
+
usedServer = "ytmp3.mobi";
|
|
598
1381
|
}
|
|
599
1382
|
}
|
|
600
1383
|
break;
|
|
@@ -603,15 +1386,19 @@ export async function scrapeUrl(url, serverPreference = "auto") {
|
|
|
603
1386
|
if (srv === "server2") {
|
|
604
1387
|
scrapers.setTwitterSource("savetwt");
|
|
605
1388
|
res = await scrapers.scrapeTwitter(url);
|
|
1389
|
+
usedServer = "SaveTWT";
|
|
606
1390
|
} else if (srv === "server1") {
|
|
607
1391
|
scrapers.setTwitterSource("tvd");
|
|
608
1392
|
res = await scrapers.scrapeTwitter(url);
|
|
1393
|
+
usedServer = "TwitterVideoDownloader";
|
|
609
1394
|
} else {
|
|
610
1395
|
scrapers.setTwitterSource("tvd");
|
|
611
1396
|
res = await scrapers.scrapeTwitter(url);
|
|
1397
|
+
usedServer = "TwitterVideoDownloader";
|
|
612
1398
|
if (!res?.status) {
|
|
613
1399
|
scrapers.setTwitterSource("savetwt");
|
|
614
1400
|
res = await scrapers.scrapeTwitter(url);
|
|
1401
|
+
usedServer = "SaveTWT";
|
|
615
1402
|
}
|
|
616
1403
|
}
|
|
617
1404
|
break;
|
|
@@ -620,51 +1407,66 @@ export async function scrapeUrl(url, serverPreference = "auto") {
|
|
|
620
1407
|
if (srv === "server2") {
|
|
621
1408
|
scrapers.setSpotifySource("soundloaders");
|
|
622
1409
|
res = await scrapers.scrapeSpotify(url);
|
|
1410
|
+
usedServer = "SoundLoaders";
|
|
623
1411
|
} else if (srv === "server1") {
|
|
624
1412
|
scrapers.setSpotifySource("spotidown");
|
|
625
1413
|
res = await scrapers.scrapeSpotify(url);
|
|
1414
|
+
usedServer = "SpotiDown";
|
|
626
1415
|
} else {
|
|
627
1416
|
scrapers.setSpotifySource("spotidown");
|
|
628
1417
|
res = await scrapers.scrapeSpotify(url);
|
|
1418
|
+
usedServer = "SpotiDown";
|
|
629
1419
|
if (!res?.status) {
|
|
630
1420
|
scrapers.setSpotifySource("soundloaders");
|
|
631
1421
|
res = await scrapers.scrapeSpotify(url);
|
|
1422
|
+
usedServer = "SoundLoaders";
|
|
632
1423
|
}
|
|
633
1424
|
}
|
|
634
1425
|
break;
|
|
635
1426
|
}
|
|
636
1427
|
case "pinterest":
|
|
637
1428
|
res = await scrapers.scrapePinterest(url);
|
|
1429
|
+
usedServer = "Pinterest";
|
|
638
1430
|
break;
|
|
639
1431
|
case "applemusic":
|
|
640
1432
|
res = await scrapers.scrapeAppleMusic(url);
|
|
1433
|
+
usedServer = "Aplmate";
|
|
641
1434
|
break;
|
|
642
1435
|
case "facebook":
|
|
643
1436
|
res = await scrapers.scrapeFacebook(url);
|
|
1437
|
+
usedServer = "SnapSave";
|
|
644
1438
|
break;
|
|
645
1439
|
case "rednote":
|
|
646
1440
|
res = await scrapers.scrapeRedNote(url);
|
|
1441
|
+
usedServer = "RedNote";
|
|
647
1442
|
break;
|
|
648
1443
|
case "douyin":
|
|
649
1444
|
res = await scrapers.scrapeDouyin(url);
|
|
1445
|
+
usedServer = "Douyin";
|
|
650
1446
|
break;
|
|
651
1447
|
case "bilibili":
|
|
652
1448
|
res = await scrapers.scrapeBilibili(url);
|
|
1449
|
+
usedServer = "Bilibili";
|
|
653
1450
|
break;
|
|
654
1451
|
case "threads":
|
|
655
1452
|
res = await scrapers.scrapeThreads(url);
|
|
1453
|
+
usedServer = "Threads";
|
|
656
1454
|
break;
|
|
657
1455
|
case "bandcamp":
|
|
658
1456
|
res = await scrapers.scrapeBandcamp(url);
|
|
1457
|
+
usedServer = "Bandcamp";
|
|
659
1458
|
break;
|
|
660
1459
|
case "pixiv":
|
|
661
1460
|
res = await scrapers.scrapePixiv(url);
|
|
1461
|
+
usedServer = "Pixiv";
|
|
662
1462
|
break;
|
|
663
1463
|
case "reddit":
|
|
664
1464
|
res = await scrapers.scrapeReddit(url);
|
|
1465
|
+
usedServer = "RapidSave";
|
|
665
1466
|
break;
|
|
666
1467
|
case "terabox":
|
|
667
1468
|
res = await scrapers.scrapeTeraBox(url);
|
|
1469
|
+
usedServer = "TeraBox";
|
|
668
1470
|
break;
|
|
669
1471
|
default:
|
|
670
1472
|
throw new Error(`Platform handler missing for ${platform}`);
|
|
@@ -681,16 +1483,460 @@ export async function scrapeUrl(url, serverPreference = "auto") {
|
|
|
681
1483
|
|
|
682
1484
|
return {
|
|
683
1485
|
platform,
|
|
1486
|
+
engine: "mori",
|
|
1487
|
+
server: usedServer,
|
|
684
1488
|
...result,
|
|
685
1489
|
};
|
|
686
1490
|
}
|
|
687
1491
|
|
|
1492
|
+
// 5b. Engine 2: Scrapr Stand-alone Scraper & Resolver
|
|
1493
|
+
export async function scrapeWithScrapr(
|
|
1494
|
+
url,
|
|
1495
|
+
platform,
|
|
1496
|
+
serverPreference = "auto",
|
|
1497
|
+
) {
|
|
1498
|
+
const scrapr = loadScraprEngine();
|
|
1499
|
+
let srv = serverPreference;
|
|
1500
|
+
if (srv === "1") srv = "server1";
|
|
1501
|
+
if (srv === "2") srv = "server2";
|
|
1502
|
+
|
|
1503
|
+
let res = null;
|
|
1504
|
+
let usedServer = "";
|
|
1505
|
+
|
|
1506
|
+
switch (platform) {
|
|
1507
|
+
case "tiktok": {
|
|
1508
|
+
if (srv === "tiktokio" || srv === "server1") {
|
|
1509
|
+
res = await scrapr.tiktok.tiktokio(url);
|
|
1510
|
+
usedServer = "TikTokIO";
|
|
1511
|
+
} else if (srv === "tikdownloader" || srv === "server2") {
|
|
1512
|
+
res = await scrapr.tiktok.tikdownloader(url);
|
|
1513
|
+
usedServer = "TikDownloader";
|
|
1514
|
+
} else if (srv === "snaptik") {
|
|
1515
|
+
res = await scrapr.tiktok.snaptik(url);
|
|
1516
|
+
usedServer = "SnapTik";
|
|
1517
|
+
} else if (srv === "savetik") {
|
|
1518
|
+
res = await scrapr.tiktok.savetik(url);
|
|
1519
|
+
usedServer = "SaveTik";
|
|
1520
|
+
} else if (srv === "ssstik") {
|
|
1521
|
+
res = await scrapr.tiktok.ssstik(url);
|
|
1522
|
+
usedServer = "SSSTik";
|
|
1523
|
+
} else {
|
|
1524
|
+
res = await scrapr.tiktok.tiktokio(url);
|
|
1525
|
+
usedServer = "TikTokIO";
|
|
1526
|
+
if (!res?.status) {
|
|
1527
|
+
res = await scrapr.tiktok.tikdownloader(url);
|
|
1528
|
+
usedServer = "TikDownloader";
|
|
1529
|
+
}
|
|
1530
|
+
if (!res?.status) {
|
|
1531
|
+
res = await scrapr.tiktok.snaptik(url);
|
|
1532
|
+
usedServer = "SnapTik";
|
|
1533
|
+
}
|
|
1534
|
+
if (!res?.status) {
|
|
1535
|
+
res = await scrapr.tiktok.savetik(url);
|
|
1536
|
+
usedServer = "SaveTik";
|
|
1537
|
+
}
|
|
1538
|
+
if (!res?.status) {
|
|
1539
|
+
res = await scrapr.tiktok.ssstik(url);
|
|
1540
|
+
usedServer = "SSSTik";
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
break;
|
|
1544
|
+
}
|
|
1545
|
+
case "instagram": {
|
|
1546
|
+
if (srv === "indown" || srv === "server1") {
|
|
1547
|
+
res = await scrapr.instagram.indown(url);
|
|
1548
|
+
usedServer = "InDown";
|
|
1549
|
+
} else if (srv === "snapsave" || srv === "server2") {
|
|
1550
|
+
res = await scrapr.instagram.snapsave(url);
|
|
1551
|
+
usedServer = "SnapSave";
|
|
1552
|
+
} else if (srv === "snapinsta") {
|
|
1553
|
+
res = await scrapr.instagram.snapinsta(url);
|
|
1554
|
+
usedServer = "SnapInsta";
|
|
1555
|
+
} else if (srv === "direct") {
|
|
1556
|
+
res = await scrapr.instagram.direct(url);
|
|
1557
|
+
usedServer = "Direct";
|
|
1558
|
+
} else {
|
|
1559
|
+
res = await scrapr.instagram.indown(url);
|
|
1560
|
+
usedServer = "InDown";
|
|
1561
|
+
if (!res?.status) {
|
|
1562
|
+
res = await scrapr.instagram.snapsave(url);
|
|
1563
|
+
usedServer = "SnapSave";
|
|
1564
|
+
}
|
|
1565
|
+
if (!res?.status) {
|
|
1566
|
+
res = await scrapr.instagram.snapinsta(url);
|
|
1567
|
+
usedServer = "SnapInsta";
|
|
1568
|
+
}
|
|
1569
|
+
if (!res?.status) {
|
|
1570
|
+
res = await scrapr.instagram.direct(url);
|
|
1571
|
+
usedServer = "Direct";
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1576
|
+
case "youtube": {
|
|
1577
|
+
if (srv === "ytmp3gg" || srv === "server1") {
|
|
1578
|
+
res = await scrapr.youtube.ytmp3gg(url);
|
|
1579
|
+
usedServer = "ytmp3.gg";
|
|
1580
|
+
} else if (srv === "ytmp3" || srv === "server2") {
|
|
1581
|
+
res = await scrapr.youtube.ytmp3(url);
|
|
1582
|
+
usedServer = "ytmp3";
|
|
1583
|
+
} else {
|
|
1584
|
+
res = await scrapr.youtube.ytmp3gg(url);
|
|
1585
|
+
usedServer = "ytmp3.gg";
|
|
1586
|
+
if (!res?.status) {
|
|
1587
|
+
res = await scrapr.youtube.ytmp3(url);
|
|
1588
|
+
usedServer = "ytmp3";
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
break;
|
|
1592
|
+
}
|
|
1593
|
+
case "twitter": {
|
|
1594
|
+
if (srv === "tvd" || srv === "server1") {
|
|
1595
|
+
res = await scrapr.twitter.tvd(url);
|
|
1596
|
+
usedServer = "TwitterVideoDownloader";
|
|
1597
|
+
} else if (srv === "savetwt" || srv === "server2") {
|
|
1598
|
+
res = await scrapr.twitter.savetwt(url);
|
|
1599
|
+
usedServer = "SaveTWT";
|
|
1600
|
+
} else if (srv === "tweeload") {
|
|
1601
|
+
res = await scrapr.twitter.tweeload(url);
|
|
1602
|
+
usedServer = "TweeLoad";
|
|
1603
|
+
} else if (srv === "direct") {
|
|
1604
|
+
res = await scrapr.twitter.direct(url);
|
|
1605
|
+
usedServer = "Direct FXTwitter";
|
|
1606
|
+
} else {
|
|
1607
|
+
res = await scrapr.twitter.tvd(url);
|
|
1608
|
+
usedServer = "TwitterVideoDownloader";
|
|
1609
|
+
if (!res?.status) {
|
|
1610
|
+
res = await scrapr.twitter.savetwt(url);
|
|
1611
|
+
usedServer = "SaveTWT";
|
|
1612
|
+
}
|
|
1613
|
+
if (!res?.status) {
|
|
1614
|
+
res = await scrapr.twitter.tweeload(url);
|
|
1615
|
+
usedServer = "TweeLoad";
|
|
1616
|
+
}
|
|
1617
|
+
if (!res?.status) {
|
|
1618
|
+
res = await scrapr.twitter.direct(url);
|
|
1619
|
+
usedServer = "Direct FXTwitter";
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
case "spotify": {
|
|
1625
|
+
if (srv === "spotidown" || srv === "server1") {
|
|
1626
|
+
res = await scrapr.spotify.spotidown(url);
|
|
1627
|
+
usedServer = "SpotiDown";
|
|
1628
|
+
} else if (srv === "soundloaders" || srv === "server2") {
|
|
1629
|
+
res = await scrapr.spotify.soundloaders(url);
|
|
1630
|
+
usedServer = "SoundLoaders";
|
|
1631
|
+
} else if (srv === "spotmate") {
|
|
1632
|
+
res = await scrapr.spotify.spotmate(url);
|
|
1633
|
+
usedServer = "SpotMate";
|
|
1634
|
+
} else if (srv === "spotisaver") {
|
|
1635
|
+
res = await scrapr.spotify.spotisaver(url);
|
|
1636
|
+
usedServer = "SpotiSaver";
|
|
1637
|
+
} else {
|
|
1638
|
+
res = await scrapr.spotify.spotidown(url);
|
|
1639
|
+
usedServer = "SpotiDown";
|
|
1640
|
+
if (!res?.status) {
|
|
1641
|
+
res = await scrapr.spotify.soundloaders(url);
|
|
1642
|
+
usedServer = "SoundLoaders";
|
|
1643
|
+
}
|
|
1644
|
+
if (!res?.status) {
|
|
1645
|
+
res = await scrapr.spotify.spotmate(url);
|
|
1646
|
+
usedServer = "SpotMate";
|
|
1647
|
+
}
|
|
1648
|
+
if (!res?.status) {
|
|
1649
|
+
res = await scrapr.spotify.spotisaver(url);
|
|
1650
|
+
usedServer = "SpotiSaver";
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
break;
|
|
1654
|
+
}
|
|
1655
|
+
case "soundcloud":
|
|
1656
|
+
res = await scrapr.soundcloud.klickaud(url);
|
|
1657
|
+
usedServer = "KlickAud";
|
|
1658
|
+
break;
|
|
1659
|
+
case "pinterest": {
|
|
1660
|
+
if (srv === "pindown" || srv === "server1") {
|
|
1661
|
+
res = await scrapr.pinterest.pindown(url);
|
|
1662
|
+
usedServer = "PinDown";
|
|
1663
|
+
} else if (srv === "direct" || srv === "server2") {
|
|
1664
|
+
res = await scrapr.pinterest.direct(url);
|
|
1665
|
+
usedServer = "Direct";
|
|
1666
|
+
} else {
|
|
1667
|
+
res = await scrapr.pinterest.pindown(url);
|
|
1668
|
+
usedServer = "PinDown";
|
|
1669
|
+
if (!res?.status) {
|
|
1670
|
+
res = await scrapr.pinterest.direct(url);
|
|
1671
|
+
usedServer = "Direct";
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
break;
|
|
1675
|
+
}
|
|
1676
|
+
case "facebook": {
|
|
1677
|
+
if (srv === "snapsave" || srv === "server1") {
|
|
1678
|
+
res = await scrapr.facebook.snapsave(url);
|
|
1679
|
+
usedServer = "SnapSave";
|
|
1680
|
+
} else if (srv === "fdown" || srv === "server2") {
|
|
1681
|
+
res = await scrapr.facebook.fdown(url);
|
|
1682
|
+
usedServer = "FDown";
|
|
1683
|
+
} else {
|
|
1684
|
+
res = await scrapr.facebook.snapsave(url);
|
|
1685
|
+
usedServer = "SnapSave";
|
|
1686
|
+
if (!res?.status) {
|
|
1687
|
+
res = await scrapr.facebook.fdown(url);
|
|
1688
|
+
usedServer = "FDown";
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
break;
|
|
1692
|
+
}
|
|
1693
|
+
case "threads":
|
|
1694
|
+
res = await scrapr.threads.threadster(url);
|
|
1695
|
+
usedServer = "Threadster";
|
|
1696
|
+
break;
|
|
1697
|
+
case "pixiv":
|
|
1698
|
+
res = await scrapr.pixiv.ajax(url);
|
|
1699
|
+
usedServer = "Pixiv";
|
|
1700
|
+
break;
|
|
1701
|
+
case "rednote":
|
|
1702
|
+
res = await scrapr.rednote.direct(url);
|
|
1703
|
+
usedServer = "RedNote";
|
|
1704
|
+
break;
|
|
1705
|
+
case "douyin":
|
|
1706
|
+
res = await scrapr.douyin.direct(url);
|
|
1707
|
+
usedServer = "Douyin";
|
|
1708
|
+
break;
|
|
1709
|
+
case "bilibili":
|
|
1710
|
+
res = await scrapr.bilibili.direct(url);
|
|
1711
|
+
usedServer = "Bilibili";
|
|
1712
|
+
break;
|
|
1713
|
+
case "reddit":
|
|
1714
|
+
res = await scrapr.reddit.rapidsave(url);
|
|
1715
|
+
usedServer = "RapidSave";
|
|
1716
|
+
break;
|
|
1717
|
+
case "terabox":
|
|
1718
|
+
res = await scrapr.terabox.sechno(url);
|
|
1719
|
+
usedServer = "Sechno";
|
|
1720
|
+
break;
|
|
1721
|
+
case "bandcamp": {
|
|
1722
|
+
res = await scrapr.bandcamp.direct(url);
|
|
1723
|
+
usedServer = "Direct";
|
|
1724
|
+
if (!res?.status) {
|
|
1725
|
+
res = await scrapr.bandcamp.bandcampdownloader(url);
|
|
1726
|
+
usedServer = "BandcampDownloader";
|
|
1727
|
+
}
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
case "applemusic":
|
|
1731
|
+
res = await scrapr.applemusic.aplmate(url);
|
|
1732
|
+
break;
|
|
1733
|
+
case "mediafire":
|
|
1734
|
+
res = await scrapr.resolver.mediafire(url);
|
|
1735
|
+
break;
|
|
1736
|
+
case "sfile":
|
|
1737
|
+
res = await scrapr.resolver.sfile(url);
|
|
1738
|
+
break;
|
|
1739
|
+
case "pixeldrain":
|
|
1740
|
+
res = await scrapr.resolver.pixeldrain(url);
|
|
1741
|
+
break;
|
|
1742
|
+
case "catbox":
|
|
1743
|
+
res = await scrapr.resolver.catbox(url);
|
|
1744
|
+
break;
|
|
1745
|
+
case "krakenfiles":
|
|
1746
|
+
res = await scrapr.resolver.krakenfiles(url);
|
|
1747
|
+
break;
|
|
1748
|
+
case "gdrive":
|
|
1749
|
+
res = await scrapr.resolver.gdrive(url);
|
|
1750
|
+
break;
|
|
1751
|
+
case "doodstream":
|
|
1752
|
+
res = await scrapr.resolver.doodstream(url);
|
|
1753
|
+
break;
|
|
1754
|
+
case "safelinku":
|
|
1755
|
+
res = await scrapr.resolver.safelinku(url);
|
|
1756
|
+
break;
|
|
1757
|
+
case "sub2unlock":
|
|
1758
|
+
res = await scrapr.resolver.sub2unlock(url);
|
|
1759
|
+
break;
|
|
1760
|
+
case "rekonise":
|
|
1761
|
+
res = await scrapr.resolver.rekonise(url);
|
|
1762
|
+
break;
|
|
1763
|
+
case "unshorten":
|
|
1764
|
+
res = await scrapr.resolver.unshorten(url);
|
|
1765
|
+
break;
|
|
1766
|
+
// Comic & Manga
|
|
1767
|
+
case "kiryuu":
|
|
1768
|
+
res = await scrapr.comic.kiryuu(url);
|
|
1769
|
+
usedServer = "Kiryuu";
|
|
1770
|
+
break;
|
|
1771
|
+
case "komikcast":
|
|
1772
|
+
res = await scrapr.comic.komikcast(url);
|
|
1773
|
+
usedServer = "Komikcast";
|
|
1774
|
+
break;
|
|
1775
|
+
case "mangadex":
|
|
1776
|
+
res = await scrapr.comic.mangadex(url);
|
|
1777
|
+
usedServer = "MangaDex";
|
|
1778
|
+
break;
|
|
1779
|
+
case "komikindo":
|
|
1780
|
+
res = await scrapr.comic.komikindo(url);
|
|
1781
|
+
usedServer = "Komikindo";
|
|
1782
|
+
break;
|
|
1783
|
+
case "komiku":
|
|
1784
|
+
res = await scrapr.comic.komiku(url);
|
|
1785
|
+
usedServer = "Komiku";
|
|
1786
|
+
break;
|
|
1787
|
+
case "bacakomik":
|
|
1788
|
+
res = await scrapr.comic.bacakomik(url);
|
|
1789
|
+
usedServer = "Bacakomik";
|
|
1790
|
+
break;
|
|
1791
|
+
case "manhwaindo":
|
|
1792
|
+
res = await scrapr.comic.manhwaindo(url);
|
|
1793
|
+
usedServer = "ManhwaIndo";
|
|
1794
|
+
break;
|
|
1795
|
+
case "asurascans":
|
|
1796
|
+
res = await scrapr.comic.asurascans(url);
|
|
1797
|
+
usedServer = "AsuraScans";
|
|
1798
|
+
break;
|
|
1799
|
+
case "mangabats":
|
|
1800
|
+
res = await scrapr.comic.mangabats(url);
|
|
1801
|
+
usedServer = "MangaBats";
|
|
1802
|
+
break;
|
|
1803
|
+
// Anime
|
|
1804
|
+
case "otakudesu":
|
|
1805
|
+
res = await scrapr.anime.otakudesu(url);
|
|
1806
|
+
usedServer = "Otakudesu";
|
|
1807
|
+
break;
|
|
1808
|
+
case "nimegami":
|
|
1809
|
+
res = await scrapr.anime.nimegami(url);
|
|
1810
|
+
usedServer = "Nimegami";
|
|
1811
|
+
break;
|
|
1812
|
+
case "gogoanime":
|
|
1813
|
+
res = await scrapr.anime.gogoanime(url);
|
|
1814
|
+
usedServer = "Gogoanime";
|
|
1815
|
+
break;
|
|
1816
|
+
case "animetosho":
|
|
1817
|
+
res = await scrapr.anime.animetosho(url);
|
|
1818
|
+
usedServer = "AnimeTosho";
|
|
1819
|
+
break;
|
|
1820
|
+
default:
|
|
1821
|
+
throw new Error(`Scrapr does not support platform: ${platform}`);
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
if (!res || !res.status) {
|
|
1825
|
+
throw new Error(
|
|
1826
|
+
res?.message || `Failed to scrape media with Scrapr from ${platform}.`,
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
const result = res.result || {};
|
|
1831
|
+
if (result.title) {
|
|
1832
|
+
result.title = decodeHtmlEntities(result.title);
|
|
1833
|
+
}
|
|
1834
|
+
if (result.author && typeof result.author === "object") {
|
|
1835
|
+
result.author =
|
|
1836
|
+
result.author.name ||
|
|
1837
|
+
result.author.username ||
|
|
1838
|
+
result.author.nickname ||
|
|
1839
|
+
"Creator";
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
let downloads = result.downloads || [];
|
|
1843
|
+
const primaryUrl = result.destinationUrl || result.url;
|
|
1844
|
+
if (!downloads.length && primaryUrl) {
|
|
1845
|
+
downloads = [
|
|
1846
|
+
{
|
|
1847
|
+
type: SHORTLINK_PLATFORMS.has(platform) ? "link" : (result.type || "file"),
|
|
1848
|
+
quality: SHORTLINK_PLATFORMS.has(platform) ? "Resolved Link" : "Direct Download",
|
|
1849
|
+
url: primaryUrl,
|
|
1850
|
+
},
|
|
1851
|
+
];
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
return {
|
|
1855
|
+
platform,
|
|
1856
|
+
engine: "scrapr",
|
|
1857
|
+
server: usedServer,
|
|
1858
|
+
...result,
|
|
1859
|
+
downloads,
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
// 5c. Unified Scraper with Engine Routing & Automatic Fallback
|
|
1864
|
+
export async function scrapeUrl(
|
|
1865
|
+
url,
|
|
1866
|
+
serverPreference = "auto",
|
|
1867
|
+
enginePreference = "auto",
|
|
1868
|
+
) {
|
|
1869
|
+
const platform = detectPlatform(url);
|
|
1870
|
+
if (!platform) {
|
|
1871
|
+
throw new Error("URL is not supported by Mori.");
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
const engine = (enginePreference || "auto").toLowerCase();
|
|
1875
|
+
const moriInstalled = isMoriInstalled();
|
|
1876
|
+
const scraprInstalled = isScraprInstalled();
|
|
1877
|
+
|
|
1878
|
+
if (!moriInstalled && !scraprInstalled) {
|
|
1879
|
+
throw new Error(
|
|
1880
|
+
"No scraper engine installed. Run 'mori' or use /engine to install.",
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
// If platform is exclusive to Scrapr
|
|
1885
|
+
if (SCRAPR_ONLY_PLATFORMS.has(platform)) {
|
|
1886
|
+
if (!scraprInstalled) {
|
|
1887
|
+
throw new Error(
|
|
1888
|
+
`Platform '${platform}' requires Scrapr engine. Install with /engine.`,
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
return scrapeWithScrapr(url, platform, serverPreference);
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// Engine 2 explicit
|
|
1895
|
+
if (engine === "scrapr") {
|
|
1896
|
+
if (!scraprInstalled) {
|
|
1897
|
+
throw new Error("Scrapr engine is not installed. Install with /engine.");
|
|
1898
|
+
}
|
|
1899
|
+
return scrapeWithScrapr(url, platform, serverPreference);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
// Engine 1 explicit
|
|
1903
|
+
if (engine === "mori") {
|
|
1904
|
+
if (!moriInstalled) {
|
|
1905
|
+
throw new Error("Mori engine is not installed. Install with /engine.");
|
|
1906
|
+
}
|
|
1907
|
+
return scrapeWithMori(url, platform, serverPreference);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
// Auto mode: single engine fallback
|
|
1911
|
+
if (!moriInstalled && scraprInstalled) {
|
|
1912
|
+
return scrapeWithScrapr(url, platform, serverPreference);
|
|
1913
|
+
}
|
|
1914
|
+
if (moriInstalled && !scraprInstalled) {
|
|
1915
|
+
return scrapeWithMori(url, platform, serverPreference);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// Both installed: Engine 1 (Mori) first -> fallback to Engine 2 (Scrapr)
|
|
1919
|
+
try {
|
|
1920
|
+
return await scrapeWithMori(url, platform, serverPreference);
|
|
1921
|
+
} catch (moriErr) {
|
|
1922
|
+
try {
|
|
1923
|
+
const scraprRes = await scrapeWithScrapr(url, platform, serverPreference);
|
|
1924
|
+
scraprRes.fallbackFromMori = true;
|
|
1925
|
+
return scraprRes;
|
|
1926
|
+
} catch (_) {
|
|
1927
|
+
throw moriErr;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
|
|
688
1932
|
// 6. Asynchronous Direct URL Resolvers
|
|
689
1933
|
export async function resolveUrl(url, onStatus) {
|
|
1934
|
+
const scraperFetch = getScraperFetch();
|
|
1935
|
+
|
|
690
1936
|
if (url.startsWith("applemusic_resolve:")) {
|
|
691
1937
|
if (onStatus) onStatus("Resolving Apple Music direct stream...");
|
|
692
1938
|
const payloadStr = url.replace("applemusic_resolve:", "");
|
|
693
|
-
const res = await
|
|
1939
|
+
const res = await scraperFetch({
|
|
694
1940
|
method: "POST",
|
|
695
1941
|
url: "https://aplmate.com/action/track",
|
|
696
1942
|
headers: {
|
|
@@ -746,7 +1992,7 @@ export async function resolveUrl(url, onStatus) {
|
|
|
746
1992
|
};
|
|
747
1993
|
if (cookiesStr) reqHeaders["Cookie"] = cookiesStr;
|
|
748
1994
|
|
|
749
|
-
const res = await
|
|
1995
|
+
const res = await scraperFetch({
|
|
750
1996
|
url: "https://spotidown.app/action/track",
|
|
751
1997
|
method: "POST",
|
|
752
1998
|
headers: reqHeaders,
|
|
@@ -799,19 +2045,19 @@ export async function resolveUrl(url, onStatus) {
|
|
|
799
2045
|
Accept: "*/*",
|
|
800
2046
|
};
|
|
801
2047
|
|
|
802
|
-
const initData = await
|
|
2048
|
+
const initData = await scraperFetch({
|
|
803
2049
|
url: `https://a.ymcdn.org/api/v1/init?p=y&23=1llum1n471&_=${Math.random()}`,
|
|
804
2050
|
headers: mobiHeaders,
|
|
805
2051
|
});
|
|
806
2052
|
|
|
807
2053
|
if (initData && !initData.error && initData.convertURL) {
|
|
808
|
-
let convData = await
|
|
2054
|
+
let convData = await scraperFetch({
|
|
809
2055
|
url: `${initData.convertURL}&v=${ytId}&f=${format}&_=${Math.random()}`,
|
|
810
2056
|
headers: mobiHeaders,
|
|
811
2057
|
});
|
|
812
2058
|
|
|
813
2059
|
while (convData && convData.redirect > 0 && convData.redirectURL) {
|
|
814
|
-
convData = await
|
|
2060
|
+
convData = await scraperFetch({
|
|
815
2061
|
url: `${convData.redirectURL}&v=${ytId}&f=${format}&_=${Math.random()}`,
|
|
816
2062
|
headers: mobiHeaders,
|
|
817
2063
|
});
|
|
@@ -825,7 +2071,7 @@ export async function resolveUrl(url, onStatus) {
|
|
|
825
2071
|
|
|
826
2072
|
while (progress < 3 && attempts < 25) {
|
|
827
2073
|
await new Promise((r) => setTimeout(r, 1200));
|
|
828
|
-
const pData = await
|
|
2074
|
+
const pData = await scraperFetch({
|
|
829
2075
|
url: `${progUrl}&_=${Math.random()}`,
|
|
830
2076
|
headers: mobiHeaders,
|
|
831
2077
|
});
|
|
@@ -864,11 +2110,17 @@ export function sanitizeFilename(title, ext = "mp4") {
|
|
|
864
2110
|
}
|
|
865
2111
|
|
|
866
2112
|
// 8. Stream Downloader with Progress Reporting
|
|
867
|
-
export async function downloadMediaFile(
|
|
2113
|
+
export async function downloadMediaFile(
|
|
2114
|
+
downloadUrl,
|
|
2115
|
+
outputPath,
|
|
2116
|
+
onProgress,
|
|
2117
|
+
extraHeaders = {},
|
|
2118
|
+
) {
|
|
868
2119
|
const res = await fetch(downloadUrl, {
|
|
869
2120
|
headers: {
|
|
870
2121
|
"User-Agent": CHROME_UA,
|
|
871
2122
|
Accept: "*/*",
|
|
2123
|
+
...extraHeaders,
|
|
872
2124
|
},
|
|
873
2125
|
});
|
|
874
2126
|
|
|
@@ -876,6 +2128,17 @@ export async function downloadMediaFile(downloadUrl, outputPath, onProgress) {
|
|
|
876
2128
|
throw new Error(`Download HTTP error: ${res.status} ${res.statusText}`);
|
|
877
2129
|
}
|
|
878
2130
|
|
|
2131
|
+
const contentType = (res.headers.get("content-type") || "").toLowerCase();
|
|
2132
|
+
if (
|
|
2133
|
+
contentType.includes("text/html") &&
|
|
2134
|
+
!outputPath.endsWith(".html") &&
|
|
2135
|
+
!outputPath.endsWith(".txt")
|
|
2136
|
+
) {
|
|
2137
|
+
throw new Error(
|
|
2138
|
+
"Received HTML webpage instead of a direct media stream. Please select a Direct MP4 stream.",
|
|
2139
|
+
);
|
|
2140
|
+
}
|
|
2141
|
+
|
|
879
2142
|
const totalBytes = parseInt(res.headers.get("content-length") || "0", 10);
|
|
880
2143
|
const fileStream = fs.createWriteStream(outputPath);
|
|
881
2144
|
|