@coflyn/mori 1.1.0 → 1.2.1

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
@@ -35,6 +35,7 @@ import {
35
35
  addToHistory,
36
36
  clearHistory,
37
37
  deleteHistoryItem,
38
+ deleteHistoryItems,
38
39
  readClipboard,
39
40
  getNonCollidingPath,
40
41
  resetMori,
@@ -45,9 +46,14 @@ import {
45
46
  pingNetwork,
46
47
  compileImagesToPdf,
47
48
  CHROME_UA,
49
+ loadScraprEngine,
50
+ fetchMoriEngineHistory,
51
+ downloadMoriEngineByCommit,
52
+ fetchScraprEngineVersions,
53
+ downloadScraprEngineVersion,
48
54
  } from "./engine.js";
49
55
 
50
- const APP_VERSION = "1.1.0";
56
+ const APP_VERSION = "1.2.0";
51
57
 
52
58
  function isNewerVersion(latest, current) {
53
59
  if (!latest || !current) return false;
@@ -121,6 +127,22 @@ function truncateText(str, max = 72) {
121
127
  }
122
128
 
123
129
  function formatStreamItem(d, i, allDownloads = []) {
130
+ const cleanTrack = (d.title || d.type || "")
131
+ .replace(/\s*\[(MP3|MP4|JPG|PNG|WEBP|COVER)\]/gi, "")
132
+ .trim();
133
+
134
+ const isGeneric =
135
+ !cleanTrack ||
136
+ /^(mp3|audio|music|photo|image|video|link|default)$/i.test(cleanTrack) ||
137
+ /^\d+p$/i.test(cleanTrack);
138
+
139
+ if (!isGeneric && (/^\d+\.\s+/.test(cleanTrack) || d.title)) {
140
+ return {
141
+ label: d.title || cleanTrack,
142
+ hint: (d.type || "").toLowerCase().includes("mp4") ? "video" : "audio",
143
+ };
144
+ }
145
+
124
146
  const typeStr = (d.type || "").toLowerCase();
125
147
  const qualityStr = (d.quality || "").trim();
126
148
 
@@ -384,10 +406,24 @@ async function processDownloadItem({ item, meta, outputDir, index, total }) {
384
406
  ? "jpg"
385
407
  : "mp4");
386
408
 
409
+ const cleanTrack = (item.title || item.type || "")
410
+ .replace(/\s*\[(MP3|MP4|JPG|PNG|WEBP|COVER)\]/gi, "")
411
+ .trim();
412
+ const isGenericTrack =
413
+ !cleanTrack ||
414
+ /^(mp3|audio|music|photo|image|video|link|default)$/i.test(cleanTrack) ||
415
+ /^\d+p$/i.test(cleanTrack);
416
+
417
+ const trackTitle =
418
+ !isGenericTrack && (/^\d+\.\s+/.test(cleanTrack) || item.title)
419
+ ? item.title || cleanTrack
420
+ : null;
421
+
387
422
  let baseTitle = rawFilename
388
423
  ? path.basename(rawFilename, path.extname(rawFilename))
389
- : (meta.title || "Media");
390
- if (total > 1) {
424
+ : trackTitle || meta.title || "Media";
425
+
426
+ if (total > 1 && !trackTitle) {
391
427
  baseTitle = `${baseTitle}_${index + 1}`;
392
428
  }
393
429
  const filename = sanitizeFilename(baseTitle, ext);
@@ -410,17 +446,28 @@ async function processDownloadItem({ item, meta, outputDir, index, total }) {
410
446
 
411
447
  let finalBytes = 0;
412
448
  try {
413
- await downloadMediaFile(directUrl, destPath, (prog) => {
414
- finalBytes = prog.downloadedBytes;
415
- const bar = renderProgressBar(prog.percent, 20);
416
- const pct = `${prog.percent.toFixed(0)}%`.padStart(4);
417
- const dl = formatBytes(prog.downloadedBytes);
418
- const tot = prog.totalBytes > 0 ? formatBytes(prog.totalBytes) : "?";
419
- const spd = `${formatBytes(prog.speedBps)}/s`;
420
-
421
- const line = ` ${bar} ${pc.bold(pct)} ${pc.dim(`(${dl}/${tot} • ${spd})`)}`;
422
- process.stdout.write(`\r${line}\x1b[K`);
423
- });
449
+ await downloadMediaFile(
450
+ directUrl,
451
+ destPath,
452
+ (prog) => {
453
+ finalBytes = prog.downloadedBytes;
454
+ const bar = renderProgressBar(prog.percent, 20);
455
+ const pct = `${prog.percent.toFixed(0)}%`.padStart(4);
456
+ const dl = formatBytes(prog.downloadedBytes);
457
+ const tot = prog.totalBytes > 0 ? formatBytes(prog.totalBytes) : "?";
458
+ const spd = `${formatBytes(prog.speedBps)}/s`;
459
+
460
+ const line = ` ${bar} ${pc.bold(pct)} ${pc.dim(`(${dl}/${tot} • ${spd})`)}`;
461
+ process.stdout.write(`\r${line}\x1b[K`);
462
+ },
463
+ {
464
+ ...(meta.url ? { Referer: meta.url } : {}),
465
+ ...(directUrl.includes("googlevideo.com")
466
+ ? { Referer: "https://desustream.net/" }
467
+ : {}),
468
+ ...(item.headers || {}),
469
+ },
470
+ );
424
471
 
425
472
  process.stdout.write("\r\x1b[2K");
426
473
  p.log.message(
@@ -428,7 +475,7 @@ async function processDownloadItem({ item, meta, outputDir, index, total }) {
428
475
  );
429
476
  addToHistory({
430
477
  url: meta.url || "",
431
- title: meta.title || "Media",
478
+ title: trackTitle || meta.title || "Media",
432
479
  platform: meta.platform || "unknown",
433
480
  filename: path.basename(destPath),
434
481
  path: destPath,
@@ -619,37 +666,102 @@ async function handleScrapeAndDownload(targetUrl, options) {
619
666
  return false;
620
667
  }
621
668
 
622
- if (options.audio) {
623
- const audioItem =
624
- downloads.find(
625
- (d) =>
626
- d.type?.toLowerCase().includes("mp3") ||
627
- d.type?.toLowerCase().includes("audio") ||
628
- d.type?.toLowerCase().includes("music"),
629
- ) || downloads[0];
669
+ const isPlaylistOrAlbum =
670
+ media.type === "playlist" ||
671
+ media.type === "album" ||
672
+ /playlist|album/i.test(targetUrl || "") ||
673
+ /playlist|album/i.test(media.sourceUrl || "") ||
674
+ /playlist|album/i.test(media.originalUrl || "") ||
675
+ (typeof media.title === "string" &&
676
+ /\((Playlist|Album)\)/i.test(media.title));
677
+
678
+ const hasTrackNumbers = downloads.some((dl) =>
679
+ /^\d+\.\s+/.test((dl.type || dl.title || "").trim()),
680
+ );
630
681
 
631
- p.log.message(
632
- `${pc.bold("● Audio Stream:")} ${pc.white(audioItem.type || "MP3")}`,
682
+ const isPlaylistCollection =
683
+ (isPlaylistOrAlbum || hasTrackNumbers) && downloads.length > 1;
684
+
685
+ if (isPlaylistCollection) {
686
+ const audioTracks = downloads.filter(
687
+ (d) =>
688
+ !d.type?.toLowerCase().includes("cover") &&
689
+ !d.type?.toLowerCase().includes("photo"),
633
690
  );
691
+ const candidateTracks = audioTracks.length > 0 ? audioTracks : downloads;
634
692
 
635
- await processDownloadItem({
636
- item: audioItem,
637
- meta: media,
638
- outputDir,
639
- index: 0,
640
- total: 1,
641
- });
642
- return true;
643
- }
693
+ let itemsToDownload = candidateTracks;
644
694
 
645
- if (options.yes) {
646
- await processDownloadItem({
647
- item: downloads[0],
648
- meta: media,
649
- outputDir,
650
- index: 0,
651
- total: 1,
652
- });
695
+ if (!options.yes) {
696
+ const choice = await p.select({
697
+ message: `Playlist / Album detected (${candidateTracks.length} tracks):`,
698
+ options: [
699
+ {
700
+ value: "all",
701
+ label: `Download All (${candidateTracks.length} tracks)`,
702
+ },
703
+ {
704
+ value: "custom",
705
+ label: "Select specific tracks...",
706
+ },
707
+ {
708
+ value: "cancel",
709
+ label: pc.dim("Cancel"),
710
+ },
711
+ ],
712
+ });
713
+
714
+ if (p.isCancel(choice) || choice === "cancel") {
715
+ p.cancel("Cancelled.");
716
+ return false;
717
+ }
718
+
719
+ if (choice === "custom") {
720
+ const selectedIndices = await p.multiselect({
721
+ message: "Select tracks to download:",
722
+ options: candidateTracks.map((d, i) => {
723
+ const item = formatStreamItem(d, i, candidateTracks);
724
+ return {
725
+ value: i,
726
+ label: item.label,
727
+ };
728
+ }),
729
+ required: true,
730
+ });
731
+
732
+ if (p.isCancel(selectedIndices)) {
733
+ p.cancel("Cancelled.");
734
+ return false;
735
+ }
736
+
737
+ itemsToDownload = selectedIndices.map((idx) => candidateTracks[idx]);
738
+ }
739
+ }
740
+
741
+ p.log.info(
742
+ `${pc.bold("● Playlist Queue:")} Downloading ${itemsToDownload.length} track(s)...`,
743
+ );
744
+
745
+ let successCount = 0;
746
+ for (let i = 0; i < itemsToDownload.length; i++) {
747
+ const item = itemsToDownload[i];
748
+ const streamInfo = formatStreamItem(item, i, itemsToDownload);
749
+ p.log.step(
750
+ `${pc.bold(`[${i + 1}/${itemsToDownload.length}]`)} ${streamInfo.label}`,
751
+ );
752
+ const ok = await processDownloadItem({
753
+ item,
754
+ meta: media,
755
+ outputDir,
756
+ index: i,
757
+ total: itemsToDownload.length,
758
+ });
759
+ if (ok) successCount++;
760
+ }
761
+
762
+ p.log.success(
763
+ `${pc.bold("✔ Playlist completed:")} [${successCount}/${itemsToDownload.length}] tracks saved to ${pc.dim(outputDir)}`,
764
+ );
653
765
  return true;
654
766
  }
655
767
 
@@ -709,7 +821,11 @@ async function handleScrapeAndDownload(targetUrl, options) {
709
821
  let downloadAudioAlso = false;
710
822
 
711
823
  if (!albumFormat) {
712
- const albumOptions = [
824
+ if (options.yes) {
825
+ albumFormat = "all";
826
+ downloadAudioAlso = audioDownloads.length > 0;
827
+ } else {
828
+ const albumOptions = [
713
829
  {
714
830
  value: "all",
715
831
  label: `Download All (${photoDownloads.length} individual images)`,
@@ -810,6 +926,7 @@ async function handleScrapeAndDownload(targetUrl, options) {
810
926
  albumFormat = "all";
811
927
  }
812
928
  }
929
+ }
813
930
 
814
931
  if (albumFormat === "pdf") {
815
932
  const s = p.spinner();
@@ -829,6 +946,7 @@ async function handleScrapeAndDownload(targetUrl, options) {
829
946
  headers: {
830
947
  "User-Agent": CHROME_UA,
831
948
  Accept: "*/*",
949
+ ...(media.url ? { Referer: media.url } : {}),
832
950
  ...(item.headers || {}),
833
951
  },
834
952
  });
@@ -972,6 +1090,40 @@ async function handleScrapeAndDownload(targetUrl, options) {
972
1090
 
973
1091
  return true;
974
1092
  } else {
1093
+ if (options.audio) {
1094
+ const audioItem =
1095
+ downloads.find(
1096
+ (d) =>
1097
+ d.type?.toLowerCase().includes("mp3") ||
1098
+ d.type?.toLowerCase().includes("audio") ||
1099
+ d.type?.toLowerCase().includes("music"),
1100
+ ) || downloads[0];
1101
+
1102
+ p.log.message(
1103
+ `${pc.bold("● Audio Stream:")} ${pc.white(audioItem.type || "MP3")}`,
1104
+ );
1105
+
1106
+ await processDownloadItem({
1107
+ item: audioItem,
1108
+ meta: media,
1109
+ outputDir,
1110
+ index: 0,
1111
+ total: 1,
1112
+ });
1113
+ return true;
1114
+ }
1115
+
1116
+ if (options.yes) {
1117
+ await processDownloadItem({
1118
+ item: downloads[0],
1119
+ meta: media,
1120
+ outputDir,
1121
+ index: 0,
1122
+ total: 1,
1123
+ });
1124
+ return true;
1125
+ }
1126
+
975
1127
  let selectedItem = downloads[0];
976
1128
 
977
1129
  if (downloads.length > 1) {
@@ -994,6 +1146,23 @@ async function handleScrapeAndDownload(targetUrl, options) {
994
1146
  selectedItem = downloads[formatChoice];
995
1147
  }
996
1148
 
1149
+ if (selectedItem?.type === "link") {
1150
+ const linkUrl = selectedItem.url;
1151
+ await writeClipboard(linkUrl);
1152
+ p.log.success(
1153
+ `${pc.bold("✔ Mirror link copied to clipboard:")} ${pc.underline(pc.cyan(linkUrl))}`,
1154
+ );
1155
+ addToHistory({
1156
+ url: targetUrl,
1157
+ title: `${media.title || "Media"} (${selectedItem.quality || "Mirror"})`,
1158
+ platform: media.platform,
1159
+ filename: "",
1160
+ path: linkUrl,
1161
+ bytes: 0,
1162
+ });
1163
+ return true;
1164
+ }
1165
+
997
1166
  await processDownloadItem({
998
1167
  item: selectedItem,
999
1168
  meta: media,
@@ -1006,6 +1175,460 @@ async function handleScrapeAndDownload(targetUrl, options) {
1006
1175
  return true;
1007
1176
  }
1008
1177
 
1178
+ async function handleSearchAndDownload(query, forcedType = null, options = {}) {
1179
+ const scrapr = loadScraprEngine();
1180
+ let provider = null;
1181
+
1182
+ if (forcedType === "anime") {
1183
+ const chosen = await p.select({
1184
+ message: `Select Anime Provider for "${query}":`,
1185
+ options: [
1186
+ { value: "otakudesu", label: "Otakudesu (Indonesian Sub)" },
1187
+ { value: "gogoanime", label: "Gogoanime (English Sub)" },
1188
+ ],
1189
+ });
1190
+ if (p.isCancel(chosen)) return false;
1191
+ provider = chosen;
1192
+ } else if (forcedType === "comic") {
1193
+ const chosen = await p.select({
1194
+ message: `Select Comic Provider for "${query}":`,
1195
+ options: [
1196
+ { value: "komikindo", label: "Komikindo (Indonesian)" },
1197
+ { value: "komiku", label: "Komiku (Indonesian)" },
1198
+ { value: "asurascans", label: "Asura Scans (English / Manhwa)" },
1199
+ ],
1200
+ });
1201
+ if (p.isCancel(chosen)) return false;
1202
+ provider = chosen;
1203
+ } else {
1204
+ const chosen = await p.select({
1205
+ message: `Search query "${query}":`,
1206
+ options: [
1207
+ { value: "otakudesu", label: "Anime • Otakudesu (Sub Indo)" },
1208
+ { value: "gogoanime", label: "Anime • Gogoanime (Sub Eng)" },
1209
+ { value: "komikindo", label: "Comic • Komikindo (Sub Indo)" },
1210
+ { value: "komiku", label: "Comic • Komiku (Sub Indo)" },
1211
+ { value: "asurascans", label: "Comic • Asura Scans (English)" },
1212
+ ],
1213
+ });
1214
+ if (p.isCancel(chosen)) return false;
1215
+ provider = chosen;
1216
+ }
1217
+
1218
+ const s = p.spinner();
1219
+
1220
+ if (provider === "otakudesu") {
1221
+ s.start(pc.dim(`Searching Otakudesu for "${query}"...`));
1222
+ let searchRes;
1223
+ try {
1224
+ searchRes = await scrapr.anime.otakudesu.search(query);
1225
+ } catch (err) {
1226
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1227
+ return false;
1228
+ }
1229
+ s.stop(pc.dim("Search complete."));
1230
+
1231
+ const items = searchRes?.result || [];
1232
+ if (items.length === 0) {
1233
+ p.log.warn(`No anime found for "${query}" on Otakudesu.`);
1234
+ return false;
1235
+ }
1236
+
1237
+ const animeChoices = items.map((it) => ({
1238
+ value: it.url,
1239
+ label: `${it.title} ${it.meta ? pc.dim(`(${it.meta})`) : ""}`,
1240
+ }));
1241
+ animeChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1242
+
1243
+ const chosenAnimeUrl = await p.select({
1244
+ message: `Select Anime (${items.length} found):`,
1245
+ options: animeChoices,
1246
+ });
1247
+ if (p.isCancel(chosenAnimeUrl) || chosenAnimeUrl === "cancel") {
1248
+ p.cancel("Cancelled.");
1249
+ return false;
1250
+ }
1251
+
1252
+ s.start(pc.dim("Fetching episode list..."));
1253
+ let epRes;
1254
+ try {
1255
+ epRes = await scrapr.anime.otakudesu.getEpisodes(chosenAnimeUrl);
1256
+ } catch (err) {
1257
+ s.stop(pc.bold(`✕ Failed to fetch episodes: ${err.message}`));
1258
+ return false;
1259
+ }
1260
+ s.stop(pc.dim("Episodes fetched."));
1261
+
1262
+ const episodes = epRes?.result || [];
1263
+ if (episodes.length === 0) {
1264
+ p.log.warn("No episodes found for this anime.");
1265
+ return false;
1266
+ }
1267
+
1268
+ const epChoices = episodes.map((ep) => ({
1269
+ value: ep.url,
1270
+ label: ep.title,
1271
+ }));
1272
+ epChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1273
+
1274
+ const chosenEpUrl = await p.select({
1275
+ message: `Select Episode (${episodes.length} episodes):`,
1276
+ options: epChoices,
1277
+ });
1278
+ if (p.isCancel(chosenEpUrl) || chosenEpUrl === "cancel") {
1279
+ p.cancel("Cancelled.");
1280
+ return false;
1281
+ }
1282
+
1283
+ return await handleScrapeAndDownload(chosenEpUrl, options);
1284
+ }
1285
+
1286
+ if (provider === "gogoanime") {
1287
+ s.start(pc.dim(`Searching Gogoanime for "${query}"...`));
1288
+ let searchRes;
1289
+ try {
1290
+ searchRes = await scrapr.anime.gogoanime.search(query);
1291
+ } catch (err) {
1292
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1293
+ return false;
1294
+ }
1295
+ s.stop(pc.dim("Search complete."));
1296
+
1297
+ const items = searchRes?.result || [];
1298
+ if (items.length === 0) {
1299
+ p.log.warn(`No anime found for "${query}" on Gogoanime.`);
1300
+ return false;
1301
+ }
1302
+
1303
+ const animeChoices = items.map((it) => ({
1304
+ value: it.url,
1305
+ label: it.title,
1306
+ }));
1307
+ animeChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1308
+
1309
+ const chosenAnimeUrl = await p.select({
1310
+ message: `Select Anime (${items.length} found):`,
1311
+ options: animeChoices,
1312
+ });
1313
+ if (p.isCancel(chosenAnimeUrl) || chosenAnimeUrl === "cancel") {
1314
+ p.cancel("Cancelled.");
1315
+ return false;
1316
+ }
1317
+
1318
+ s.start(pc.dim("Fetching episode list..."));
1319
+ let epRes;
1320
+ try {
1321
+ epRes = await scrapr.anime.gogoanime.getEpisodes(chosenAnimeUrl);
1322
+ } catch (err) {
1323
+ s.stop(pc.bold(`✕ Failed to fetch episodes: ${err.message}`));
1324
+ return false;
1325
+ }
1326
+ s.stop(pc.dim("Episodes fetched."));
1327
+
1328
+ const episodes = epRes?.result || [];
1329
+ if (episodes.length === 0) {
1330
+ p.log.warn("No episodes found for this anime.");
1331
+ return false;
1332
+ }
1333
+
1334
+ const epChoices = episodes.slice(0, 100).map((ep) => ({
1335
+ value: ep.url,
1336
+ label: ep.title,
1337
+ }));
1338
+ epChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1339
+
1340
+ const chosenEpUrl = await p.select({
1341
+ message: `Select Episode (${episodes.length} episodes):`,
1342
+ options: epChoices,
1343
+ });
1344
+ if (p.isCancel(chosenEpUrl) || chosenEpUrl === "cancel") {
1345
+ p.cancel("Cancelled.");
1346
+ return false;
1347
+ }
1348
+
1349
+ return await handleScrapeAndDownload(chosenEpUrl, options);
1350
+ }
1351
+
1352
+ if (provider === "komikindo") {
1353
+ s.start(pc.dim(`Searching Komikindo for "${query}"...`));
1354
+ let searchRes;
1355
+ try {
1356
+ searchRes = await scrapr.comic.komikindo.search(query);
1357
+ } catch (err) {
1358
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1359
+ return false;
1360
+ }
1361
+ s.stop(pc.dim("Search complete."));
1362
+
1363
+ const items = searchRes?.result || [];
1364
+ if (items.length === 0) {
1365
+ p.log.warn(`No comics found for "${query}" on Komikindo.`);
1366
+ return false;
1367
+ }
1368
+
1369
+ const comicChoices = items.map((it) => ({
1370
+ value: it.url,
1371
+ label: it.title,
1372
+ }));
1373
+ comicChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1374
+
1375
+ const chosenComicUrl = await p.select({
1376
+ message: `Select Comic (${items.length} found):`,
1377
+ options: comicChoices,
1378
+ });
1379
+ if (p.isCancel(chosenComicUrl) || chosenComicUrl === "cancel") {
1380
+ p.cancel("Cancelled.");
1381
+ return false;
1382
+ }
1383
+
1384
+ s.start(pc.dim("Fetching chapter list..."));
1385
+ let chRes;
1386
+ try {
1387
+ chRes = await scrapr.comic.komikindo.getChapters(chosenComicUrl);
1388
+ } catch (err) {
1389
+ s.stop(pc.bold(`✕ Failed to fetch chapters: ${err.message}`));
1390
+ return false;
1391
+ }
1392
+ s.stop(pc.dim("Chapters fetched."));
1393
+
1394
+ const chapters = chRes?.result || [];
1395
+ if (chapters.length === 0) {
1396
+ p.log.warn("No chapters found for this comic.");
1397
+ return false;
1398
+ }
1399
+
1400
+ const chChoices = chapters.slice(0, 100).map((ch) => ({
1401
+ value: ch.url,
1402
+ label: ch.title,
1403
+ }));
1404
+ chChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1405
+
1406
+ const chosenChUrl = await p.select({
1407
+ message: `Select Chapter (${chapters.length} available):`,
1408
+ options: chChoices,
1409
+ });
1410
+ if (p.isCancel(chosenChUrl) || chosenChUrl === "cancel") {
1411
+ p.cancel("Cancelled.");
1412
+ return false;
1413
+ }
1414
+
1415
+ return await handleScrapeAndDownload(chosenChUrl, options);
1416
+ }
1417
+
1418
+ if (provider === "komiku") {
1419
+ s.start(pc.dim(`Searching Komiku for "${query}"...`));
1420
+ let searchRes;
1421
+ try {
1422
+ searchRes = await scrapr.comic.komiku.search(query);
1423
+ } catch (err) {
1424
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1425
+ return false;
1426
+ }
1427
+ s.stop(pc.dim("Search complete."));
1428
+
1429
+ const items = searchRes?.result || [];
1430
+ if (items.length === 0) {
1431
+ p.log.warn(`No comics found for "${query}" on Komiku.`);
1432
+ return false;
1433
+ }
1434
+
1435
+ const comicChoices = items.map((it) => ({
1436
+ value: it.url,
1437
+ label: it.title,
1438
+ }));
1439
+ comicChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1440
+
1441
+ const chosenComicUrl = await p.select({
1442
+ message: `Select Comic (${items.length} found):`,
1443
+ options: comicChoices,
1444
+ });
1445
+ if (p.isCancel(chosenComicUrl) || chosenComicUrl === "cancel") {
1446
+ p.cancel("Cancelled.");
1447
+ return false;
1448
+ }
1449
+
1450
+ s.start(pc.dim("Fetching chapter list..."));
1451
+ let chRes;
1452
+ try {
1453
+ chRes = await scrapr.comic.komiku.getChapters(chosenComicUrl);
1454
+ } catch (err) {
1455
+ s.stop(pc.bold(`✕ Failed to fetch chapters: ${err.message}`));
1456
+ return false;
1457
+ }
1458
+ s.stop(pc.dim("Chapters fetched."));
1459
+
1460
+ const chapters = chRes?.result || [];
1461
+ if (chapters.length === 0) {
1462
+ p.log.warn("No chapters found for this comic.");
1463
+ return false;
1464
+ }
1465
+
1466
+ const chChoices = chapters.slice(0, 100).map((ch) => ({
1467
+ value: ch.url,
1468
+ label: ch.title,
1469
+ }));
1470
+ chChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1471
+
1472
+ const chosenChUrl = await p.select({
1473
+ message: `Select Chapter (${chapters.length} available):`,
1474
+ options: chChoices,
1475
+ });
1476
+ if (p.isCancel(chosenChUrl) || chosenChUrl === "cancel") {
1477
+ p.cancel("Cancelled.");
1478
+ return false;
1479
+ }
1480
+
1481
+ return await handleScrapeAndDownload(chosenChUrl, options);
1482
+ }
1483
+
1484
+ if (provider === "asurascans") {
1485
+ s.start(pc.dim(`Searching Asura Scans for "${query}"...`));
1486
+ let searchRes;
1487
+ try {
1488
+ searchRes = await scrapr.comic.asurascans.search(query);
1489
+ } catch (err) {
1490
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1491
+ return false;
1492
+ }
1493
+ s.stop(pc.dim("Search complete."));
1494
+
1495
+ const items = searchRes?.result || [];
1496
+ if (items.length === 0) {
1497
+ p.log.warn(`No comics found for "${query}" on Asura Scans.`);
1498
+ return false;
1499
+ }
1500
+
1501
+ const comicChoices = items.map((it) => ({
1502
+ value: it.url,
1503
+ label: `${it.title} ${it.status ? pc.dim(`[${it.status}]`) : ""}`,
1504
+ }));
1505
+ comicChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1506
+
1507
+ const chosenComicUrl = await p.select({
1508
+ message: `Select Comic (${items.length} found):`,
1509
+ options: comicChoices,
1510
+ });
1511
+ if (p.isCancel(chosenComicUrl) || chosenComicUrl === "cancel") {
1512
+ p.cancel("Cancelled.");
1513
+ return false;
1514
+ }
1515
+
1516
+ s.start(pc.dim("Fetching chapter list..."));
1517
+ let chRes;
1518
+ try {
1519
+ chRes = await scrapr.comic.asurascans.getChapters(chosenComicUrl);
1520
+ } catch (err) {
1521
+ s.stop(pc.bold(`✕ Failed to fetch chapters: ${err.message}`));
1522
+ return false;
1523
+ }
1524
+ s.stop(pc.dim("Chapters fetched."));
1525
+
1526
+ const chapters = chRes?.result || [];
1527
+ if (chapters.length === 0) {
1528
+ p.log.warn("No chapters found for this comic.");
1529
+ return false;
1530
+ }
1531
+
1532
+ const chChoices = chapters.slice(0, 100).map((ch) => ({
1533
+ value: ch.url,
1534
+ label: ch.title,
1535
+ }));
1536
+ chChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1537
+
1538
+ const chosenChUrl = await p.select({
1539
+ message: `Select Chapter (${chapters.length} available):`,
1540
+ options: chChoices,
1541
+ });
1542
+ if (p.isCancel(chosenChUrl) || chosenChUrl === "cancel") {
1543
+ p.cancel("Cancelled.");
1544
+ return false;
1545
+ }
1546
+
1547
+ return await handleScrapeAndDownload(chosenChUrl, options);
1548
+ }
1549
+
1550
+ return false;
1551
+ }
1552
+
1553
+ async function handleRollbackMori() {
1554
+ const s = p.spinner();
1555
+ s.start(pc.dim("Fetching Mori Engine commit history from GitHub..."));
1556
+ const history = await fetchMoriEngineHistory();
1557
+ s.stop(pc.dim("History fetched."));
1558
+
1559
+ if (history.length === 0) {
1560
+ p.log.warn("Could not fetch Mori Core commit history from GitHub.");
1561
+ return false;
1562
+ }
1563
+
1564
+ const currentVer = getActiveScraperVersion();
1565
+ const commitChoice = await p.select({
1566
+ message: `Select Mori Core version / commit (Current: v${currentVer || "none"}):`,
1567
+ options: [
1568
+ ...history.map((h, idx) => ({
1569
+ value: h.fullSha,
1570
+ label: `[${h.sha}] ${h.message}`,
1571
+ hint: `${idx === 0 ? "Latest • " : ""}${h.date ? h.date.split("T")[0] : ""}`,
1572
+ })),
1573
+ { value: "cancel", label: pc.dim("Cancel") },
1574
+ ],
1575
+ });
1576
+
1577
+ if (p.isCancel(commitChoice) || commitChoice === "cancel") return false;
1578
+
1579
+ const dlSpin = p.spinner();
1580
+ dlSpin.start(pc.dim("Downloading Mori Core bundle..."));
1581
+ try {
1582
+ const res = await downloadMoriEngineByCommit(commitChoice, (msg) => {
1583
+ dlSpin.message(pc.dim(msg));
1584
+ });
1585
+ dlSpin.stop(pc.bold(`✔ Mori Core Engine installed (v${res.version}).`));
1586
+ return true;
1587
+ } catch (err) {
1588
+ dlSpin.stop(pc.bold(`✕ Installation failed: ${err.message}`));
1589
+ return false;
1590
+ }
1591
+ }
1592
+
1593
+ async function handleRollbackScrapr() {
1594
+ const s = p.spinner();
1595
+ s.start(pc.dim("Fetching available Scrapr versions from NPM..."));
1596
+ const versions = await fetchScraprEngineVersions();
1597
+ s.stop(pc.dim("Versions fetched."));
1598
+
1599
+ if (versions.length === 0) {
1600
+ p.log.warn("Could not fetch Scrapr versions from registry.");
1601
+ return false;
1602
+ }
1603
+
1604
+ const currentVer = getActiveScraprVersion();
1605
+ const verChoice = await p.select({
1606
+ message: `Select Scrapr version to install (Current: v${currentVer || "none"}):`,
1607
+ options: [
1608
+ ...versions.slice(0, 15).map((v) => ({
1609
+ value: v,
1610
+ label: `v${v}${v === currentVer ? pc.green(" (current)") : ""}`,
1611
+ })),
1612
+ { value: "cancel", label: pc.dim("Cancel") },
1613
+ ],
1614
+ });
1615
+
1616
+ if (p.isCancel(verChoice) || verChoice === "cancel") return false;
1617
+
1618
+ const dlSpin = p.spinner();
1619
+ dlSpin.start(pc.dim(`Installing Scrapr Engine v${verChoice}...`));
1620
+ try {
1621
+ const res = await downloadScraprEngineVersion(verChoice, (msg) => {
1622
+ dlSpin.message(pc.dim(msg));
1623
+ });
1624
+ dlSpin.stop(pc.bold(`✔ Scrapr Engine v${res.version} installed.`));
1625
+ return true;
1626
+ } catch (err) {
1627
+ dlSpin.stop(pc.bold(`✕ Installation failed: ${err.message}`));
1628
+ return false;
1629
+ }
1630
+ }
1631
+
1009
1632
  async function main() {
1010
1633
  const { values, positionals } = parseArgs({
1011
1634
  args: process.argv.slice(2),
@@ -1163,6 +1786,26 @@ async function main() {
1163
1786
  let lastUrl = null;
1164
1787
 
1165
1788
  if (targetUrl) {
1789
+ const isUrl =
1790
+ targetUrl.startsWith("http://") || targetUrl.startsWith("https://");
1791
+ if (!isUrl) {
1792
+ lastUrl = targetUrl;
1793
+ await handleSearchAndDownload(targetUrl, null, {
1794
+ ...values,
1795
+ output: currentOutputDir,
1796
+ });
1797
+ const newVer = await cliUpdatePromise;
1798
+ if (newVer) {
1799
+ p.log.message(
1800
+ pc.yellow(
1801
+ `● Update available: v${APP_VERSION} → v${newVer} (run: npm i -g @coflyn/mori)`,
1802
+ ),
1803
+ );
1804
+ }
1805
+ p.outro(pc.dim("Complete."));
1806
+ process.exit(0);
1807
+ }
1808
+
1166
1809
  const platform = detectPlatform(targetUrl);
1167
1810
  if (!platform) {
1168
1811
  p.log.error(`Unsupported URL: ${targetUrl}`);
@@ -1198,17 +1841,22 @@ async function main() {
1198
1841
 
1199
1842
  while (keepGoing) {
1200
1843
  const urlInput = await p.text({
1201
- message: "Paste link:",
1202
- placeholder: "https://... or type /help",
1844
+ message: "Paste link or search title:",
1845
+ placeholder: "https://..., anime/comic title, or type /help",
1203
1846
  validate: (val) => {
1204
1847
  if (!val || val.trim().length === 0)
1205
- return "Please enter a URL or /command.";
1848
+ return "Please enter a URL, title, or /command.";
1206
1849
  const clean = val.trim().toLowerCase();
1207
1850
  if (clean === "exit" || clean === "quit" || clean === "q")
1208
1851
  return undefined;
1209
1852
  if (clean.startsWith("/")) return undefined;
1210
- if (!detectPlatform(val.trim())) {
1211
- return "Platform not supported. Type /platform to view supported platforms.";
1853
+ if (
1854
+ val.trim().startsWith("http://") ||
1855
+ val.trim().startsWith("https://")
1856
+ ) {
1857
+ if (!detectPlatform(val.trim())) {
1858
+ return "Platform not supported. Type /platform to view supported platforms.";
1859
+ }
1212
1860
  }
1213
1861
  return undefined;
1214
1862
  },
@@ -1242,13 +1890,57 @@ async function main() {
1242
1890
  `${pc.bold("Photo/Art :")} Pinterest, Pixiv, RedNote (Xiaohongshu)`,
1243
1891
  `${pc.bold("Cloud/Files :")} TeraBox, MediaFire, Sfile, Catbox, Pixeldrain, Krakenfiles, Google Drive`,
1244
1892
  `${pc.bold("Resolvers :")} SafeLinkU, Sub2Unlock, Rekonise, Link Unshortener`,
1893
+ `${pc.bold("Comic/Manga :")} Kiryuu, Komikcast, MangaDex, Komikindo, Komiku, Bacakomik, ManhwaIndo, Asura Scans, MangaBats`,
1894
+ `${pc.bold("Anime :")} Otakudesu, Nimegami, Gogoanime, AnimeTosho`,
1245
1895
  ];
1246
- p.note(platformList.join("\n"), pc.dim("Supported Platforms (27 • Dual-Engine)"));
1896
+ p.note(platformList.join("\n"), pc.dim("Supported Platforms (40 • Dual-Engine)"));
1897
+ break;
1898
+ }
1899
+
1900
+ case "anime": {
1901
+ let query = args.join(" ").trim();
1902
+ if (!query) {
1903
+ const qInput = await p.text({
1904
+ message: "Enter anime title to search:",
1905
+ placeholder: "e.g. majo no tabi tabi",
1906
+ validate: (v) => (!v || !v.trim() ? "Title required." : undefined),
1907
+ });
1908
+ if (p.isCancel(qInput)) break;
1909
+ query = qInput.trim();
1910
+ }
1911
+ await handleSearchAndDownload(query, "anime", {
1912
+ ...values,
1913
+ output: currentOutputDir,
1914
+ });
1915
+ break;
1916
+ }
1917
+
1918
+ case "comic":
1919
+ case "manga": {
1920
+ let query = args.join(" ").trim();
1921
+ if (!query) {
1922
+ const qInput = await p.text({
1923
+ message: "Enter comic/manga title to search:",
1924
+ placeholder: "e.g. solo leveling",
1925
+ validate: (v) => (!v || !v.trim() ? "Title required." : undefined),
1926
+ });
1927
+ if (p.isCancel(qInput)) break;
1928
+ query = qInput.trim();
1929
+ }
1930
+ await handleSearchAndDownload(query, "comic", {
1931
+ ...values,
1932
+ output: currentOutputDir,
1933
+ });
1247
1934
  break;
1248
1935
  }
1249
1936
 
1250
1937
  case "play": {
1251
- const items = getHistory(15);
1938
+ const items = getHistory(25);
1939
+ if (items.length === 0) {
1940
+ p.log.warn("No download history found to play.");
1941
+ break;
1942
+ }
1943
+
1252
1944
  let targetItem = null;
1253
1945
  let targetNum = 1;
1254
1946
 
@@ -1266,13 +1958,6 @@ async function main() {
1266
1958
  } else {
1267
1959
  const customPath = path.resolve(args.join(" "));
1268
1960
  if (fs.existsSync(customPath)) {
1269
- const ext = path.extname(customPath).toLowerCase();
1270
- if (ext !== ".mp4" && ext !== ".mp3" && ext !== ".m4a") {
1271
- p.log.warn(
1272
- `Cannot play ${ext ? ext.toUpperCase() : "this"} file. /play is only for MP4 and MP3 (use /open to view files).`,
1273
- );
1274
- break;
1275
- }
1276
1961
  try {
1277
1962
  await openFile(customPath);
1278
1963
  p.log.step(`${pc.bold("Playing:")} ${pc.dim(customPath)}`);
@@ -1281,27 +1966,40 @@ async function main() {
1281
1966
  }
1282
1967
  break;
1283
1968
  }
1969
+ p.log.error(`File does not exist: ${customPath}`);
1970
+ break;
1284
1971
  }
1285
1972
  } else {
1286
- if (items.length > 0) {
1287
- const playIdx = items.findIndex((it) => {
1288
- const ext = path
1289
- .extname(it.path || it.filename || "")
1290
- .toLowerCase();
1291
- return ext === ".mp4" || ext === ".mp3" || ext === ".m4a";
1292
- });
1293
- if (playIdx !== -1) {
1294
- targetItem = items[playIdx];
1295
- targetNum = playIdx + 1;
1296
- } else {
1297
- targetItem = items[0];
1298
- }
1299
- }
1300
- }
1973
+ const selectChoice = await p.select({
1974
+ message: "Select media to play:",
1975
+ options: [
1976
+ ...items.map((it, idx) => {
1977
+ const ext = path
1978
+ .extname(it.path || it.filename || "")
1979
+ .toLowerCase();
1980
+ const typeLabel =
1981
+ ext === ".mp4" || ext === ".mkv" || ext === ".webm"
1982
+ ? "VIDEO"
1983
+ : ext === ".mp3" || ext === ".m4a" || ext === ".wav"
1984
+ ? "AUDIO"
1985
+ : ext === ".pdf"
1986
+ ? "PDF"
1987
+ : ext.slice(1).toUpperCase() || "MEDIA";
1988
+ return {
1989
+ value: idx,
1990
+ label: `[#${idx + 1}] ${it.filename || it.title || "Media"}`,
1991
+ hint: `${it.platform || "media"} • ${typeLabel}`,
1992
+ };
1993
+ }),
1994
+ { value: -1, label: pc.dim("Cancel") },
1995
+ ],
1996
+ });
1301
1997
 
1302
- if (!targetItem) {
1303
- p.log.warn("No downloaded media found in history to play.");
1304
- break;
1998
+ if (p.isCancel(selectChoice) || selectChoice === -1) {
1999
+ break;
2000
+ }
2001
+ targetItem = items[selectChoice];
2002
+ targetNum = selectChoice + 1;
1305
2003
  }
1306
2004
 
1307
2005
  if (!targetItem.path || !fs.existsSync(targetItem.path)) {
@@ -1311,20 +2009,6 @@ async function main() {
1311
2009
  break;
1312
2010
  }
1313
2011
 
1314
- const fileExt = path
1315
- .extname(targetItem.path || targetItem.filename || "")
1316
- .toLowerCase();
1317
- if (
1318
- fileExt !== ".mp4" &&
1319
- fileExt !== ".mp3" &&
1320
- fileExt !== ".m4a"
1321
- ) {
1322
- p.log.warn(
1323
- `Item #${targetNum} is a ${fileExt ? fileExt.toUpperCase() : "non-audio/video"} file. /play is only for MP4 and MP3 (type /open to view files).`,
1324
- );
1325
- break;
1326
- }
1327
-
1328
2012
  try {
1329
2013
  await openFile(targetItem.path);
1330
2014
  p.log.step(
@@ -1339,63 +2023,96 @@ async function main() {
1339
2023
  case "delete":
1340
2024
  case "del":
1341
2025
  case "rm": {
1342
- const items = getHistory(20);
2026
+ const items = getHistory(25);
1343
2027
  if (items.length === 0) {
1344
2028
  p.log.warn("No download history to delete.");
1345
2029
  break;
1346
2030
  }
1347
2031
 
1348
- let targetIndex = -1;
2032
+ let targetIndices = [];
1349
2033
 
1350
2034
  if (args[0]) {
1351
- const numArg = parseInt(args[0], 10);
1352
- if (isNaN(numArg) || numArg < 1 || numArg > items.length) {
2035
+ const rawIndices = args[0]
2036
+ .split(",")
2037
+ .map((s) => parseInt(s.trim(), 10));
2038
+ const validIndices = rawIndices
2039
+ .filter((n) => !isNaN(n) && n >= 1 && n <= items.length)
2040
+ .map((n) => n - 1);
2041
+
2042
+ if (validIndices.length === 0) {
1353
2043
  p.log.warn(
1354
2044
  `Invalid index. Available range: 1 to ${items.length}.`,
1355
2045
  );
1356
2046
  break;
1357
2047
  }
1358
- targetIndex = numArg - 1;
2048
+ targetIndices = validIndices;
1359
2049
  } else {
1360
- const selectChoice = await p.select({
1361
- message: "Select item to delete:",
2050
+ const selectedChoices = await p.multiselect({
2051
+ message:
2052
+ "Select item(s) to delete (Space to toggle, Enter to confirm):",
1362
2053
  options: [
1363
2054
  ...items.map((it, idx) => ({
1364
2055
  value: idx,
1365
2056
  label: `[#${idx + 1}] ${it.filename || it.title || "Media"}`,
1366
2057
  hint: it.platform || "",
1367
2058
  })),
1368
- { value: -1, label: pc.dim("Cancel") },
1369
2059
  ],
2060
+ required: false,
1370
2061
  });
1371
2062
 
1372
- if (p.isCancel(selectChoice) || selectChoice === -1) {
2063
+ if (p.isCancel(selectedChoices) || selectedChoices.length === 0) {
2064
+ p.log.step(pc.dim("Deletion cancelled."));
1373
2065
  break;
1374
2066
  }
1375
- targetIndex = selectChoice;
2067
+ targetIndices = selectedChoices;
1376
2068
  }
1377
2069
 
1378
- const itemToDelete = items[targetIndex];
1379
- const confirm = await p.confirm({
1380
- message: `Delete "${itemToDelete.filename || itemToDelete.title}" from disk and history?`,
1381
- initialValue: false,
2070
+ const targetNames = targetIndices
2071
+ .map(
2072
+ (i) => `[#${i + 1}] ${items[i]?.filename || items[i]?.title}`,
2073
+ )
2074
+ .join(", ");
2075
+
2076
+ const deleteMode = await p.select({
2077
+ message:
2078
+ targetIndices.length === 1
2079
+ ? `Delete "${items[targetIndices[0]]?.filename || items[targetIndices[0]]?.title}":`
2080
+ : `Delete ${targetIndices.length} item(s) (${targetNames}):`,
2081
+ options: [
2082
+ {
2083
+ value: "both",
2084
+ label: "Delete from disk & remove from history",
2085
+ hint: "Permanently deletes the physical file",
2086
+ },
2087
+ {
2088
+ value: "history",
2089
+ label: "Remove from history only",
2090
+ hint: "Keeps the file safe on disk",
2091
+ },
2092
+ { value: "cancel", label: pc.dim("Cancel") },
2093
+ ],
1382
2094
  });
1383
2095
 
1384
- if (p.isCancel(confirm) || !confirm) {
2096
+ if (p.isCancel(deleteMode) || deleteMode === "cancel") {
1385
2097
  p.log.step(pc.dim("Deletion cancelled."));
1386
2098
  break;
1387
2099
  }
1388
2100
 
1389
- const res = deleteHistoryItem(targetIndex, true);
2101
+ const deleteFromDisk = deleteMode === "both";
2102
+ const res = deleteHistoryItems(targetIndices, deleteFromDisk);
1390
2103
  if (res.success) {
1391
- const fileNote = res.fileDeleted
1392
- ? pc.dim("(deleted from disk & removed from history)")
1393
- : pc.dim("(removed from history; file was not on disk)");
2104
+ const fileNote = deleteFromDisk
2105
+ ? res.filesDeletedCount > 0
2106
+ ? pc.dim(
2107
+ `(${res.filesDeletedCount} file(s) deleted from disk & removed from history)`,
2108
+ )
2109
+ : pc.dim(`(removed from history; file(s) not found on disk)`)
2110
+ : pc.dim(`(removed from history; file(s) preserved on disk)`);
1394
2111
  p.log.step(
1395
- `${pc.bold("✔ Deleted:")} ${pc.white(itemToDelete.filename || itemToDelete.title)} ${fileNote}`,
2112
+ `${pc.bold("✔ Deleted:")} ${pc.white(`${res.count} item(s)`)} ${fileNote}`,
1396
2113
  );
1397
2114
  } else {
1398
- p.log.error(`Failed to delete item: ${res.error}`);
2115
+ p.log.error(`Failed to delete items: ${res.error}`);
1399
2116
  }
1400
2117
  break;
1401
2118
  }
@@ -1623,14 +2340,24 @@ async function main() {
1623
2340
  options: [
1624
2341
  {
1625
2342
  value: "reinstall_mori",
1626
- label: "Reinstall Mori Engine (~80 KB)",
2343
+ label: "Reinstall Latest Mori Engine (~80 KB)",
1627
2344
  hint: moriInst ? "Re-fetch latest bundle" : "Install",
1628
2345
  },
1629
2346
  {
1630
2347
  value: "reinstall_scrapr",
1631
- label: "Reinstall Scrapr Engine (~2.7 MB)",
2348
+ label: "Reinstall Latest Scrapr Engine (~2.7 MB)",
1632
2349
  hint: scraprInst ? "Re-fetch latest bundle" : "Install",
1633
2350
  },
2351
+ {
2352
+ value: "version_mori",
2353
+ label: "Choose / Downgrade Mori Core Version...",
2354
+ hint: "Install specific commit from GitHub",
2355
+ },
2356
+ {
2357
+ value: "version_scrapr",
2358
+ label: "Choose / Downgrade Scrapr Engine Version...",
2359
+ hint: "Install specific release from NPM",
2360
+ },
1634
2361
  ...(moriInst
1635
2362
  ? [
1636
2363
  {
@@ -1673,6 +2400,10 @@ async function main() {
1673
2400
  } catch (err) {
1674
2401
  s.stop(pc.bold(`✕ Failed: ${err.message}`));
1675
2402
  }
2403
+ } else if (mgmtChoice === "version_mori") {
2404
+ await handleRollbackMori();
2405
+ } else if (mgmtChoice === "version_scrapr") {
2406
+ await handleRollbackScrapr();
1676
2407
  } else if (mgmtChoice === "uninstall_mori") {
1677
2408
  uninstallMoriEngine();
1678
2409
  p.log.message(pc.dim("✔ Mori Engine uninstalled."));
@@ -1732,6 +2463,35 @@ async function main() {
1732
2463
  break;
1733
2464
  }
1734
2465
 
2466
+ case "rollback":
2467
+ case "downgrade": {
2468
+ const rbChoice = await p.select({
2469
+ message: "Select engine to rollback / choose version:",
2470
+ options: [
2471
+ {
2472
+ value: "mori",
2473
+ label: "Mori Core Engine",
2474
+ hint: `Current: v${getActiveScraperVersion() || "not installed"}`,
2475
+ },
2476
+ {
2477
+ value: "scrapr",
2478
+ label: "Scrapr Engine",
2479
+ hint: `Current: v${getActiveScraprVersion() || "not installed"}`,
2480
+ },
2481
+ { value: "cancel", label: pc.dim("Cancel") },
2482
+ ],
2483
+ });
2484
+
2485
+ if (p.isCancel(rbChoice) || rbChoice === "cancel") break;
2486
+
2487
+ if (rbChoice === "mori") {
2488
+ await handleRollbackMori();
2489
+ } else if (rbChoice === "scrapr") {
2490
+ await handleRollbackScrapr();
2491
+ }
2492
+ break;
2493
+ }
2494
+
1735
2495
  case "clip":
1736
2496
  case "paste": {
1737
2497
  const s = p.spinner();
@@ -1806,13 +2566,14 @@ async function main() {
1806
2566
  break;
1807
2567
  }
1808
2568
 
1809
- const items = getHistory(15);
2569
+ const items = getHistory(25);
1810
2570
  if (items.length === 0) {
1811
2571
  p.log.message(pc.dim("No download history yet."));
1812
2572
  break;
1813
2573
  }
1814
2574
 
1815
- // Check if user specified an iteration number, e.g. /history 1
2575
+ let selectedIndex = -1;
2576
+
1816
2577
  const numArg = parseInt(args[0], 10);
1817
2578
  if (!isNaN(numArg)) {
1818
2579
  if (numArg < 1 || numArg > items.length) {
@@ -1821,40 +2582,56 @@ async function main() {
1821
2582
  );
1822
2583
  break;
1823
2584
  }
1824
- const selected = items[numArg - 1];
1825
- if (!selected.url) {
1826
- p.log.warn(
1827
- `Item #${numArg} has no recorded source URL (downloaded prior to URL tracking).`,
1828
- );
2585
+ selectedIndex = numArg - 1;
2586
+ } else {
2587
+ const choice = await p.select({
2588
+ message: "Download History (Select to re-download):",
2589
+ options: [
2590
+ ...items.map((it, idx) => ({
2591
+ value: idx,
2592
+ label: `[#${idx + 1}] ${it.filename || it.title || "Media"}`,
2593
+ hint: `${it.platform?.toUpperCase() || ""}${it.timestamp ? ` • ${formatRelativeTime(it.timestamp)}` : ""}`,
2594
+ })),
2595
+ { value: "clear", label: pc.red("🗑 Clear all history") },
2596
+ { value: "cancel", label: pc.dim("Cancel") },
2597
+ ],
2598
+ });
2599
+
2600
+ if (p.isCancel(choice) || choice === "cancel") {
1829
2601
  break;
1830
2602
  }
1831
- p.log.message(
1832
- `${pc.bold("● Re-downloading from history:")} ${pc.inverse(` ${selected.platform?.toUpperCase()} `)} ${pc.dim(selected.url)}`,
2603
+
2604
+ if (choice === "clear") {
2605
+ const confirmClear = await p.confirm({
2606
+ message:
2607
+ "Are you sure you want to clear all download history?",
2608
+ initialValue: false,
2609
+ });
2610
+ if (confirmClear && !p.isCancel(confirmClear)) {
2611
+ clearHistory();
2612
+ p.log.message(pc.dim("Download history cleared."));
2613
+ }
2614
+ break;
2615
+ }
2616
+
2617
+ selectedIndex = choice;
2618
+ }
2619
+
2620
+ const selected = items[selectedIndex];
2621
+ if (!selected.url) {
2622
+ p.log.warn(
2623
+ `Item #${selectedIndex + 1} has no recorded source URL (downloaded prior to URL tracking).`,
1833
2624
  );
1834
- lastUrl = selected.url;
1835
- await handleScrapeAndDownload(selected.url, {
1836
- ...values,
1837
- output: currentOutputDir,
1838
- });
1839
2625
  break;
1840
2626
  }
1841
-
1842
- const historyLines = items.map((it, idx) => {
1843
- const num = pc.bold(`[${idx + 1}]`);
1844
- const badge = pc.inverse(` ${it.platform.toUpperCase()} `);
1845
- const name = pc.bold(it.filename || it.title || "Media");
1846
- const rel = it.timestamp
1847
- ? pc.dim(`(${formatRelativeTime(it.timestamp)})`)
1848
- : "";
1849
- return `${num} ${badge} ${name} ${rel}`;
1850
- });
1851
-
1852
- p.note(
1853
- historyLines.join("\n"),
1854
- pc.dim(
1855
- `Recent Downloads (${items.length}) • /history <num> to redownload • /history clear to reset`,
1856
- ),
2627
+ p.log.message(
2628
+ `${pc.bold("● Re-downloading from history:")} ${pc.inverse(` ${selected.platform?.toUpperCase()} `)} ${pc.dim(selected.url)}`,
1857
2629
  );
2630
+ lastUrl = selected.url;
2631
+ await handleScrapeAndDownload(selected.url, {
2632
+ ...values,
2633
+ output: currentOutputDir,
2634
+ });
1858
2635
  break;
1859
2636
  }
1860
2637
 
@@ -2077,24 +2854,27 @@ async function main() {
2077
2854
  case "help":
2078
2855
  case "?": {
2079
2856
  const cmds = [
2857
+ `${pc.bold("/anime [query]")} Search and download anime episodes`,
2858
+ `${pc.bold("/comic [query]")} Search and download comic chapters (supports PDF)`,
2080
2859
  `${pc.bold("/clip")} Download link currently in clipboard`,
2081
2860
  `${pc.bold("/audio [url]")} Download audio stream only (MP3/M4A)`,
2082
2861
  `${pc.bold("/pdf [url]")} Download photo album compiled directly into 1 PDF`,
2083
- `${pc.bold("/play [num]")} Play downloaded media in default system player`,
2862
+ `${pc.bold("/play [num]")} Interactive media player picker (or /play <num>)`,
2084
2863
  `${pc.bold("/ping [host]")} Check user network latency (default: 1.1.1.1)`,
2085
2864
  `${pc.bold("/info [url]")} Inspect media details without downloading`,
2086
2865
  `${pc.bold("/retry")} Re-download the last link processed`,
2087
2866
  `${pc.bold("/batch")} Bulk download multiple links at once`,
2088
- `${pc.bold("/platform")} List all 27 supported media platforms`,
2867
+ `${pc.bold("/platform")} List all 40 supported media platforms`,
2089
2868
  `${pc.bold("/dir")} View or set download directory (persistent)`,
2090
2869
  `${pc.bold("/open")} Open download folder in file manager`,
2091
2870
  `${pc.bold("/engine")} Set default extraction engine (auto/mori/scrapr)`,
2092
2871
  `${pc.bold("/server")} Set default scraper server (auto/1/2)`,
2093
- `${pc.bold("/history [num]")} View or redownload history item (/history 1, /history clear)`,
2094
- `${pc.bold("/delete [num]")} Delete downloaded file from disk and history`,
2872
+ `${pc.bold("/history")} Interactive download history & redownload picker`,
2873
+ `${pc.bold("/delete")} Interactive bulk delete from disk & history (Space)`,
2095
2874
  `${pc.bold("/stats")} View total downloads & storage statistics`,
2096
2875
  `${pc.bold("/config")} Show active Mori configuration`,
2097
2876
  `${pc.bold("/update")} Check and apply remote OTA scraper patches`,
2877
+ `${pc.bold("/rollback")} Rollback or install specific engine versions`,
2098
2878
  `${pc.bold("/reset")} Factory reset Mori config, cache, & history`,
2099
2879
  `${pc.bold("/clear")} Clear screen and reprint header`,
2100
2880
  `${pc.bold("/exit, /q")} Exit Mori CLI`,
@@ -2122,10 +2902,17 @@ async function main() {
2122
2902
  }
2123
2903
 
2124
2904
  lastUrl = rawInput;
2125
- await handleScrapeAndDownload(rawInput, {
2126
- ...values,
2127
- output: currentOutputDir,
2128
- });
2905
+ if (!rawInput.startsWith("http://") && !rawInput.startsWith("https://")) {
2906
+ await handleSearchAndDownload(rawInput, null, {
2907
+ ...values,
2908
+ output: currentOutputDir,
2909
+ });
2910
+ } else {
2911
+ await handleScrapeAndDownload(rawInput, {
2912
+ ...values,
2913
+ output: currentOutputDir,
2914
+ });
2915
+ }
2129
2916
 
2130
2917
  const next = await p.confirm({
2131
2918
  message: "Continue?",