@coflyn/mori 1.1.0 → 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/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;
@@ -410,17 +416,28 @@ async function processDownloadItem({ item, meta, outputDir, index, total }) {
410
416
 
411
417
  let finalBytes = 0;
412
418
  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
- });
419
+ await downloadMediaFile(
420
+ directUrl,
421
+ destPath,
422
+ (prog) => {
423
+ finalBytes = prog.downloadedBytes;
424
+ const bar = renderProgressBar(prog.percent, 20);
425
+ const pct = `${prog.percent.toFixed(0)}%`.padStart(4);
426
+ const dl = formatBytes(prog.downloadedBytes);
427
+ const tot = prog.totalBytes > 0 ? formatBytes(prog.totalBytes) : "?";
428
+ const spd = `${formatBytes(prog.speedBps)}/s`;
429
+
430
+ const line = ` ${bar} ${pc.bold(pct)} ${pc.dim(`(${dl}/${tot} • ${spd})`)}`;
431
+ process.stdout.write(`\r${line}\x1b[K`);
432
+ },
433
+ {
434
+ ...(meta.url ? { Referer: meta.url } : {}),
435
+ ...(directUrl.includes("googlevideo.com")
436
+ ? { Referer: "https://desustream.net/" }
437
+ : {}),
438
+ ...(item.headers || {}),
439
+ },
440
+ );
424
441
 
425
442
  process.stdout.write("\r\x1b[2K");
426
443
  p.log.message(
@@ -829,6 +846,7 @@ async function handleScrapeAndDownload(targetUrl, options) {
829
846
  headers: {
830
847
  "User-Agent": CHROME_UA,
831
848
  Accept: "*/*",
849
+ ...(media.url ? { Referer: media.url } : {}),
832
850
  ...(item.headers || {}),
833
851
  },
834
852
  });
@@ -994,6 +1012,23 @@ async function handleScrapeAndDownload(targetUrl, options) {
994
1012
  selectedItem = downloads[formatChoice];
995
1013
  }
996
1014
 
1015
+ if (selectedItem?.type === "link") {
1016
+ const linkUrl = selectedItem.url;
1017
+ await writeClipboard(linkUrl);
1018
+ p.log.success(
1019
+ `${pc.bold("✔ Mirror link copied to clipboard:")} ${pc.underline(pc.cyan(linkUrl))}`,
1020
+ );
1021
+ addToHistory({
1022
+ url: targetUrl,
1023
+ title: `${media.title || "Media"} (${selectedItem.quality || "Mirror"})`,
1024
+ platform: media.platform,
1025
+ filename: "",
1026
+ path: linkUrl,
1027
+ bytes: 0,
1028
+ });
1029
+ return true;
1030
+ }
1031
+
997
1032
  await processDownloadItem({
998
1033
  item: selectedItem,
999
1034
  meta: media,
@@ -1006,6 +1041,460 @@ async function handleScrapeAndDownload(targetUrl, options) {
1006
1041
  return true;
1007
1042
  }
1008
1043
 
1044
+ async function handleSearchAndDownload(query, forcedType = null, options = {}) {
1045
+ const scrapr = loadScraprEngine();
1046
+ let provider = null;
1047
+
1048
+ if (forcedType === "anime") {
1049
+ const chosen = await p.select({
1050
+ message: `Select Anime Provider for "${query}":`,
1051
+ options: [
1052
+ { value: "otakudesu", label: "Otakudesu (Indonesian Sub)" },
1053
+ { value: "gogoanime", label: "Gogoanime (English Sub)" },
1054
+ ],
1055
+ });
1056
+ if (p.isCancel(chosen)) return false;
1057
+ provider = chosen;
1058
+ } else if (forcedType === "comic") {
1059
+ const chosen = await p.select({
1060
+ message: `Select Comic Provider for "${query}":`,
1061
+ options: [
1062
+ { value: "komikindo", label: "Komikindo (Indonesian)" },
1063
+ { value: "komiku", label: "Komiku (Indonesian)" },
1064
+ { value: "asurascans", label: "Asura Scans (English / Manhwa)" },
1065
+ ],
1066
+ });
1067
+ if (p.isCancel(chosen)) return false;
1068
+ provider = chosen;
1069
+ } else {
1070
+ const chosen = await p.select({
1071
+ message: `Search query "${query}":`,
1072
+ options: [
1073
+ { value: "otakudesu", label: "Anime • Otakudesu (Sub Indo)" },
1074
+ { value: "gogoanime", label: "Anime • Gogoanime (Sub Eng)" },
1075
+ { value: "komikindo", label: "Comic • Komikindo (Sub Indo)" },
1076
+ { value: "komiku", label: "Comic • Komiku (Sub Indo)" },
1077
+ { value: "asurascans", label: "Comic • Asura Scans (English)" },
1078
+ ],
1079
+ });
1080
+ if (p.isCancel(chosen)) return false;
1081
+ provider = chosen;
1082
+ }
1083
+
1084
+ const s = p.spinner();
1085
+
1086
+ if (provider === "otakudesu") {
1087
+ s.start(pc.dim(`Searching Otakudesu for "${query}"...`));
1088
+ let searchRes;
1089
+ try {
1090
+ searchRes = await scrapr.anime.otakudesu.search(query);
1091
+ } catch (err) {
1092
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1093
+ return false;
1094
+ }
1095
+ s.stop(pc.dim("Search complete."));
1096
+
1097
+ const items = searchRes?.result || [];
1098
+ if (items.length === 0) {
1099
+ p.log.warn(`No anime found for "${query}" on Otakudesu.`);
1100
+ return false;
1101
+ }
1102
+
1103
+ const animeChoices = items.map((it) => ({
1104
+ value: it.url,
1105
+ label: `${it.title} ${it.meta ? pc.dim(`(${it.meta})`) : ""}`,
1106
+ }));
1107
+ animeChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1108
+
1109
+ const chosenAnimeUrl = await p.select({
1110
+ message: `Select Anime (${items.length} found):`,
1111
+ options: animeChoices,
1112
+ });
1113
+ if (p.isCancel(chosenAnimeUrl) || chosenAnimeUrl === "cancel") {
1114
+ p.cancel("Cancelled.");
1115
+ return false;
1116
+ }
1117
+
1118
+ s.start(pc.dim("Fetching episode list..."));
1119
+ let epRes;
1120
+ try {
1121
+ epRes = await scrapr.anime.otakudesu.getEpisodes(chosenAnimeUrl);
1122
+ } catch (err) {
1123
+ s.stop(pc.bold(`✕ Failed to fetch episodes: ${err.message}`));
1124
+ return false;
1125
+ }
1126
+ s.stop(pc.dim("Episodes fetched."));
1127
+
1128
+ const episodes = epRes?.result || [];
1129
+ if (episodes.length === 0) {
1130
+ p.log.warn("No episodes found for this anime.");
1131
+ return false;
1132
+ }
1133
+
1134
+ const epChoices = episodes.map((ep) => ({
1135
+ value: ep.url,
1136
+ label: ep.title,
1137
+ }));
1138
+ epChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1139
+
1140
+ const chosenEpUrl = await p.select({
1141
+ message: `Select Episode (${episodes.length} episodes):`,
1142
+ options: epChoices,
1143
+ });
1144
+ if (p.isCancel(chosenEpUrl) || chosenEpUrl === "cancel") {
1145
+ p.cancel("Cancelled.");
1146
+ return false;
1147
+ }
1148
+
1149
+ return await handleScrapeAndDownload(chosenEpUrl, options);
1150
+ }
1151
+
1152
+ if (provider === "gogoanime") {
1153
+ s.start(pc.dim(`Searching Gogoanime for "${query}"...`));
1154
+ let searchRes;
1155
+ try {
1156
+ searchRes = await scrapr.anime.gogoanime.search(query);
1157
+ } catch (err) {
1158
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1159
+ return false;
1160
+ }
1161
+ s.stop(pc.dim("Search complete."));
1162
+
1163
+ const items = searchRes?.result || [];
1164
+ if (items.length === 0) {
1165
+ p.log.warn(`No anime found for "${query}" on Gogoanime.`);
1166
+ return false;
1167
+ }
1168
+
1169
+ const animeChoices = items.map((it) => ({
1170
+ value: it.url,
1171
+ label: it.title,
1172
+ }));
1173
+ animeChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1174
+
1175
+ const chosenAnimeUrl = await p.select({
1176
+ message: `Select Anime (${items.length} found):`,
1177
+ options: animeChoices,
1178
+ });
1179
+ if (p.isCancel(chosenAnimeUrl) || chosenAnimeUrl === "cancel") {
1180
+ p.cancel("Cancelled.");
1181
+ return false;
1182
+ }
1183
+
1184
+ s.start(pc.dim("Fetching episode list..."));
1185
+ let epRes;
1186
+ try {
1187
+ epRes = await scrapr.anime.gogoanime.getEpisodes(chosenAnimeUrl);
1188
+ } catch (err) {
1189
+ s.stop(pc.bold(`✕ Failed to fetch episodes: ${err.message}`));
1190
+ return false;
1191
+ }
1192
+ s.stop(pc.dim("Episodes fetched."));
1193
+
1194
+ const episodes = epRes?.result || [];
1195
+ if (episodes.length === 0) {
1196
+ p.log.warn("No episodes found for this anime.");
1197
+ return false;
1198
+ }
1199
+
1200
+ const epChoices = episodes.slice(0, 100).map((ep) => ({
1201
+ value: ep.url,
1202
+ label: ep.title,
1203
+ }));
1204
+ epChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1205
+
1206
+ const chosenEpUrl = await p.select({
1207
+ message: `Select Episode (${episodes.length} episodes):`,
1208
+ options: epChoices,
1209
+ });
1210
+ if (p.isCancel(chosenEpUrl) || chosenEpUrl === "cancel") {
1211
+ p.cancel("Cancelled.");
1212
+ return false;
1213
+ }
1214
+
1215
+ return await handleScrapeAndDownload(chosenEpUrl, options);
1216
+ }
1217
+
1218
+ if (provider === "komikindo") {
1219
+ s.start(pc.dim(`Searching Komikindo for "${query}"...`));
1220
+ let searchRes;
1221
+ try {
1222
+ searchRes = await scrapr.comic.komikindo.search(query);
1223
+ } catch (err) {
1224
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1225
+ return false;
1226
+ }
1227
+ s.stop(pc.dim("Search complete."));
1228
+
1229
+ const items = searchRes?.result || [];
1230
+ if (items.length === 0) {
1231
+ p.log.warn(`No comics found for "${query}" on Komikindo.`);
1232
+ return false;
1233
+ }
1234
+
1235
+ const comicChoices = items.map((it) => ({
1236
+ value: it.url,
1237
+ label: it.title,
1238
+ }));
1239
+ comicChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1240
+
1241
+ const chosenComicUrl = await p.select({
1242
+ message: `Select Comic (${items.length} found):`,
1243
+ options: comicChoices,
1244
+ });
1245
+ if (p.isCancel(chosenComicUrl) || chosenComicUrl === "cancel") {
1246
+ p.cancel("Cancelled.");
1247
+ return false;
1248
+ }
1249
+
1250
+ s.start(pc.dim("Fetching chapter list..."));
1251
+ let chRes;
1252
+ try {
1253
+ chRes = await scrapr.comic.komikindo.getChapters(chosenComicUrl);
1254
+ } catch (err) {
1255
+ s.stop(pc.bold(`✕ Failed to fetch chapters: ${err.message}`));
1256
+ return false;
1257
+ }
1258
+ s.stop(pc.dim("Chapters fetched."));
1259
+
1260
+ const chapters = chRes?.result || [];
1261
+ if (chapters.length === 0) {
1262
+ p.log.warn("No chapters found for this comic.");
1263
+ return false;
1264
+ }
1265
+
1266
+ const chChoices = chapters.slice(0, 100).map((ch) => ({
1267
+ value: ch.url,
1268
+ label: ch.title,
1269
+ }));
1270
+ chChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1271
+
1272
+ const chosenChUrl = await p.select({
1273
+ message: `Select Chapter (${chapters.length} available):`,
1274
+ options: chChoices,
1275
+ });
1276
+ if (p.isCancel(chosenChUrl) || chosenChUrl === "cancel") {
1277
+ p.cancel("Cancelled.");
1278
+ return false;
1279
+ }
1280
+
1281
+ return await handleScrapeAndDownload(chosenChUrl, options);
1282
+ }
1283
+
1284
+ if (provider === "komiku") {
1285
+ s.start(pc.dim(`Searching Komiku for "${query}"...`));
1286
+ let searchRes;
1287
+ try {
1288
+ searchRes = await scrapr.comic.komiku.search(query);
1289
+ } catch (err) {
1290
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1291
+ return false;
1292
+ }
1293
+ s.stop(pc.dim("Search complete."));
1294
+
1295
+ const items = searchRes?.result || [];
1296
+ if (items.length === 0) {
1297
+ p.log.warn(`No comics found for "${query}" on Komiku.`);
1298
+ return false;
1299
+ }
1300
+
1301
+ const comicChoices = items.map((it) => ({
1302
+ value: it.url,
1303
+ label: it.title,
1304
+ }));
1305
+ comicChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1306
+
1307
+ const chosenComicUrl = await p.select({
1308
+ message: `Select Comic (${items.length} found):`,
1309
+ options: comicChoices,
1310
+ });
1311
+ if (p.isCancel(chosenComicUrl) || chosenComicUrl === "cancel") {
1312
+ p.cancel("Cancelled.");
1313
+ return false;
1314
+ }
1315
+
1316
+ s.start(pc.dim("Fetching chapter list..."));
1317
+ let chRes;
1318
+ try {
1319
+ chRes = await scrapr.comic.komiku.getChapters(chosenComicUrl);
1320
+ } catch (err) {
1321
+ s.stop(pc.bold(`✕ Failed to fetch chapters: ${err.message}`));
1322
+ return false;
1323
+ }
1324
+ s.stop(pc.dim("Chapters fetched."));
1325
+
1326
+ const chapters = chRes?.result || [];
1327
+ if (chapters.length === 0) {
1328
+ p.log.warn("No chapters found for this comic.");
1329
+ return false;
1330
+ }
1331
+
1332
+ const chChoices = chapters.slice(0, 100).map((ch) => ({
1333
+ value: ch.url,
1334
+ label: ch.title,
1335
+ }));
1336
+ chChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1337
+
1338
+ const chosenChUrl = await p.select({
1339
+ message: `Select Chapter (${chapters.length} available):`,
1340
+ options: chChoices,
1341
+ });
1342
+ if (p.isCancel(chosenChUrl) || chosenChUrl === "cancel") {
1343
+ p.cancel("Cancelled.");
1344
+ return false;
1345
+ }
1346
+
1347
+ return await handleScrapeAndDownload(chosenChUrl, options);
1348
+ }
1349
+
1350
+ if (provider === "asurascans") {
1351
+ s.start(pc.dim(`Searching Asura Scans for "${query}"...`));
1352
+ let searchRes;
1353
+ try {
1354
+ searchRes = await scrapr.comic.asurascans.search(query);
1355
+ } catch (err) {
1356
+ s.stop(pc.bold(`✕ Search failed: ${err.message}`));
1357
+ return false;
1358
+ }
1359
+ s.stop(pc.dim("Search complete."));
1360
+
1361
+ const items = searchRes?.result || [];
1362
+ if (items.length === 0) {
1363
+ p.log.warn(`No comics found for "${query}" on Asura Scans.`);
1364
+ return false;
1365
+ }
1366
+
1367
+ const comicChoices = items.map((it) => ({
1368
+ value: it.url,
1369
+ label: `${it.title} ${it.status ? pc.dim(`[${it.status}]`) : ""}`,
1370
+ }));
1371
+ comicChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1372
+
1373
+ const chosenComicUrl = await p.select({
1374
+ message: `Select Comic (${items.length} found):`,
1375
+ options: comicChoices,
1376
+ });
1377
+ if (p.isCancel(chosenComicUrl) || chosenComicUrl === "cancel") {
1378
+ p.cancel("Cancelled.");
1379
+ return false;
1380
+ }
1381
+
1382
+ s.start(pc.dim("Fetching chapter list..."));
1383
+ let chRes;
1384
+ try {
1385
+ chRes = await scrapr.comic.asurascans.getChapters(chosenComicUrl);
1386
+ } catch (err) {
1387
+ s.stop(pc.bold(`✕ Failed to fetch chapters: ${err.message}`));
1388
+ return false;
1389
+ }
1390
+ s.stop(pc.dim("Chapters fetched."));
1391
+
1392
+ const chapters = chRes?.result || [];
1393
+ if (chapters.length === 0) {
1394
+ p.log.warn("No chapters found for this comic.");
1395
+ return false;
1396
+ }
1397
+
1398
+ const chChoices = chapters.slice(0, 100).map((ch) => ({
1399
+ value: ch.url,
1400
+ label: ch.title,
1401
+ }));
1402
+ chChoices.push({ value: "cancel", label: pc.dim("Cancel") });
1403
+
1404
+ const chosenChUrl = await p.select({
1405
+ message: `Select Chapter (${chapters.length} available):`,
1406
+ options: chChoices,
1407
+ });
1408
+ if (p.isCancel(chosenChUrl) || chosenChUrl === "cancel") {
1409
+ p.cancel("Cancelled.");
1410
+ return false;
1411
+ }
1412
+
1413
+ return await handleScrapeAndDownload(chosenChUrl, options);
1414
+ }
1415
+
1416
+ return false;
1417
+ }
1418
+
1419
+ async function handleRollbackMori() {
1420
+ const s = p.spinner();
1421
+ s.start(pc.dim("Fetching Mori Engine commit history from GitHub..."));
1422
+ const history = await fetchMoriEngineHistory();
1423
+ s.stop(pc.dim("History fetched."));
1424
+
1425
+ if (history.length === 0) {
1426
+ p.log.warn("Could not fetch Mori Core commit history from GitHub.");
1427
+ return false;
1428
+ }
1429
+
1430
+ const currentVer = getActiveScraperVersion();
1431
+ const commitChoice = await p.select({
1432
+ message: `Select Mori Core version / commit (Current: v${currentVer || "none"}):`,
1433
+ options: [
1434
+ ...history.map((h, idx) => ({
1435
+ value: h.fullSha,
1436
+ label: `[${h.sha}] ${h.message}`,
1437
+ hint: `${idx === 0 ? "Latest • " : ""}${h.date ? h.date.split("T")[0] : ""}`,
1438
+ })),
1439
+ { value: "cancel", label: pc.dim("Cancel") },
1440
+ ],
1441
+ });
1442
+
1443
+ if (p.isCancel(commitChoice) || commitChoice === "cancel") return false;
1444
+
1445
+ const dlSpin = p.spinner();
1446
+ dlSpin.start(pc.dim("Downloading Mori Core bundle..."));
1447
+ try {
1448
+ const res = await downloadMoriEngineByCommit(commitChoice, (msg) => {
1449
+ dlSpin.message(pc.dim(msg));
1450
+ });
1451
+ dlSpin.stop(pc.bold(`✔ Mori Core Engine installed (v${res.version}).`));
1452
+ return true;
1453
+ } catch (err) {
1454
+ dlSpin.stop(pc.bold(`✕ Installation failed: ${err.message}`));
1455
+ return false;
1456
+ }
1457
+ }
1458
+
1459
+ async function handleRollbackScrapr() {
1460
+ const s = p.spinner();
1461
+ s.start(pc.dim("Fetching available Scrapr versions from NPM..."));
1462
+ const versions = await fetchScraprEngineVersions();
1463
+ s.stop(pc.dim("Versions fetched."));
1464
+
1465
+ if (versions.length === 0) {
1466
+ p.log.warn("Could not fetch Scrapr versions from registry.");
1467
+ return false;
1468
+ }
1469
+
1470
+ const currentVer = getActiveScraprVersion();
1471
+ const verChoice = await p.select({
1472
+ message: `Select Scrapr version to install (Current: v${currentVer || "none"}):`,
1473
+ options: [
1474
+ ...versions.slice(0, 15).map((v) => ({
1475
+ value: v,
1476
+ label: `v${v}${v === currentVer ? pc.green(" (current)") : ""}`,
1477
+ })),
1478
+ { value: "cancel", label: pc.dim("Cancel") },
1479
+ ],
1480
+ });
1481
+
1482
+ if (p.isCancel(verChoice) || verChoice === "cancel") return false;
1483
+
1484
+ const dlSpin = p.spinner();
1485
+ dlSpin.start(pc.dim(`Installing Scrapr Engine v${verChoice}...`));
1486
+ try {
1487
+ const res = await downloadScraprEngineVersion(verChoice, (msg) => {
1488
+ dlSpin.message(pc.dim(msg));
1489
+ });
1490
+ dlSpin.stop(pc.bold(`✔ Scrapr Engine v${res.version} installed.`));
1491
+ return true;
1492
+ } catch (err) {
1493
+ dlSpin.stop(pc.bold(`✕ Installation failed: ${err.message}`));
1494
+ return false;
1495
+ }
1496
+ }
1497
+
1009
1498
  async function main() {
1010
1499
  const { values, positionals } = parseArgs({
1011
1500
  args: process.argv.slice(2),
@@ -1163,6 +1652,26 @@ async function main() {
1163
1652
  let lastUrl = null;
1164
1653
 
1165
1654
  if (targetUrl) {
1655
+ const isUrl =
1656
+ targetUrl.startsWith("http://") || targetUrl.startsWith("https://");
1657
+ if (!isUrl) {
1658
+ lastUrl = targetUrl;
1659
+ await handleSearchAndDownload(targetUrl, null, {
1660
+ ...values,
1661
+ output: currentOutputDir,
1662
+ });
1663
+ const newVer = await cliUpdatePromise;
1664
+ if (newVer) {
1665
+ p.log.message(
1666
+ pc.yellow(
1667
+ `● Update available: v${APP_VERSION} → v${newVer} (run: npm i -g @coflyn/mori)`,
1668
+ ),
1669
+ );
1670
+ }
1671
+ p.outro(pc.dim("Complete."));
1672
+ process.exit(0);
1673
+ }
1674
+
1166
1675
  const platform = detectPlatform(targetUrl);
1167
1676
  if (!platform) {
1168
1677
  p.log.error(`Unsupported URL: ${targetUrl}`);
@@ -1198,17 +1707,22 @@ async function main() {
1198
1707
 
1199
1708
  while (keepGoing) {
1200
1709
  const urlInput = await p.text({
1201
- message: "Paste link:",
1202
- placeholder: "https://... or type /help",
1710
+ message: "Paste link or search title:",
1711
+ placeholder: "https://..., anime/comic title, or type /help",
1203
1712
  validate: (val) => {
1204
1713
  if (!val || val.trim().length === 0)
1205
- return "Please enter a URL or /command.";
1714
+ return "Please enter a URL, title, or /command.";
1206
1715
  const clean = val.trim().toLowerCase();
1207
1716
  if (clean === "exit" || clean === "quit" || clean === "q")
1208
1717
  return undefined;
1209
1718
  if (clean.startsWith("/")) return undefined;
1210
- if (!detectPlatform(val.trim())) {
1211
- return "Platform not supported. Type /platform to view supported platforms.";
1719
+ if (
1720
+ val.trim().startsWith("http://") ||
1721
+ val.trim().startsWith("https://")
1722
+ ) {
1723
+ if (!detectPlatform(val.trim())) {
1724
+ return "Platform not supported. Type /platform to view supported platforms.";
1725
+ }
1212
1726
  }
1213
1727
  return undefined;
1214
1728
  },
@@ -1242,13 +1756,57 @@ async function main() {
1242
1756
  `${pc.bold("Photo/Art :")} Pinterest, Pixiv, RedNote (Xiaohongshu)`,
1243
1757
  `${pc.bold("Cloud/Files :")} TeraBox, MediaFire, Sfile, Catbox, Pixeldrain, Krakenfiles, Google Drive`,
1244
1758
  `${pc.bold("Resolvers :")} SafeLinkU, Sub2Unlock, Rekonise, Link Unshortener`,
1759
+ `${pc.bold("Comic/Manga :")} Kiryuu, Komikcast, MangaDex, Komikindo, Komiku, Bacakomik, ManhwaIndo, Asura Scans, MangaBats`,
1760
+ `${pc.bold("Anime :")} Otakudesu, Nimegami, Gogoanime, AnimeTosho`,
1245
1761
  ];
1246
- p.note(platformList.join("\n"), pc.dim("Supported Platforms (27 • Dual-Engine)"));
1762
+ p.note(platformList.join("\n"), pc.dim("Supported Platforms (40 • Dual-Engine)"));
1763
+ break;
1764
+ }
1765
+
1766
+ case "anime": {
1767
+ let query = args.join(" ").trim();
1768
+ if (!query) {
1769
+ const qInput = await p.text({
1770
+ message: "Enter anime title to search:",
1771
+ placeholder: "e.g. majo no tabi tabi",
1772
+ validate: (v) => (!v || !v.trim() ? "Title required." : undefined),
1773
+ });
1774
+ if (p.isCancel(qInput)) break;
1775
+ query = qInput.trim();
1776
+ }
1777
+ await handleSearchAndDownload(query, "anime", {
1778
+ ...values,
1779
+ output: currentOutputDir,
1780
+ });
1781
+ break;
1782
+ }
1783
+
1784
+ case "comic":
1785
+ case "manga": {
1786
+ let query = args.join(" ").trim();
1787
+ if (!query) {
1788
+ const qInput = await p.text({
1789
+ message: "Enter comic/manga title to search:",
1790
+ placeholder: "e.g. solo leveling",
1791
+ validate: (v) => (!v || !v.trim() ? "Title required." : undefined),
1792
+ });
1793
+ if (p.isCancel(qInput)) break;
1794
+ query = qInput.trim();
1795
+ }
1796
+ await handleSearchAndDownload(query, "comic", {
1797
+ ...values,
1798
+ output: currentOutputDir,
1799
+ });
1247
1800
  break;
1248
1801
  }
1249
1802
 
1250
1803
  case "play": {
1251
- const items = getHistory(15);
1804
+ const items = getHistory(25);
1805
+ if (items.length === 0) {
1806
+ p.log.warn("No download history found to play.");
1807
+ break;
1808
+ }
1809
+
1252
1810
  let targetItem = null;
1253
1811
  let targetNum = 1;
1254
1812
 
@@ -1266,13 +1824,6 @@ async function main() {
1266
1824
  } else {
1267
1825
  const customPath = path.resolve(args.join(" "));
1268
1826
  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
1827
  try {
1277
1828
  await openFile(customPath);
1278
1829
  p.log.step(`${pc.bold("Playing:")} ${pc.dim(customPath)}`);
@@ -1281,27 +1832,40 @@ async function main() {
1281
1832
  }
1282
1833
  break;
1283
1834
  }
1835
+ p.log.error(`File does not exist: ${customPath}`);
1836
+ break;
1284
1837
  }
1285
1838
  } 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
- }
1839
+ const selectChoice = await p.select({
1840
+ message: "Select media to play:",
1841
+ options: [
1842
+ ...items.map((it, idx) => {
1843
+ const ext = path
1844
+ .extname(it.path || it.filename || "")
1845
+ .toLowerCase();
1846
+ const typeLabel =
1847
+ ext === ".mp4" || ext === ".mkv" || ext === ".webm"
1848
+ ? "VIDEO"
1849
+ : ext === ".mp3" || ext === ".m4a" || ext === ".wav"
1850
+ ? "AUDIO"
1851
+ : ext === ".pdf"
1852
+ ? "PDF"
1853
+ : ext.slice(1).toUpperCase() || "MEDIA";
1854
+ return {
1855
+ value: idx,
1856
+ label: `[#${idx + 1}] ${it.filename || it.title || "Media"}`,
1857
+ hint: `${it.platform || "media"} • ${typeLabel}`,
1858
+ };
1859
+ }),
1860
+ { value: -1, label: pc.dim("Cancel") },
1861
+ ],
1862
+ });
1301
1863
 
1302
- if (!targetItem) {
1303
- p.log.warn("No downloaded media found in history to play.");
1304
- break;
1864
+ if (p.isCancel(selectChoice) || selectChoice === -1) {
1865
+ break;
1866
+ }
1867
+ targetItem = items[selectChoice];
1868
+ targetNum = selectChoice + 1;
1305
1869
  }
1306
1870
 
1307
1871
  if (!targetItem.path || !fs.existsSync(targetItem.path)) {
@@ -1311,20 +1875,6 @@ async function main() {
1311
1875
  break;
1312
1876
  }
1313
1877
 
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
1878
  try {
1329
1879
  await openFile(targetItem.path);
1330
1880
  p.log.step(
@@ -1339,63 +1889,96 @@ async function main() {
1339
1889
  case "delete":
1340
1890
  case "del":
1341
1891
  case "rm": {
1342
- const items = getHistory(20);
1892
+ const items = getHistory(25);
1343
1893
  if (items.length === 0) {
1344
1894
  p.log.warn("No download history to delete.");
1345
1895
  break;
1346
1896
  }
1347
1897
 
1348
- let targetIndex = -1;
1898
+ let targetIndices = [];
1349
1899
 
1350
1900
  if (args[0]) {
1351
- const numArg = parseInt(args[0], 10);
1352
- if (isNaN(numArg) || numArg < 1 || numArg > items.length) {
1901
+ const rawIndices = args[0]
1902
+ .split(",")
1903
+ .map((s) => parseInt(s.trim(), 10));
1904
+ const validIndices = rawIndices
1905
+ .filter((n) => !isNaN(n) && n >= 1 && n <= items.length)
1906
+ .map((n) => n - 1);
1907
+
1908
+ if (validIndices.length === 0) {
1353
1909
  p.log.warn(
1354
1910
  `Invalid index. Available range: 1 to ${items.length}.`,
1355
1911
  );
1356
1912
  break;
1357
1913
  }
1358
- targetIndex = numArg - 1;
1914
+ targetIndices = validIndices;
1359
1915
  } else {
1360
- const selectChoice = await p.select({
1361
- message: "Select item to delete:",
1916
+ const selectedChoices = await p.multiselect({
1917
+ message:
1918
+ "Select item(s) to delete (Space to toggle, Enter to confirm):",
1362
1919
  options: [
1363
1920
  ...items.map((it, idx) => ({
1364
1921
  value: idx,
1365
1922
  label: `[#${idx + 1}] ${it.filename || it.title || "Media"}`,
1366
1923
  hint: it.platform || "",
1367
1924
  })),
1368
- { value: -1, label: pc.dim("Cancel") },
1369
1925
  ],
1926
+ required: false,
1370
1927
  });
1371
1928
 
1372
- if (p.isCancel(selectChoice) || selectChoice === -1) {
1929
+ if (p.isCancel(selectedChoices) || selectedChoices.length === 0) {
1930
+ p.log.step(pc.dim("Deletion cancelled."));
1373
1931
  break;
1374
1932
  }
1375
- targetIndex = selectChoice;
1933
+ targetIndices = selectedChoices;
1376
1934
  }
1377
1935
 
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,
1936
+ const targetNames = targetIndices
1937
+ .map(
1938
+ (i) => `[#${i + 1}] ${items[i]?.filename || items[i]?.title}`,
1939
+ )
1940
+ .join(", ");
1941
+
1942
+ const deleteMode = await p.select({
1943
+ message:
1944
+ targetIndices.length === 1
1945
+ ? `Delete "${items[targetIndices[0]]?.filename || items[targetIndices[0]]?.title}":`
1946
+ : `Delete ${targetIndices.length} item(s) (${targetNames}):`,
1947
+ options: [
1948
+ {
1949
+ value: "both",
1950
+ label: "Delete from disk & remove from history",
1951
+ hint: "Permanently deletes the physical file",
1952
+ },
1953
+ {
1954
+ value: "history",
1955
+ label: "Remove from history only",
1956
+ hint: "Keeps the file safe on disk",
1957
+ },
1958
+ { value: "cancel", label: pc.dim("Cancel") },
1959
+ ],
1382
1960
  });
1383
1961
 
1384
- if (p.isCancel(confirm) || !confirm) {
1962
+ if (p.isCancel(deleteMode) || deleteMode === "cancel") {
1385
1963
  p.log.step(pc.dim("Deletion cancelled."));
1386
1964
  break;
1387
1965
  }
1388
1966
 
1389
- const res = deleteHistoryItem(targetIndex, true);
1967
+ const deleteFromDisk = deleteMode === "both";
1968
+ const res = deleteHistoryItems(targetIndices, deleteFromDisk);
1390
1969
  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)");
1970
+ const fileNote = deleteFromDisk
1971
+ ? res.filesDeletedCount > 0
1972
+ ? pc.dim(
1973
+ `(${res.filesDeletedCount} file(s) deleted from disk & removed from history)`,
1974
+ )
1975
+ : pc.dim(`(removed from history; file(s) not found on disk)`)
1976
+ : pc.dim(`(removed from history; file(s) preserved on disk)`);
1394
1977
  p.log.step(
1395
- `${pc.bold("✔ Deleted:")} ${pc.white(itemToDelete.filename || itemToDelete.title)} ${fileNote}`,
1978
+ `${pc.bold("✔ Deleted:")} ${pc.white(`${res.count} item(s)`)} ${fileNote}`,
1396
1979
  );
1397
1980
  } else {
1398
- p.log.error(`Failed to delete item: ${res.error}`);
1981
+ p.log.error(`Failed to delete items: ${res.error}`);
1399
1982
  }
1400
1983
  break;
1401
1984
  }
@@ -1623,14 +2206,24 @@ async function main() {
1623
2206
  options: [
1624
2207
  {
1625
2208
  value: "reinstall_mori",
1626
- label: "Reinstall Mori Engine (~80 KB)",
2209
+ label: "Reinstall Latest Mori Engine (~80 KB)",
1627
2210
  hint: moriInst ? "Re-fetch latest bundle" : "Install",
1628
2211
  },
1629
2212
  {
1630
2213
  value: "reinstall_scrapr",
1631
- label: "Reinstall Scrapr Engine (~2.7 MB)",
2214
+ label: "Reinstall Latest Scrapr Engine (~2.7 MB)",
1632
2215
  hint: scraprInst ? "Re-fetch latest bundle" : "Install",
1633
2216
  },
2217
+ {
2218
+ value: "version_mori",
2219
+ label: "Choose / Downgrade Mori Core Version...",
2220
+ hint: "Install specific commit from GitHub",
2221
+ },
2222
+ {
2223
+ value: "version_scrapr",
2224
+ label: "Choose / Downgrade Scrapr Engine Version...",
2225
+ hint: "Install specific release from NPM",
2226
+ },
1634
2227
  ...(moriInst
1635
2228
  ? [
1636
2229
  {
@@ -1673,6 +2266,10 @@ async function main() {
1673
2266
  } catch (err) {
1674
2267
  s.stop(pc.bold(`✕ Failed: ${err.message}`));
1675
2268
  }
2269
+ } else if (mgmtChoice === "version_mori") {
2270
+ await handleRollbackMori();
2271
+ } else if (mgmtChoice === "version_scrapr") {
2272
+ await handleRollbackScrapr();
1676
2273
  } else if (mgmtChoice === "uninstall_mori") {
1677
2274
  uninstallMoriEngine();
1678
2275
  p.log.message(pc.dim("✔ Mori Engine uninstalled."));
@@ -1732,6 +2329,35 @@ async function main() {
1732
2329
  break;
1733
2330
  }
1734
2331
 
2332
+ case "rollback":
2333
+ case "downgrade": {
2334
+ const rbChoice = await p.select({
2335
+ message: "Select engine to rollback / choose version:",
2336
+ options: [
2337
+ {
2338
+ value: "mori",
2339
+ label: "Mori Core Engine",
2340
+ hint: `Current: v${getActiveScraperVersion() || "not installed"}`,
2341
+ },
2342
+ {
2343
+ value: "scrapr",
2344
+ label: "Scrapr Engine",
2345
+ hint: `Current: v${getActiveScraprVersion() || "not installed"}`,
2346
+ },
2347
+ { value: "cancel", label: pc.dim("Cancel") },
2348
+ ],
2349
+ });
2350
+
2351
+ if (p.isCancel(rbChoice) || rbChoice === "cancel") break;
2352
+
2353
+ if (rbChoice === "mori") {
2354
+ await handleRollbackMori();
2355
+ } else if (rbChoice === "scrapr") {
2356
+ await handleRollbackScrapr();
2357
+ }
2358
+ break;
2359
+ }
2360
+
1735
2361
  case "clip":
1736
2362
  case "paste": {
1737
2363
  const s = p.spinner();
@@ -1806,13 +2432,14 @@ async function main() {
1806
2432
  break;
1807
2433
  }
1808
2434
 
1809
- const items = getHistory(15);
2435
+ const items = getHistory(25);
1810
2436
  if (items.length === 0) {
1811
2437
  p.log.message(pc.dim("No download history yet."));
1812
2438
  break;
1813
2439
  }
1814
2440
 
1815
- // Check if user specified an iteration number, e.g. /history 1
2441
+ let selectedIndex = -1;
2442
+
1816
2443
  const numArg = parseInt(args[0], 10);
1817
2444
  if (!isNaN(numArg)) {
1818
2445
  if (numArg < 1 || numArg > items.length) {
@@ -1821,40 +2448,56 @@ async function main() {
1821
2448
  );
1822
2449
  break;
1823
2450
  }
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
- );
2451
+ selectedIndex = numArg - 1;
2452
+ } else {
2453
+ const choice = await p.select({
2454
+ message: "Download History (Select to re-download):",
2455
+ options: [
2456
+ ...items.map((it, idx) => ({
2457
+ value: idx,
2458
+ label: `[#${idx + 1}] ${it.filename || it.title || "Media"}`,
2459
+ hint: `${it.platform?.toUpperCase() || ""}${it.timestamp ? ` • ${formatRelativeTime(it.timestamp)}` : ""}`,
2460
+ })),
2461
+ { value: "clear", label: pc.red("🗑 Clear all history") },
2462
+ { value: "cancel", label: pc.dim("Cancel") },
2463
+ ],
2464
+ });
2465
+
2466
+ if (p.isCancel(choice) || choice === "cancel") {
1829
2467
  break;
1830
2468
  }
1831
- p.log.message(
1832
- `${pc.bold("● Re-downloading from history:")} ${pc.inverse(` ${selected.platform?.toUpperCase()} `)} ${pc.dim(selected.url)}`,
2469
+
2470
+ if (choice === "clear") {
2471
+ const confirmClear = await p.confirm({
2472
+ message:
2473
+ "Are you sure you want to clear all download history?",
2474
+ initialValue: false,
2475
+ });
2476
+ if (confirmClear && !p.isCancel(confirmClear)) {
2477
+ clearHistory();
2478
+ p.log.message(pc.dim("Download history cleared."));
2479
+ }
2480
+ break;
2481
+ }
2482
+
2483
+ selectedIndex = choice;
2484
+ }
2485
+
2486
+ const selected = items[selectedIndex];
2487
+ if (!selected.url) {
2488
+ p.log.warn(
2489
+ `Item #${selectedIndex + 1} has no recorded source URL (downloaded prior to URL tracking).`,
1833
2490
  );
1834
- lastUrl = selected.url;
1835
- await handleScrapeAndDownload(selected.url, {
1836
- ...values,
1837
- output: currentOutputDir,
1838
- });
1839
2491
  break;
1840
2492
  }
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
- ),
2493
+ p.log.message(
2494
+ `${pc.bold("● Re-downloading from history:")} ${pc.inverse(` ${selected.platform?.toUpperCase()} `)} ${pc.dim(selected.url)}`,
1857
2495
  );
2496
+ lastUrl = selected.url;
2497
+ await handleScrapeAndDownload(selected.url, {
2498
+ ...values,
2499
+ output: currentOutputDir,
2500
+ });
1858
2501
  break;
1859
2502
  }
1860
2503
 
@@ -2077,24 +2720,27 @@ async function main() {
2077
2720
  case "help":
2078
2721
  case "?": {
2079
2722
  const cmds = [
2723
+ `${pc.bold("/anime [query]")} Search and download anime episodes`,
2724
+ `${pc.bold("/comic [query]")} Search and download comic chapters (supports PDF)`,
2080
2725
  `${pc.bold("/clip")} Download link currently in clipboard`,
2081
2726
  `${pc.bold("/audio [url]")} Download audio stream only (MP3/M4A)`,
2082
2727
  `${pc.bold("/pdf [url]")} Download photo album compiled directly into 1 PDF`,
2083
- `${pc.bold("/play [num]")} Play downloaded media in default system player`,
2728
+ `${pc.bold("/play [num]")} Interactive media player picker (or /play <num>)`,
2084
2729
  `${pc.bold("/ping [host]")} Check user network latency (default: 1.1.1.1)`,
2085
2730
  `${pc.bold("/info [url]")} Inspect media details without downloading`,
2086
2731
  `${pc.bold("/retry")} Re-download the last link processed`,
2087
2732
  `${pc.bold("/batch")} Bulk download multiple links at once`,
2088
- `${pc.bold("/platform")} List all 27 supported media platforms`,
2733
+ `${pc.bold("/platform")} List all 40 supported media platforms`,
2089
2734
  `${pc.bold("/dir")} View or set download directory (persistent)`,
2090
2735
  `${pc.bold("/open")} Open download folder in file manager`,
2091
2736
  `${pc.bold("/engine")} Set default extraction engine (auto/mori/scrapr)`,
2092
2737
  `${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`,
2738
+ `${pc.bold("/history")} Interactive download history & redownload picker`,
2739
+ `${pc.bold("/delete")} Interactive bulk delete from disk & history (Space)`,
2095
2740
  `${pc.bold("/stats")} View total downloads & storage statistics`,
2096
2741
  `${pc.bold("/config")} Show active Mori configuration`,
2097
2742
  `${pc.bold("/update")} Check and apply remote OTA scraper patches`,
2743
+ `${pc.bold("/rollback")} Rollback or install specific engine versions`,
2098
2744
  `${pc.bold("/reset")} Factory reset Mori config, cache, & history`,
2099
2745
  `${pc.bold("/clear")} Clear screen and reprint header`,
2100
2746
  `${pc.bold("/exit, /q")} Exit Mori CLI`,
@@ -2122,10 +2768,17 @@ async function main() {
2122
2768
  }
2123
2769
 
2124
2770
  lastUrl = rawInput;
2125
- await handleScrapeAndDownload(rawInput, {
2126
- ...values,
2127
- output: currentOutputDir,
2128
- });
2771
+ if (!rawInput.startsWith("http://") && !rawInput.startsWith("https://")) {
2772
+ await handleSearchAndDownload(rawInput, null, {
2773
+ ...values,
2774
+ output: currentOutputDir,
2775
+ });
2776
+ } else {
2777
+ await handleScrapeAndDownload(rawInput, {
2778
+ ...values,
2779
+ output: currentOutputDir,
2780
+ });
2781
+ }
2129
2782
 
2130
2783
  const next = await p.confirm({
2131
2784
  message: "Continue?",