@coflyn/mori 1.0.0 → 1.1.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/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import fs from "fs";
4
+ import os from "os";
4
5
  import path from "path";
5
6
  import { parseArgs } from "node:util";
6
7
  import * as p from "@clack/prompts";
@@ -8,12 +9,24 @@ import pc from "picocolors";
8
9
  import {
9
10
  detectPlatform,
10
11
  PLATFORM_SERVERS,
12
+ getPlatformServers,
11
13
  scrapeUrl,
12
14
  resolveUrl,
13
15
  sanitizeFilename,
14
16
  downloadMediaFile,
15
17
  checkForOtaUpdate,
16
18
  getActiveScraperVersion,
19
+ getActiveScraprVersion,
20
+ checkForScraprOtaUpdate,
21
+ isMoriInstalled,
22
+ isScraprInstalled,
23
+ downloadMoriEngine,
24
+ downloadScraprEngine,
25
+ uninstallMoriEngine,
26
+ uninstallScraprEngine,
27
+ RESOLVER_LINK_PLATFORMS,
28
+ SHORTLINK_PLATFORMS,
29
+ writeClipboard,
17
30
  getSavedConfig,
18
31
  saveConfig,
19
32
  openDirectory,
@@ -34,7 +47,7 @@ import {
34
47
  CHROME_UA,
35
48
  } from "./engine.js";
36
49
 
37
- const APP_VERSION = "1.0.0";
50
+ const APP_VERSION = "1.1.0";
38
51
 
39
52
  function isNewerVersion(latest, current) {
40
53
  if (!latest || !current) return false;
@@ -91,21 +104,203 @@ function renderProgressBar(percent, width = 22) {
91
104
  return pc.white("█".repeat(filled)) + pc.dim("░".repeat(empty));
92
105
  }
93
106
 
94
- function printBanner(coreVer) {
107
+ function formatPath(filePath) {
108
+ if (!filePath) return "";
109
+ const home = os.homedir();
110
+ if (filePath.startsWith(home)) {
111
+ return `~${filePath.slice(home.length)}`;
112
+ }
113
+ return filePath;
114
+ }
115
+
116
+ function truncateText(str, max = 72) {
117
+ if (!str || typeof str !== "string") return "";
118
+ const single = str.replace(/\r?\n|\r/g, " ").trim();
119
+ if (single.length <= max) return single;
120
+ return single.substring(0, max - 3) + "...";
121
+ }
122
+
123
+ function formatStreamItem(d, i, allDownloads = []) {
124
+ const typeStr = (d.type || "").toLowerCase();
125
+ const qualityStr = (d.quality || "").trim();
126
+
127
+ const isAudio =
128
+ typeStr.includes("audio") ||
129
+ typeStr.includes("music") ||
130
+ typeStr.includes("mp3");
131
+
132
+ const isPhoto = typeStr.includes("photo") || typeStr.includes("image");
133
+
134
+ if (isAudio) {
135
+ const qual =
136
+ qualityStr &&
137
+ !qualityStr.toLowerCase().includes("audio") &&
138
+ !qualityStr.toLowerCase().includes("music") &&
139
+ !qualityStr.toLowerCase().includes("mp3")
140
+ ? ` (${qualityStr})`
141
+ : "";
142
+ return {
143
+ label: `MP3 Audio${qual}`,
144
+ hint: "audio",
145
+ };
146
+ }
147
+
148
+ if (isPhoto) {
149
+ return {
150
+ label: `Photo #${i + 1}`,
151
+ hint: qualityStr || "image",
152
+ };
153
+ }
154
+
155
+ // Video stream
156
+ let resLabel = "";
157
+ if (qualityStr && qualityStr.toLowerCase() !== "video") {
158
+ resLabel = qualityStr;
159
+ } else if (/^\d+p$/i.test(d.type)) {
160
+ resLabel = d.type;
161
+ } else if (allDownloads.length > 0) {
162
+ const videoStreams = allDownloads.filter(
163
+ (item) =>
164
+ !item.type?.toLowerCase().includes("audio") &&
165
+ !item.type?.toLowerCase().includes("music") &&
166
+ !item.type?.toLowerCase().includes("photo"),
167
+ );
168
+ const vIdx = videoStreams.indexOf(d);
169
+ if (vIdx === 0) resLabel = "HD / Best Quality";
170
+ else if (vIdx === 1) resLabel = "Standard Quality";
171
+ else resLabel = `Option ${vIdx + 1}`;
172
+ } else {
173
+ resLabel = "Video";
174
+ }
175
+
176
+ const mirrorTag = d.isMirror ? " [Mirror]" : "";
177
+ return {
178
+ label: `${resLabel} Video${mirrorTag}`,
179
+ hint: mirrorTag ? "mirror" : "video",
180
+ };
181
+ }
182
+
183
+ const MORI_BANNER = [
184
+ "███╗ ███╗ ██████╗ ██████╗ ██╗",
185
+ "████╗ ████║██╔═══██╗██╔══██╗██║",
186
+ "██╔████╔██║██║ ██║██████╔╝██║",
187
+ "██║╚██╔╝██║██║ ██║██╔══██╗██║",
188
+ "██║ ╚═╝ ██║╚██████╔╝██║ ██║██║",
189
+ "╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝",
190
+ ];
191
+
192
+ function renderBanner() {
193
+ return MORI_BANNER.map(
194
+ (l) =>
195
+ " " +
196
+ l
197
+ .replace(/(█+)/g, pc.bold(pc.cyan("$1")))
198
+ .replace(/([╗║╚╝═]+)/g, pc.dim(pc.cyan("$1"))),
199
+ ).join("\n");
200
+ }
201
+
202
+ function printBanner(coreVer, scraprVer) {
203
+ console.log("\n" + renderBanner() + "\n");
204
+ const engines = [];
205
+ if (coreVer) engines.push(`mori v${coreVer}`);
206
+ if (scraprVer) engines.push(`scrapr v${scraprVer}`);
207
+ const engineStr =
208
+ engines.length > 0 ? engines.join(" • ") : "no engine installed";
95
209
  const brand =
96
210
  pc.bold(pc.inverse(" MORI ")) +
97
211
  " " +
98
212
  pc.bold(`v${APP_VERSION}`) +
99
213
  " " +
100
- pc.dim(`(core v${coreVer})`);
214
+ pc.dim(`(${engineStr})`);
101
215
  const sub = pc.dim(
102
- "Save anything, from anywhere. No watermarks. No tracking.",
216
+ "Save anything, from anywhere. Dual-Engine powered.",
103
217
  );
104
218
  p.intro(`${brand}\n ${sub}`);
105
219
  }
106
220
 
221
+ async function ensureEnginesInstalled() {
222
+ const moriInstalled = isMoriInstalled();
223
+ const scraprInstalled = isScraprInstalled();
224
+
225
+ if (moriInstalled || scraprInstalled) {
226
+ return true;
227
+ }
228
+
229
+ p.note(
230
+ `Welcome to Mori CLI!\n\n` +
231
+ `Mori is a lightweight CLI wrapper without pre-bundled scraper engines.\n` +
232
+ `Choose which engine(s) you would like to download to get started:`,
233
+ pc.bold("First-Time Engine Setup"),
234
+ );
235
+
236
+ const choice = await p.select({
237
+ message: "Which engine would you like to install?",
238
+ options: [
239
+ {
240
+ value: "both",
241
+ label: "Both (Mori Core + Scrapr) [Recommended]",
242
+ hint: "All 27 platforms: social media, audio, file hosts & unshorteners",
243
+ },
244
+ {
245
+ value: "scrapr",
246
+ label: "Scrapr Engine only (~2.7 MB)",
247
+ hint: "Stand-alone engine with file host resolvers (MediaFire, Sfile, GDrive, etc.)",
248
+ },
249
+ {
250
+ value: "mori",
251
+ label: "Mori Engine only (~80 KB)",
252
+ hint: "Ultra lightweight core scrapers (TikTok, IG, YouTube, Spotify, X, etc.)",
253
+ },
254
+ {
255
+ value: "skip",
256
+ label: "Skip for now",
257
+ hint: "Install manually later via /engine",
258
+ },
259
+ ],
260
+ initialValue: "both",
261
+ });
262
+
263
+ if (p.isCancel(choice) || choice === "skip") {
264
+ p.log.warn("Setup skipped. You will need to install an engine before scraping.");
265
+ return false;
266
+ }
267
+
268
+ if (choice === "both" || choice === "mori") {
269
+ const s = p.spinner();
270
+ s.start(pc.dim("Installing Mori Core Engine (~80 KB)..."));
271
+ try {
272
+ const res = await downloadMoriEngine();
273
+ s.stop(pc.bold(`✔ Mori Core Engine installed (v${res.version}).`));
274
+ } catch (err) {
275
+ s.stop(pc.bold(`✕ Failed to install Mori Engine: ${err.message}`));
276
+ }
277
+ }
278
+
279
+ if (choice === "both" || choice === "scrapr") {
280
+ const s = p.spinner();
281
+ s.start(pc.dim("Installing Scrapr Engine (~2.7 MB)..."));
282
+ try {
283
+ const res = await downloadScraprEngine();
284
+ s.stop(pc.bold(`✔ Scrapr Engine installed (v${res.version}).`));
285
+ } catch (err) {
286
+ s.stop(pc.bold(`✕ Failed to install Scrapr Engine: ${err.message}`));
287
+ }
288
+ }
289
+
290
+ const defEngine = choice === "both" ? "auto" : choice;
291
+ saveConfig({ defaultEngine: defEngine });
292
+
293
+ p.log.message(
294
+ `${pc.bold("● Default engine set:")} ${pc.white(defEngine)} ${pc.dim("(change anytime with /engine)")}`,
295
+ );
296
+
297
+ return isMoriInstalled() || isScraprInstalled();
298
+ }
299
+
107
300
  function printHelp() {
108
301
  console.log(`
302
+ ${renderBanner()}
303
+
109
304
  ${pc.bold(pc.inverse(" MORI CLI "))} ${pc.bold(`v${APP_VERSION}`)}
110
305
 
111
306
  ${pc.bold("USAGE:")}
@@ -113,20 +308,24 @@ ${pc.bold("USAGE:")}
113
308
  ${pc.white("npx @coflyn/mori")} ${pc.dim("[URL]")} ${pc.dim("[OPTIONS]")}
114
309
 
115
310
  ${pc.bold("OPTIONS:")}
116
- ${pc.white("-o, --output <dir>")} Destination folder (default: ${pc.dim("~/Downloads/Mori")})
117
- ${pc.white("-s, --server <1|2>")} Choose scraper server (TikTok, IG, YouTube, X, Spotify)
118
- ${pc.white("-a, --audio")} Download audio-only stream (MP3/M4A)
119
- ${pc.white("-p, --pdf")} Compile photo album directly into a single PDF
120
- ${pc.white("-c, --clip")} Auto-fetch link from system clipboard
121
- ${pc.white("-y, --yes")} Download best/first available stream automatically
122
- ${pc.white("-i, --info")} Inspect and display media details only
123
- ${pc.white("-u, --update")} Check and pull latest OTA scraper patch
124
- ${pc.white("-h, --help")} Show this documentation
125
- ${pc.white("-v, --version")} Print version number
126
-
127
- ${pc.bold("SUPPORTED PLATFORMS (16):")}
128
- ${pc.dim("TikTok • Instagram • YouTube • Twitter/X • Spotify • Pinterest • Facebook")}
129
- ${pc.dim("Bilibili • Reddit • RedNote • Threads • Pixiv • Bandcamp • Apple Music • Douyin • TeraBox")}
311
+ ${pc.white("-o, --output <dir>")} Destination folder (default: ${pc.dim("~/Downloads/Mori")})
312
+ ${pc.white("-e, --engine <auto|mori|scrapr>")} Scraper engine choice (default: ${pc.dim("auto")})
313
+ ${pc.white("-s, --server <1|2>")} Choose scraper server (TikTok, IG, YouTube, X, Spotify)
314
+ ${pc.white("-a, --audio")} Download audio-only stream (MP3/M4A)
315
+ ${pc.white("-p, --pdf")} Compile photo album directly into a single PDF
316
+ ${pc.white("-c, --clip")} Auto-fetch link from system clipboard
317
+ ${pc.white("-y, --yes")} Download best/first available stream automatically
318
+ ${pc.white("-i, --info")} Inspect and display media details only
319
+ ${pc.white("-u, --update")} Check and pull latest OTA scraper patches
320
+ ${pc.white("-h, --help")} Show this documentation
321
+ ${pc.white("-v, --version")} Print version number
322
+
323
+ ${pc.bold("SUPPORTED PLATFORMS (27 • DUAL-ENGINE):")}
324
+ ${pc.dim("Social & Video:")} TikTok • Instagram • YouTube • Twitter/X • Facebook • Douyin
325
+ Bilibili • Threads • RedNote • Reddit • Pixiv • Doodstream
326
+ ${pc.dim("Music & Audio :")} Spotify • SoundCloud • Apple Music • Bandcamp
327
+ ${pc.dim("Cloud & Files :")} TeraBox • MediaFire • Sfile • Catbox • Pixeldrain • Krakenfiles • GDrive
328
+ ${pc.dim("Resolvers :")} SafeLinkU • Sub2Unlock • Rekonise • Link Unshortener
130
329
 
131
330
  ${pc.bold("EXAMPLES:")}
132
331
  ${pc.dim("# Interactive")}
@@ -135,13 +334,13 @@ ${pc.bold("EXAMPLES:")}
135
334
  # Download link directly from clipboard
136
335
  mori --clip
137
336
 
138
- # Download audio-only (MP3)
139
- mori https://youtu.be/dQw4w9WgXcQ -a
337
+ # Use Scrapr engine explicitly
338
+ mori https://www.mediafire.com/file/... -e scrapr
140
339
 
141
- # Direct link with Server 2
142
- mori https://www.tiktok.com/@user/video/123456789 -s 2
340
+ # Download audio-only (MP3)
341
+ mori https://soundcloud.com/... -a
143
342
 
144
- # Check OTA scraper updates
343
+ # Check OTA updates for both engines
145
344
  mori --update
146
345
  `);
147
346
  }
@@ -163,16 +362,31 @@ async function runConcurrentPool(items, concurrency, fn) {
163
362
  }
164
363
 
165
364
  async function processDownloadItem({ item, meta, outputDir, index, total }) {
365
+ let detectedExt = "";
366
+ const rawFilename = item.filename || meta.filename;
367
+ if (rawFilename && path.extname(rawFilename)) {
368
+ detectedExt = path.extname(rawFilename).replace(/^\./, "");
369
+ } else if (item.url) {
370
+ try {
371
+ const uPath = new URL(item.url).pathname;
372
+ const uExt = path.extname(uPath).replace(/^\./, "");
373
+ if (uExt && uExt.length <= 5 && !uExt.includes("/")) detectedExt = uExt;
374
+ } catch (_) {}
375
+ }
376
+
166
377
  const ext =
167
- item.type?.toLowerCase().includes("mp3") ||
378
+ detectedExt ||
379
+ (item.type?.toLowerCase().includes("mp3") ||
168
380
  item.type?.toLowerCase().includes("audio")
169
381
  ? "mp3"
170
382
  : item.type?.toLowerCase().includes("photo") ||
171
383
  item.type?.toLowerCase().includes("image")
172
384
  ? "jpg"
173
- : "mp4";
385
+ : "mp4");
174
386
 
175
- let baseTitle = meta.title || "Media";
387
+ let baseTitle = rawFilename
388
+ ? path.basename(rawFilename, path.extname(rawFilename))
389
+ : (meta.title || "Media");
176
390
  if (total > 1) {
177
391
  baseTitle = `${baseTitle}_${index + 1}`;
178
392
  }
@@ -210,7 +424,7 @@ async function processDownloadItem({ item, meta, outputDir, index, total }) {
210
424
 
211
425
  process.stdout.write("\r\x1b[2K");
212
426
  p.log.message(
213
- `${pc.bold("● Saved:")} ${pc.bold(path.basename(destPath))} ${pc.dim(`(${path.relative(process.cwd(), destPath)})`)}`,
427
+ `${pc.bold("● Saved:")} ${pc.bold(path.basename(destPath))} ${pc.dim(`(${formatPath(destPath)})`)}`,
214
428
  );
215
429
  addToHistory({
216
430
  url: meta.url || "",
@@ -241,9 +455,11 @@ async function handleScrapeAndDownload(targetUrl, options) {
241
455
  }
242
456
 
243
457
  const savedConfig = getSavedConfig();
244
- // Dual Server Selection prompt for supported platforms
458
+ const engineChoice = options.engine || savedConfig.defaultEngine || "auto";
459
+
460
+ // Server Selection prompt for supported platforms based on active engine
245
461
  let serverChoice = options.server || savedConfig.defaultServer;
246
- const serverList = PLATFORM_SERVERS[platform];
462
+ const serverList = getPlatformServers(platform, engineChoice);
247
463
  const isInteractive = Boolean(process.stdin.isTTY);
248
464
  if (
249
465
  (!serverChoice || serverChoice === "auto") &&
@@ -273,7 +489,7 @@ async function handleScrapeAndDownload(targetUrl, options) {
273
489
 
274
490
  let media;
275
491
  try {
276
- media = await scrapeUrl(targetUrl, serverChoice || "auto");
492
+ media = await scrapeUrl(targetUrl, serverChoice || "auto", engineChoice);
277
493
  media.url = targetUrl;
278
494
  s.stop(pc.dim("Link analyzed."));
279
495
  } catch (err) {
@@ -281,20 +497,117 @@ async function handleScrapeAndDownload(targetUrl, options) {
281
497
  return false;
282
498
  }
283
499
 
500
+ const serverTag = media.server ? ` • ${media.server}` : "";
501
+ const engineBadge =
502
+ media.engine === "scrapr"
503
+ ? media.fallbackFromMori
504
+ ? pc.yellow(`[Scrapr • Fallback${serverTag}]`)
505
+ : pc.cyan(`[Scrapr Engine${serverTag}]`)
506
+ : pc.green(`[Mori Engine${serverTag}]`);
507
+
508
+ // Direct Link / Resolver Platforms (catbox, pixeldrain, sfl.gl, mediafire, sfile, etc.)
509
+ if (RESOLVER_LINK_PLATFORMS.has(media.platform)) {
510
+ // If it's a multi-file collection (e.g. catbox collection, pixeldrain list)
511
+ if (
512
+ media.type === "album" &&
513
+ Array.isArray(media.downloads) &&
514
+ media.downloads.length > 1
515
+ ) {
516
+ const urls = media.downloads.map((d) => d.url).filter(Boolean);
517
+ const urlText = urls.join("\n");
518
+ if (urlText) {
519
+ await writeClipboard(urlText);
520
+ }
521
+
522
+ const cardLines = [
523
+ `${pc.dim("Title :")} ${truncateText(media.title, 65) || "Collection Album"}`,
524
+ `${pc.dim("Engine :")} ${engineBadge}`,
525
+ `${pc.dim("Files :")} ${urls.length} item(s)`,
526
+ ];
527
+ p.note(cardLines.join("\n"), pc.bold(media.platform.toUpperCase()));
528
+
529
+ if (urls.length) {
530
+ p.log.success(
531
+ `${pc.bold(`✔ ${urls.length} URLs copied to clipboard:`)}`,
532
+ );
533
+ urls.slice(0, 5).forEach((u, i) => {
534
+ p.log.message(` ${pc.dim(`[${i + 1}]`)} ${pc.cyan(u)}`);
535
+ });
536
+ if (urls.length > 5) {
537
+ p.log.message(` ${pc.dim(`... and ${urls.length - 5} more`)}`);
538
+ }
539
+ }
540
+
541
+ addToHistory({
542
+ url: targetUrl,
543
+ title: media.title || targetUrl,
544
+ platform: media.platform,
545
+ filename: "",
546
+ path: urls[0] || "",
547
+ bytes: 0,
548
+ });
549
+
550
+ return true;
551
+ }
552
+
553
+ const directUrl =
554
+ media.destinationUrl ||
555
+ media.url ||
556
+ media.downloads?.[0]?.url ||
557
+ "";
558
+
559
+ if (directUrl) {
560
+ await writeClipboard(directUrl);
561
+ }
562
+
563
+ const cardLines = [
564
+ `${pc.dim("Title :")} ${truncateText(media.title || media.filename, 65) || "Direct / Resolved Link"}`,
565
+ `${pc.dim("Engine :")} ${engineBadge}`,
566
+ `${pc.dim("URL :")} ${truncateText(directUrl, 65)}`,
567
+ ];
568
+ if (media.size && media.size !== "Unknown") {
569
+ cardLines.push(`${pc.dim("Size :")} ${pc.white(media.size)}`);
570
+ }
571
+ p.note(cardLines.join("\n"), pc.bold(media.platform.toUpperCase()));
572
+
573
+ if (directUrl) {
574
+ p.log.success(
575
+ `${pc.bold("✔ URL copied to clipboard:")} ${pc.underline(pc.cyan(directUrl))}`,
576
+ );
577
+ }
578
+
579
+ addToHistory({
580
+ url: targetUrl,
581
+ title: media.title || media.filename || directUrl,
582
+ platform: media.platform,
583
+ filename: media.filename || "",
584
+ path: directUrl,
585
+ bytes: 0,
586
+ });
587
+
588
+ return true;
589
+ }
590
+
284
591
  // Metadata card with Platform name as title (e.g. TIKTOK, INSTAGRAM)
285
592
  const infoLines = [
286
- `${pc.dim("Title :")} ${media.title || "Untitled"}`,
287
- `${pc.dim("Creator :")} ${media.author || "Creator"}`,
288
- `${pc.dim("Streams :")} ${media.downloads?.length || 0} option(s)`,
593
+ `${pc.dim("Title :")} ${truncateText(media.title, 68) || "Untitled"}`,
594
+ `${pc.dim("Creator :")} ${truncateText(media.author, 40) || "Creator"}`,
595
+ `${pc.dim("Engine :")} ${engineBadge}`,
289
596
  ];
597
+ if (media.viaResolver) {
598
+ infoLines.push(
599
+ `${pc.dim("Via :")} ${pc.magenta(media.viaResolver.toUpperCase())} ${pc.dim(`(${media.originalShortUrl || ""})`)}`,
600
+ );
601
+ }
602
+ infoLines.push(`${pc.dim("Streams :")} ${media.downloads?.length || 0} option(s)`);
290
603
  p.note(infoLines.join("\n"), pc.bold(media.platform.toUpperCase()));
291
604
 
292
605
  if (options.info) {
293
606
  if (media.downloads?.length) {
294
- const streamLines = media.downloads.map(
295
- (d, idx) =>
296
- ` ${pc.bold(`[${idx + 1}]`)} ${pc.white(d.type || "Stream")} ${d.quality ? pc.dim(`(${d.quality})`) : ""} ${d.isMirror ? pc.dim("[Mirror]") : ""}`,
297
- );
607
+ const streamLines = media.downloads.map((d, idx) => {
608
+ const item = formatStreamItem(d, idx, media.downloads);
609
+ return ` ${pc.bold(`[${idx + 1}]`)} ${pc.white(item.label)}`;
610
+ });
298
611
  p.note(streamLines.join("\n"), pc.dim("Available Streams"));
299
612
  }
300
613
  return true;
@@ -664,11 +977,14 @@ async function handleScrapeAndDownload(targetUrl, options) {
664
977
  if (downloads.length > 1) {
665
978
  const formatChoice = await p.select({
666
979
  message: "Select stream:",
667
- options: downloads.map((d, i) => ({
668
- value: i,
669
- label: pc.bold(d.type || `Stream ${i + 1}`),
670
- hint: d.quality || (d.isMirror ? "Mirror" : ""),
671
- })),
980
+ options: downloads.map((d, i) => {
981
+ const item = formatStreamItem(d, i, downloads);
982
+ return {
983
+ value: i,
984
+ label: pc.bold(item.label),
985
+ hint: item.hint ? pc.dim(item.hint) : undefined,
986
+ };
987
+ }),
672
988
  });
673
989
 
674
990
  if (p.isCancel(formatChoice)) {
@@ -695,6 +1011,7 @@ async function main() {
695
1011
  args: process.argv.slice(2),
696
1012
  options: {
697
1013
  output: { type: "string", short: "o" },
1014
+ engine: { type: "string", short: "e" },
698
1015
  server: { type: "string", short: "s" },
699
1016
  audio: { type: "boolean", short: "a", default: false },
700
1017
  pdf: { type: "boolean", short: "p", default: false },
@@ -715,26 +1032,65 @@ async function main() {
715
1032
  }
716
1033
 
717
1034
  if (values.version) {
718
- console.log(
719
- `Mori CLI v${APP_VERSION} (core v${getActiveScraperVersion()})`,
720
- );
1035
+ const core = getActiveScraperVersion();
1036
+ const scrapr = getActiveScraprVersion();
1037
+ const parts = [];
1038
+ if (core) parts.push(`mori core v${core}`);
1039
+ if (scrapr) parts.push(`scrapr v${scrapr}`);
1040
+ const engStr = parts.length > 0 ? ` (${parts.join(" • ")})` : " (no engines installed)";
1041
+ console.log(`Mori CLI v${APP_VERSION}${engStr}`);
721
1042
  process.exit(0);
722
1043
  }
723
1044
 
724
1045
  // Handle manual OTA update flag
725
1046
  if (values.update) {
1047
+ const moriInst = isMoriInstalled();
1048
+ const scraprInst = isScraprInstalled();
1049
+
1050
+ if (!moriInst && !scraprInst) {
1051
+ p.log.warn("No scraper engines installed yet. Run 'mori' to set up engines.");
1052
+ process.exit(0);
1053
+ }
1054
+
726
1055
  const s = p.spinner();
727
- s.start(pc.dim("Checking remote scraper patch..."));
1056
+ s.start(pc.dim("Checking remote scraper updates..."));
728
1057
  try {
729
- const res = await checkForOtaUpdate(true);
730
- if (res.updated) {
731
- s.stop(
732
- pc.bold(`✔ Scrapers updated to v${res.newVersion}`) +
733
- (res.changelog ? pc.dim(` — ${res.changelog}`) : ""),
1058
+ const [moriRes, scraprRes] = await Promise.allSettled([
1059
+ moriInst ? checkForOtaUpdate(true) : Promise.resolve({ notInstalled: true }),
1060
+ scraprInst ? checkForScraprOtaUpdate(true) : Promise.resolve({ notInstalled: true }),
1061
+ ]);
1062
+
1063
+ const moriUpdate = moriRes.status === "fulfilled" ? moriRes.value : null;
1064
+ const scraprUpdate =
1065
+ scraprRes.status === "fulfilled" ? scraprRes.value : null;
1066
+
1067
+ const lines = [];
1068
+ if (moriUpdate?.updated) {
1069
+ lines.push(
1070
+ pc.bold(`✔ Mori Core updated to v${moriUpdate.newVersion}`) +
1071
+ (moriUpdate.changelog ? pc.dim(` — ${moriUpdate.changelog}`) : ""),
1072
+ );
1073
+ } else if (moriInst && moriUpdate) {
1074
+ lines.push(
1075
+ pc.dim(
1076
+ `Mori Core is up to date (v${moriUpdate.currentVersion || getActiveScraperVersion()}).`,
1077
+ ),
1078
+ );
1079
+ }
1080
+
1081
+ if (scraprUpdate?.updated) {
1082
+ lines.push(
1083
+ pc.bold(`✔ Scrapr Engine updated to v${scraprUpdate.newVersion}`),
1084
+ );
1085
+ } else if (scraprInst && scraprUpdate) {
1086
+ lines.push(
1087
+ pc.dim(
1088
+ `Scrapr Engine is up to date (v${scraprUpdate.currentVersion || getActiveScraprVersion()}).`,
1089
+ ),
734
1090
  );
735
- } else {
736
- s.stop(pc.dim(`Scrapers already up to date (v${res.currentVersion}).`));
737
1091
  }
1092
+
1093
+ s.stop(lines.join("\n"));
738
1094
  } catch (err) {
739
1095
  s.stop(pc.bold(`✕ OTA check failed: ${err.message}`));
740
1096
  }
@@ -742,20 +1098,42 @@ async function main() {
742
1098
  }
743
1099
 
744
1100
  const coreVer = getActiveScraperVersion();
745
- printBanner(coreVer);
1101
+ const scraprVer = getActiveScraprVersion();
1102
+ printBanner(coreVer, scraprVer);
746
1103
 
747
- // Background non-blocking silent OTA check (timeout 2s)
748
- checkForOtaUpdate(false)
749
- .then((ota) => {
750
- if (ota?.updated) {
751
- p.log.message(
752
- pc.dim(
753
- `● New scraper patch installed in background: v${ota.newVersion}`,
754
- ),
755
- );
756
- }
757
- })
758
- .catch(() => {});
1104
+ // Check if first-run engine setup is required
1105
+ if (!isMoriInstalled() && !isScraprInstalled()) {
1106
+ await ensureEnginesInstalled();
1107
+ }
1108
+
1109
+ // Background non-blocking silent OTA check (only for installed engines)
1110
+ if (isMoriInstalled()) {
1111
+ checkForOtaUpdate(false)
1112
+ .then((ota) => {
1113
+ if (ota?.updated) {
1114
+ p.log.message(
1115
+ pc.dim(
1116
+ `● New Mori Core patch installed in background: v${ota.newVersion}`,
1117
+ ),
1118
+ );
1119
+ }
1120
+ })
1121
+ .catch(() => {});
1122
+ }
1123
+
1124
+ if (isScraprInstalled()) {
1125
+ checkForScraprOtaUpdate(false)
1126
+ .then((scraprOta) => {
1127
+ if (scraprOta?.updated) {
1128
+ p.log.message(
1129
+ pc.dim(
1130
+ `● New Scrapr Engine bundle installed in background: v${scraprOta.newVersion}`,
1131
+ ),
1132
+ );
1133
+ }
1134
+ })
1135
+ .catch(() => {});
1136
+ }
759
1137
 
760
1138
  const cliUpdatePromise = checkCliUpdate();
761
1139
 
@@ -859,12 +1237,13 @@ async function main() {
859
1237
  case "platform":
860
1238
  case "platforms": {
861
1239
  const platformList = [
862
- `${pc.bold("Video :")} TikTok, Douyin, YouTube, Instagram, Facebook, Bilibili, Reddit, Threads, Twitter/X`,
863
- `${pc.bold("Audio :")} Spotify, Apple Music, Bandcamp`,
864
- `${pc.bold("Photo :")} Pinterest, Pixiv, RedNote (Xiaohongshu)`,
865
- `${pc.bold("Cloud :")} TeraBox (1024tera, nephobox, etc.)`,
1240
+ `${pc.bold("Social/Video:")} TikTok, Douyin, YouTube, Instagram, Facebook, Bilibili, Reddit, Threads, Twitter/X, Doodstream`,
1241
+ `${pc.bold("Music/Audio :")} Spotify, SoundCloud, Apple Music, Bandcamp`,
1242
+ `${pc.bold("Photo/Art :")} Pinterest, Pixiv, RedNote (Xiaohongshu)`,
1243
+ `${pc.bold("Cloud/Files :")} TeraBox, MediaFire, Sfile, Catbox, Pixeldrain, Krakenfiles, Google Drive`,
1244
+ `${pc.bold("Resolvers :")} SafeLinkU, Sub2Unlock, Rekonise, Link Unshortener`,
866
1245
  ];
867
- p.note(platformList.join("\n"), pc.dim("Supported Platforms (16)"));
1246
+ p.note(platformList.join("\n"), pc.dim("Supported Platforms (27 • Dual-Engine)"));
868
1247
  break;
869
1248
  }
870
1249
 
@@ -1169,6 +1548,190 @@ async function main() {
1169
1548
  break;
1170
1549
  }
1171
1550
 
1551
+ case "engine": {
1552
+ const moriInst = isMoriInstalled();
1553
+ const scraprInst = isScraprInstalled();
1554
+ const currentPref = getSavedConfig().defaultEngine || "auto";
1555
+
1556
+ const options = [
1557
+ {
1558
+ value: "auto",
1559
+ label: "Auto (Recommended)",
1560
+ hint: `Cascade engines • Mori: ${moriInst ? "v" + (getActiveScraperVersion() || "installed") : "missing"} • Scrapr: ${scraprInst ? "v" + (getActiveScraprVersion() || "installed") : "missing"}`,
1561
+ },
1562
+ {
1563
+ value: "mori",
1564
+ label: "Mori Engine",
1565
+ hint: `Core browser scrapers ~80 KB • ${moriInst ? "Installed (v" + (getActiveScraperVersion() || "1.0.0") + ")" : "Not installed"}`,
1566
+ },
1567
+ {
1568
+ value: "scrapr",
1569
+ label: "Scrapr Engine",
1570
+ hint: `Resolvers & scrapers ~2.7 MB • ${scraprInst ? "Installed (v" + (getActiveScraprVersion() || "1.3.1") + ")" : "Not installed"}`,
1571
+ },
1572
+ ];
1573
+
1574
+ if (!moriInst || !scraprInst) {
1575
+ options.push({
1576
+ value: "install_missing",
1577
+ label: "Install Missing Engine...",
1578
+ hint: !moriInst && !scraprInst ? "Both missing" : !moriInst ? "Install Mori" : "Install Scrapr",
1579
+ });
1580
+ }
1581
+
1582
+ options.push({
1583
+ value: "manage",
1584
+ label: "Manage Engines (Reinstall / Uninstall)...",
1585
+ hint: "Re-download or remove engines",
1586
+ });
1587
+
1588
+ const choice = await p.select({
1589
+ message: "Select extraction engine preference:",
1590
+ options,
1591
+ initialValue: currentPref,
1592
+ });
1593
+
1594
+ if (p.isCancel(choice)) break;
1595
+
1596
+ if (choice === "install_missing") {
1597
+ if (!moriInst) {
1598
+ const s = p.spinner();
1599
+ s.start(pc.dim("Installing Mori Core Engine (~80 KB)..."));
1600
+ try {
1601
+ const res = await downloadMoriEngine();
1602
+ s.stop(pc.bold(`✔ Mori Core Engine installed (v${res.version}).`));
1603
+ } catch (err) {
1604
+ s.stop(pc.bold(`✕ Failed: ${err.message}`));
1605
+ }
1606
+ }
1607
+ if (!scraprInst) {
1608
+ const s = p.spinner();
1609
+ s.start(pc.dim("Installing Scrapr Engine (~2.7 MB)..."));
1610
+ try {
1611
+ const res = await downloadScraprEngine();
1612
+ s.stop(pc.bold(`✔ Scrapr Engine installed (v${res.version}).`));
1613
+ } catch (err) {
1614
+ s.stop(pc.bold(`✕ Failed: ${err.message}`));
1615
+ }
1616
+ }
1617
+ break;
1618
+ }
1619
+
1620
+ if (choice === "manage") {
1621
+ const mgmtChoice = await p.select({
1622
+ message: "Engine Management:",
1623
+ options: [
1624
+ {
1625
+ value: "reinstall_mori",
1626
+ label: "Reinstall Mori Engine (~80 KB)",
1627
+ hint: moriInst ? "Re-fetch latest bundle" : "Install",
1628
+ },
1629
+ {
1630
+ value: "reinstall_scrapr",
1631
+ label: "Reinstall Scrapr Engine (~2.7 MB)",
1632
+ hint: scraprInst ? "Re-fetch latest bundle" : "Install",
1633
+ },
1634
+ ...(moriInst
1635
+ ? [
1636
+ {
1637
+ value: "uninstall_mori",
1638
+ label: "Uninstall Mori Engine",
1639
+ hint: "Delete ~/.mori/scrapers-bundle.js",
1640
+ },
1641
+ ]
1642
+ : []),
1643
+ ...(scraprInst
1644
+ ? [
1645
+ {
1646
+ value: "uninstall_scrapr",
1647
+ label: "Uninstall Scrapr Engine",
1648
+ hint: "Delete ~/.mori/scrapr/",
1649
+ },
1650
+ ]
1651
+ : []),
1652
+ { value: "cancel", label: pc.dim("Cancel") },
1653
+ ],
1654
+ });
1655
+
1656
+ if (p.isCancel(mgmtChoice) || mgmtChoice === "cancel") break;
1657
+
1658
+ if (mgmtChoice === "reinstall_mori") {
1659
+ const s = p.spinner();
1660
+ s.start(pc.dim("Downloading Mori Engine..."));
1661
+ try {
1662
+ const res = await downloadMoriEngine();
1663
+ s.stop(pc.bold(`✔ Mori Engine installed (v${res.version}).`));
1664
+ } catch (err) {
1665
+ s.stop(pc.bold(`✕ Failed: ${err.message}`));
1666
+ }
1667
+ } else if (mgmtChoice === "reinstall_scrapr") {
1668
+ const s = p.spinner();
1669
+ s.start(pc.dim("Downloading Scrapr Engine..."));
1670
+ try {
1671
+ const res = await downloadScraprEngine();
1672
+ s.stop(pc.bold(`✔ Scrapr Engine installed (v${res.version}).`));
1673
+ } catch (err) {
1674
+ s.stop(pc.bold(`✕ Failed: ${err.message}`));
1675
+ }
1676
+ } else if (mgmtChoice === "uninstall_mori") {
1677
+ uninstallMoriEngine();
1678
+ p.log.message(pc.dim("✔ Mori Engine uninstalled."));
1679
+ } else if (mgmtChoice === "uninstall_scrapr") {
1680
+ uninstallScraprEngine();
1681
+ p.log.message(pc.dim("✔ Scrapr Engine uninstalled."));
1682
+ }
1683
+ break;
1684
+ }
1685
+
1686
+ // If selected mori but not installed
1687
+ if (choice === "mori" && !moriInst) {
1688
+ const confirmDl = await p.confirm({
1689
+ message: "Mori Engine is not installed. Download now (~80 KB)?",
1690
+ initialValue: true,
1691
+ });
1692
+ if (!p.isCancel(confirmDl) && confirmDl) {
1693
+ const s = p.spinner();
1694
+ s.start(pc.dim("Downloading Mori Engine..."));
1695
+ try {
1696
+ const res = await downloadMoriEngine();
1697
+ s.stop(pc.bold(`✔ Mori Engine installed (v${res.version}).`));
1698
+ } catch (err) {
1699
+ s.stop(pc.bold(`✕ Failed: ${err.message}`));
1700
+ break;
1701
+ }
1702
+ } else {
1703
+ break;
1704
+ }
1705
+ }
1706
+
1707
+ // If selected scrapr but not installed
1708
+ if (choice === "scrapr" && !scraprInst) {
1709
+ const confirmDl = await p.confirm({
1710
+ message: "Scrapr Engine is not installed. Download now (~2.7 MB)?",
1711
+ initialValue: true,
1712
+ });
1713
+ if (!p.isCancel(confirmDl) && confirmDl) {
1714
+ const s = p.spinner();
1715
+ s.start(pc.dim("Downloading Scrapr Engine..."));
1716
+ try {
1717
+ const res = await downloadScraprEngine();
1718
+ s.stop(pc.bold(`✔ Scrapr Engine installed (v${res.version}).`));
1719
+ } catch (err) {
1720
+ s.stop(pc.bold(`✕ Failed: ${err.message}`));
1721
+ break;
1722
+ }
1723
+ } else {
1724
+ break;
1725
+ }
1726
+ }
1727
+
1728
+ saveConfig({ defaultEngine: choice });
1729
+ p.log.message(
1730
+ `${pc.bold("● Default engine set:")} ${pc.white(choice)}`,
1731
+ );
1732
+ break;
1733
+ }
1734
+
1172
1735
  case "clip":
1173
1736
  case "paste": {
1174
1737
  const s = p.spinner();
@@ -1299,9 +1862,11 @@ async function main() {
1299
1862
  const cfg = getSavedConfig();
1300
1863
  const cfgLines = [
1301
1864
  `${pc.bold("Download Dir :")} ${pc.white(currentOutputDir)}`,
1865
+ `${pc.bold("Default Engine:")} ${pc.white(cfg.defaultEngine || "auto")}`,
1302
1866
  `${pc.bold("Default Server:")} ${pc.white(cfg.defaultServer || "auto")}`,
1303
1867
  `${pc.bold("CLI Version :")} ${pc.white(`v${APP_VERSION}`)}`,
1304
- `${pc.bold("Core Version :")} ${pc.white(`v${getActiveScraperVersion()}`)}`,
1868
+ `${pc.bold("Mori Core Ver :")} ${pc.white(`v${getActiveScraperVersion()}`)}`,
1869
+ `${pc.bold("Scrapr Ver :")} ${pc.white(`v${getActiveScraprVersion()}`)}`,
1305
1870
  `${pc.bold("Config Path :")} ${pc.dim(CONFIG_PATH)}`,
1306
1871
  ];
1307
1872
  p.note(cfgLines.join("\n"), pc.dim("Active Configuration"));
@@ -1404,7 +1969,14 @@ async function main() {
1404
1969
  s.start(pc.dim("Checking for updates..."));
1405
1970
  try {
1406
1971
  const cliVer = await checkCliUpdate();
1407
- const ota = await checkForOtaUpdate(true);
1972
+ const [moriRes, scraprRes] = await Promise.allSettled([
1973
+ isMoriInstalled()
1974
+ ? checkForOtaUpdate(true)
1975
+ : Promise.resolve({ notInstalled: true }),
1976
+ isScraprInstalled()
1977
+ ? checkForScraprOtaUpdate(true)
1978
+ : Promise.resolve({ notInstalled: true }),
1979
+ ]);
1408
1980
 
1409
1981
  s.stop(pc.bold("Update Check:"));
1410
1982
 
@@ -1420,15 +1992,44 @@ async function main() {
1420
1992
  );
1421
1993
  }
1422
1994
 
1423
- if (ota.updated) {
1995
+ const moriUpdate =
1996
+ moriRes.status === "fulfilled" ? moriRes.value : null;
1997
+ const scraprUpdate =
1998
+ scraprRes.status === "fulfilled" ? scraprRes.value : null;
1999
+
2000
+ if (moriUpdate?.notInstalled) {
1424
2001
  p.log.step(
1425
- pc.bold(`✔ Scrapers updated to v${ota.newVersion}`) +
1426
- (ota.changelog ? pc.dim(` — ${ota.changelog}`) : ""),
2002
+ pc.dim("Mori Engine: Not installed (install with /engine)."),
1427
2003
  );
1428
- } else {
2004
+ } else if (moriUpdate?.updated) {
2005
+ p.log.step(
2006
+ pc.bold(`✔ Mori Core updated to v${moriUpdate.newVersion}`) +
2007
+ (moriUpdate.changelog
2008
+ ? pc.dim(` — ${moriUpdate.changelog}`)
2009
+ : ""),
2010
+ );
2011
+ } else if (moriUpdate) {
2012
+ p.log.step(
2013
+ pc.dim(
2014
+ `Mori Core is up to date (v${moriUpdate.currentVersion || getActiveScraperVersion()}).`,
2015
+ ),
2016
+ );
2017
+ }
2018
+
2019
+ if (scraprUpdate?.notInstalled) {
2020
+ p.log.step(
2021
+ pc.dim("Scrapr Engine: Not installed (install with /engine)."),
2022
+ );
2023
+ } else if (scraprUpdate?.updated) {
2024
+ p.log.step(
2025
+ pc.bold(
2026
+ `✔ Scrapr Engine updated to v${scraprUpdate.newVersion}`,
2027
+ ),
2028
+ );
2029
+ } else if (scraprUpdate) {
1429
2030
  p.log.step(
1430
2031
  pc.dim(
1431
- `Scraper engine is up to date (v${ota.currentVersion}).`,
2032
+ `Scrapr Engine is up to date (v${scraprUpdate.currentVersion || getActiveScraprVersion()}).`,
1432
2033
  ),
1433
2034
  );
1434
2035
  }
@@ -1469,7 +2070,7 @@ async function main() {
1469
2070
  case "clear":
1470
2071
  case "cls": {
1471
2072
  console.clear();
1472
- printBanner(getActiveScraperVersion());
2073
+ printBanner(getActiveScraperVersion(), getActiveScraprVersion());
1473
2074
  break;
1474
2075
  }
1475
2076
 
@@ -1484,15 +2085,16 @@ async function main() {
1484
2085
  `${pc.bold("/info [url]")} Inspect media details without downloading`,
1485
2086
  `${pc.bold("/retry")} Re-download the last link processed`,
1486
2087
  `${pc.bold("/batch")} Bulk download multiple links at once`,
1487
- `${pc.bold("/platform")} List all 16 supported media platforms`,
2088
+ `${pc.bold("/platform")} List all 27 supported media platforms`,
1488
2089
  `${pc.bold("/dir")} View or set download directory (persistent)`,
1489
2090
  `${pc.bold("/open")} Open download folder in file manager`,
2091
+ `${pc.bold("/engine")} Set default extraction engine (auto/mori/scrapr)`,
1490
2092
  `${pc.bold("/server")} Set default scraper server (auto/1/2)`,
1491
2093
  `${pc.bold("/history [num]")} View or redownload history item (/history 1, /history clear)`,
1492
2094
  `${pc.bold("/delete [num]")} Delete downloaded file from disk and history`,
1493
2095
  `${pc.bold("/stats")} View total downloads & storage statistics`,
1494
2096
  `${pc.bold("/config")} Show active Mori configuration`,
1495
- `${pc.bold("/update")} Check and apply remote OTA scraper patch`,
2097
+ `${pc.bold("/update")} Check and apply remote OTA scraper patches`,
1496
2098
  `${pc.bold("/reset")} Factory reset Mori config, cache, & history`,
1497
2099
  `${pc.bold("/clear")} Clear screen and reprint header`,
1498
2100
  `${pc.bold("/exit, /q")} Exit Mori CLI`,