@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/CHANGELOG.md CHANGED
@@ -5,6 +5,31 @@ All notable changes to the Mori CLI (`@coflyn/mori`) will be documented in this
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.0] - 2026-10-25
9
+
10
+ ### Added
11
+ - **Interactive Anime & Comic Discovery**:
12
+ - Type titles directly (e.g. `solo leveling`, `frieren`) into the CLI prompt to trigger search across Anime and Comic providers.
13
+ - **Anime Providers**: Otakudesu (Sub Indo) and Gogoanime (Sub Eng) with episode selectors and multi-server stream extraction.
14
+ - **Comic Providers**: Komikindo (Indonesian), Komiku (Indonesian), and Asura Scans (English / Manhwa) with chapter navigation.
15
+ - **Manga Chapter PDF Compilation**:
16
+ - Download comic chapters as individual page images or automatically compile them into a single clean PDF document.
17
+ - **Web Player & HLS Stream Support**:
18
+ - Prioritizes embed web player links for seamless browser playback without Cloudflare WAF blocks.
19
+ - Direct master HLS m3u8 streams labeled with media player headers (`Referer`) for VLC, mpv, and ffmpeg.
20
+ - **Interactive Media Player & History Pickers**:
21
+ - Replaced manual numeric input in `/play` and `/history` with interactive select menus displaying media badges (Video, Audio, PDF) and relative download timestamps.
22
+ - **Bulk Multiselect Deletion (`/delete`)**:
23
+ - Upgraded `/delete` to an interactive multiselect list allowing users to toggle multiple items with `Space` and confirm with `Enter`, with dual deletion modes: delete from disk & history or remove from history only.
24
+ - **Engine Rollback & Version Selector (`/rollback`)**:
25
+ - Rollback or install specific versions of scraper engines if an update introduces upstream breaking changes.
26
+ - **Mori Core Engine**: Browse and install previous bundles directly via GitHub commit history.
27
+ - **Scrapr Engine**: Browse and install previous releases directly from the NPM registry.
28
+ - Accessible via `/rollback` or `/engine` management menu.
29
+
30
+ ### Fixed
31
+ - **Facebook SnapSave Extraction**: Fixed `(0, j.decodeSnapSave) is not a function` error when extracting Facebook media by defining `decodeSnapSave` and `extractFinalUrl` in engine runtime dependencies ([#18](https://github.com/coflyn/Mori/issues/18)).
32
+
8
33
  ## [1.1.0] - 2026-10-21
9
34
 
10
35
  ### Added
package/README.md CHANGED
@@ -46,7 +46,7 @@ mori
46
46
 
47
47
  ---
48
48
 
49
- ## 🌐 Supported Platforms (16)
49
+ ## 🌐 Supported Platforms & Media
50
50
 
51
51
  | Platform | Capabilities |
52
52
  | :------------------------ | :---------------------------------------------------------- |
@@ -66,6 +66,8 @@ mori
66
66
  | **Pixiv** | Artwork galleries and animated Ugoira |
67
67
  | **Bandcamp** | Individual songs and full discographies |
68
68
  | **TeraBox** | Direct stream extraction |
69
+ | **Anime** | Interactive search & episode stream resolution (Otakudesu Sub Indo, Gogoanime Sub Eng) |
70
+ | **Comic / Manga** | Interactive chapter search, image extraction, and PDF compilation (Komikindo, Komiku, Asura Scans) |
69
71
 
70
72
  ---
71
73
 
package/engine.js CHANGED
@@ -61,15 +61,81 @@ function cleanUrl(u) {
61
61
  return u ? u.split("?")[0] : "";
62
62
  }
63
63
 
64
+ const SAFARI_MOBILE_UA = CHROME_MOBILE_UA;
65
+
66
+ function decodeSnapSave(data) {
67
+ try {
68
+ const regex =
69
+ /eval\(function\(h,u,n,t,e,r\)\{.*?\}\("(.*?)",(\d+),"(.*?)",(\d+),(\d+),(\d+)\)\)/;
70
+ const match = data.match(regex);
71
+ if (match) {
72
+ const h = match[1],
73
+ u = parseInt(match[2]),
74
+ n = match[3],
75
+ t = parseInt(match[4]),
76
+ e = parseInt(match[5]);
77
+ const delimiter = n[e],
78
+ parts = h.split(delimiter);
79
+ let decoded = "";
80
+ for (let s of parts) {
81
+ if (s === "") continue;
82
+ let val = 0;
83
+ for (let j = 0; j < s.length; j++)
84
+ val += n.indexOf(s[j]) * Math.pow(e, s.length - 1 - j);
85
+ decoded += String.fromCharCode(val - t);
86
+ }
87
+ try {
88
+ return decodeURIComponent(escape(decoded));
89
+ } catch {
90
+ return Buffer.from(decoded, "binary").toString("utf-8");
91
+ }
92
+ }
93
+ return data;
94
+ } catch (err) {
95
+ return data;
96
+ }
97
+ }
98
+
99
+ function extractFinalUrl(input) {
100
+ if (!input) return null;
101
+ let raw = input.trim().replace(/^["'\\]+|["'\\]+$/g, ""),
102
+ isRender = false;
103
+ if (raw.includes("get_progressApi") || raw.includes("get_progress")) {
104
+ isRender = true;
105
+ const tokenMatch = raw.match(/token=([^&'"]+)/);
106
+ if (tokenMatch) raw = tokenMatch[1];
107
+ }
108
+ if (raw.includes(".") && !raw.startsWith("http")) {
109
+ try {
110
+ const payloadPart = raw.split(".")[1];
111
+ if (payloadPart) {
112
+ const payload = JSON.parse(
113
+ Buffer.from(payloadPart, "base64").toString("utf-8")
114
+ );
115
+ if (payload.video_url)
116
+ return { url: payload.video_url, isRender: true };
117
+ if (payload.url) return { url: payload.url, isRender: false };
118
+ }
119
+ } catch (e) {}
120
+ }
121
+ if (raw.startsWith("//")) return { url: "https:" + raw, isRender };
122
+ if (raw.startsWith("/"))
123
+ return { url: "https://snapsave.app" + raw, isRender };
124
+ return { url: raw, isRender };
125
+ }
126
+
64
127
  globalThis.window.__moriDeps = {
65
128
  utils: {
66
129
  CHROME_UA,
67
130
  CHROME_DESKTOP_UA,
68
131
  CHROME_MOBILE_UA,
132
+ SAFARI_MOBILE_UA,
69
133
  getUserAgent,
70
134
  cleanUrl,
71
135
  getCookiesFromHeaders,
72
136
  serializeData,
137
+ decodeSnapSave,
138
+ extractFinalUrl,
73
139
  },
74
140
  urlUtils: {
75
141
  getCleanUrl: (u) => (u ? u.trim() : ""),
@@ -250,34 +316,51 @@ export function clearHistory() {
250
316
  }
251
317
  }
252
318
 
253
- export function deleteHistoryItem(index, deleteFile = true) {
319
+ export function deleteHistoryItems(indices, deleteFile = true) {
254
320
  try {
255
321
  const list = getHistory(200);
256
- if (index < 0 || index >= list.length) {
257
- return { success: false, error: "Index out of range" };
258
- }
259
- const [removed] = list.splice(index, 1);
260
- let fileDeleted = false;
261
-
262
- if (deleteFile && removed.path && fs.existsSync(removed.path)) {
263
- try {
264
- fs.unlinkSync(removed.path);
265
- fileDeleted = true;
266
- } catch (_) {}
322
+ const sortedIndices = [...new Set(indices)].sort((a, b) => b - a);
323
+ const deletedItems = [];
324
+ let filesDeletedCount = 0;
325
+
326
+ for (const idx of sortedIndices) {
327
+ if (idx >= 0 && idx < list.length) {
328
+ const [removed] = list.splice(idx, 1);
329
+ let fileDeleted = false;
330
+ if (deleteFile && removed.path && fs.existsSync(removed.path)) {
331
+ try {
332
+ fs.unlinkSync(removed.path);
333
+ fileDeleted = true;
334
+ filesDeletedCount++;
335
+ } catch (_) {}
336
+ }
337
+ deletedItems.push({ item: removed, fileDeleted });
338
+ }
267
339
  }
268
340
 
269
341
  fs.writeFileSync(HISTORY_PATH, JSON.stringify(list, null, 2), "utf8");
270
342
 
271
343
  return {
272
344
  success: true,
273
- item: removed,
274
- fileDeleted,
345
+ count: deletedItems.length,
346
+ filesDeletedCount,
347
+ deletedItems,
275
348
  };
276
349
  } catch (err) {
277
350
  return { success: false, error: err.message };
278
351
  }
279
352
  }
280
353
 
354
+ export function deleteHistoryItem(index, deleteFile = true) {
355
+ const res = deleteHistoryItems([index], deleteFile);
356
+ if (!res.success) return res;
357
+ return {
358
+ success: true,
359
+ item: res.deletedItems[0]?.item,
360
+ fileDeleted: res.deletedItems[0]?.fileDeleted || false,
361
+ };
362
+ }
363
+
281
364
  export function getStats() {
282
365
  const items = getHistory(200);
283
366
  const totalDownloads = items.length;
@@ -526,6 +609,160 @@ export function uninstallScraprEngine() {
526
609
  return true;
527
610
  }
528
611
 
612
+ export async function fetchMoriEngineHistory() {
613
+ try {
614
+ const res = await fetch(
615
+ `https://api.github.com/repos/${GITHUB_REPO}/commits?path=public/js/scrapers/bundle.js&per_page=15`,
616
+ {
617
+ signal: AbortSignal.timeout(10000),
618
+ headers: { "User-Agent": "Mori-CLI" },
619
+ },
620
+ );
621
+ if (!res.ok) return [];
622
+ const commits = await res.json();
623
+ if (!Array.isArray(commits)) return [];
624
+ return commits.map((c) => ({
625
+ sha: c.sha.slice(0, 7),
626
+ fullSha: c.sha,
627
+ message: (c.commit?.message || "").split("\n")[0].trim(),
628
+ date: c.commit?.author?.date || "",
629
+ }));
630
+ } catch (_) {
631
+ return [];
632
+ }
633
+ }
634
+
635
+ export async function downloadMoriEngineByCommit(commitSha, onProgress) {
636
+ const shortSha = commitSha.slice(0, 7);
637
+ if (onProgress) onProgress(`Fetching Mori Core bundle at commit ${shortSha}...`);
638
+
639
+ const bundleUrl = `https://raw.githubusercontent.com/${GITHUB_REPO}/${commitSha}/public/js/scrapers/bundle.js`;
640
+ const metaUrl = `https://raw.githubusercontent.com/${GITHUB_REPO}/${commitSha}/public/scrapers-version.json`;
641
+
642
+ const [bundleRes, metaRes] = await Promise.all([
643
+ fetch(bundleUrl, {
644
+ signal: AbortSignal.timeout(30000),
645
+ headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
646
+ }),
647
+ fetch(metaUrl, {
648
+ signal: AbortSignal.timeout(15000),
649
+ headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
650
+ }).catch(() => null),
651
+ ]);
652
+
653
+ if (!bundleRes.ok) {
654
+ throw new Error(`Failed to fetch bundle at commit ${shortSha}: HTTP ${bundleRes.status}`);
655
+ }
656
+
657
+ const bundleText = await bundleRes.text();
658
+ if (!bundleText || bundleText.length < 5000) {
659
+ throw new Error("Downloaded bundle is empty or invalid.");
660
+ }
661
+
662
+ let meta = { scraperVersion: shortSha };
663
+ if (metaRes && metaRes.ok) {
664
+ try {
665
+ meta = await metaRes.json();
666
+ } catch (_) {}
667
+ }
668
+
669
+ if (!fs.existsSync(OTA_DIR)) {
670
+ fs.mkdirSync(OTA_DIR, { recursive: true });
671
+ }
672
+
673
+ fs.writeFileSync(OTA_BUNDLE_PATH, bundleText, "utf8");
674
+ fs.writeFileSync(
675
+ OTA_META_PATH,
676
+ JSON.stringify(
677
+ {
678
+ scraperVersion: meta.scraperVersion || shortSha,
679
+ updatedAt: Date.now(),
680
+ sourceHash: meta.sourceHash || "",
681
+ changelog: meta.changelog || "",
682
+ commitSha: shortSha,
683
+ },
684
+ null,
685
+ 2,
686
+ ),
687
+ "utf8",
688
+ );
689
+
690
+ cachedMoriScrapers = null;
691
+ return { success: true, version: meta.scraperVersion || shortSha };
692
+ }
693
+
694
+ export async function fetchScraprEngineVersions() {
695
+ try {
696
+ const res = await fetch("https://registry.npmjs.org/@coflyn/scrapr", {
697
+ signal: AbortSignal.timeout(10000),
698
+ headers: { "User-Agent": "Mori-CLI" },
699
+ });
700
+ if (!res.ok) return [];
701
+ const data = await res.json();
702
+ const versions = Object.keys(data.versions || {});
703
+ return versions.reverse();
704
+ } catch (_) {
705
+ return [];
706
+ }
707
+ }
708
+
709
+ export async function downloadScraprEngineVersion(targetVersion, onProgress) {
710
+ if (onProgress) onProgress(`Downloading Scrapr Engine v${targetVersion}...`);
711
+ let bundleText = "";
712
+
713
+ const urls = [
714
+ `https://unpkg.com/@coflyn/scrapr@${targetVersion}/bundle.cjs`,
715
+ `https://cdn.jsdelivr.net/npm/@coflyn/scrapr@${targetVersion}/bundle.cjs`,
716
+ `https://raw.githubusercontent.com/coflyn/scrapr/v${targetVersion}/bundle.cjs`,
717
+ `https://raw.githubusercontent.com/coflyn/scrapr/main/bundle.cjs`,
718
+ ];
719
+
720
+ for (const u of urls) {
721
+ try {
722
+ const res = await fetch(u, {
723
+ signal: AbortSignal.timeout(30000),
724
+ headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
725
+ });
726
+ if (res.ok) {
727
+ bundleText = await res.text();
728
+ if (bundleText && bundleText.length > 50000) break;
729
+ }
730
+ } catch (_) {}
731
+ }
732
+
733
+ if (!bundleText || bundleText.length < 50000) {
734
+ const localDevScrapr = path.resolve(__dirname, "../../../scrapr/bundle.cjs");
735
+ if (fs.existsSync(localDevScrapr)) {
736
+ bundleText = fs.readFileSync(localDevScrapr, "utf8");
737
+ }
738
+ }
739
+
740
+ if (!bundleText || bundleText.length < 50000) {
741
+ throw new Error(`Failed to download Scrapr v${targetVersion} bundle.`);
742
+ }
743
+
744
+ if (!fs.existsSync(SCRAPR_DIR)) {
745
+ fs.mkdirSync(SCRAPR_DIR, { recursive: true });
746
+ }
747
+
748
+ fs.writeFileSync(SCRAPR_BUNDLE_PATH, bundleText, "utf8");
749
+ fs.writeFileSync(
750
+ SCRAPR_META_PATH,
751
+ JSON.stringify(
752
+ {
753
+ version: targetVersion,
754
+ updatedAt: Date.now(),
755
+ },
756
+ null,
757
+ 2,
758
+ ),
759
+ "utf8",
760
+ );
761
+
762
+ cachedScrapr = null;
763
+ return { success: true, version: targetVersion };
764
+ }
765
+
529
766
  /**
530
767
  * Checks for Mori Core OTA updates from GitHub raw.
531
768
  */
@@ -784,6 +1021,21 @@ export const SCRAPR_ONLY_PLATFORMS = new Set([
784
1021
  "sub2unlock",
785
1022
  "rekonise",
786
1023
  "unshorten",
1024
+ // Comic & Manga (Engine 2)
1025
+ "kiryuu",
1026
+ "komikcast",
1027
+ "mangadex",
1028
+ "komikindo",
1029
+ "komiku",
1030
+ "bacakomik",
1031
+ "manhwaindo",
1032
+ "asurascans",
1033
+ "mangabats",
1034
+ // Anime (Engine 2)
1035
+ "otakudesu",
1036
+ "nimegami",
1037
+ "gogoanime",
1038
+ "animetosho",
787
1039
  ]);
788
1040
 
789
1041
  export const RESOLVER_LINK_PLATFORMS = new Set([
@@ -903,9 +1155,64 @@ export function detectPlatform(rawUrl) {
903
1155
  url.includes("dub.sh") ||
904
1156
  url.includes("cutt.ly") ||
905
1157
  url.includes("t.co/") ||
906
- url.includes("shorturl.at")
1158
+ url.includes("shorturl.at") ||
1159
+ url.includes("aka.ms")
907
1160
  )
908
1161
  return "unshorten";
1162
+ // Comic & Manga (Engine 2: Scrapr)
1163
+ if (url.includes("kiryuu.to") || url.includes("kiryuu.id")) return "kiryuu";
1164
+ if (
1165
+ url.includes("komikcast.info") ||
1166
+ url.includes("komikcast.ch") ||
1167
+ url.includes("komikcast.me") ||
1168
+ url.includes("komikcast.cz")
1169
+ )
1170
+ return "komikcast";
1171
+ if (url.includes("mangadex.org")) return "mangadex";
1172
+ if (
1173
+ url.includes("komikindo.ch") ||
1174
+ url.includes("komikindo.org") ||
1175
+ url.includes("komikindo.tv")
1176
+ )
1177
+ return "komikindo";
1178
+ if (url.includes("komiku.org") || url.includes("komiku.id")) return "komiku";
1179
+ if (
1180
+ url.includes("bacakomik.my") ||
1181
+ url.includes("bacakomik.co") ||
1182
+ url.includes("bacakomik.one")
1183
+ )
1184
+ return "bacakomik";
1185
+ if (
1186
+ url.includes("manhwaindo.my") ||
1187
+ url.includes("manhwaindo.id") ||
1188
+ url.includes("manhwaindo.org")
1189
+ )
1190
+ return "manhwaindo";
1191
+ if (
1192
+ url.includes("asurascans.com") ||
1193
+ url.includes("asuracomic.net") ||
1194
+ url.includes("asura.gg")
1195
+ )
1196
+ return "asurascans";
1197
+ if (url.includes("mangabats.com") || url.includes("mangabat.com"))
1198
+ return "mangabats";
1199
+
1200
+ // Anime (Engine 2: Scrapr)
1201
+ if (
1202
+ url.includes("otakudesu.blog") ||
1203
+ url.includes("otakudesu.cloud") ||
1204
+ url.includes("otakudesu.tube") ||
1205
+ url.includes("otakudesu.info")
1206
+ )
1207
+ return "otakudesu";
1208
+ if (url.includes("nimegami.id")) return "nimegami";
1209
+ if (
1210
+ url.includes("gogoanime") ||
1211
+ url.includes("gogoanimes") ||
1212
+ url.includes("anitaku")
1213
+ )
1214
+ return "gogoanime";
1215
+ if (url.includes("animetosho.org")) return "animetosho";
909
1216
  return null;
910
1217
  }
911
1218
 
@@ -1456,6 +1763,60 @@ export async function scrapeWithScrapr(
1456
1763
  case "unshorten":
1457
1764
  res = await scrapr.resolver.unshorten(url);
1458
1765
  break;
1766
+ // Comic & Manga
1767
+ case "kiryuu":
1768
+ res = await scrapr.comic.kiryuu(url);
1769
+ usedServer = "Kiryuu";
1770
+ break;
1771
+ case "komikcast":
1772
+ res = await scrapr.comic.komikcast(url);
1773
+ usedServer = "Komikcast";
1774
+ break;
1775
+ case "mangadex":
1776
+ res = await scrapr.comic.mangadex(url);
1777
+ usedServer = "MangaDex";
1778
+ break;
1779
+ case "komikindo":
1780
+ res = await scrapr.comic.komikindo(url);
1781
+ usedServer = "Komikindo";
1782
+ break;
1783
+ case "komiku":
1784
+ res = await scrapr.comic.komiku(url);
1785
+ usedServer = "Komiku";
1786
+ break;
1787
+ case "bacakomik":
1788
+ res = await scrapr.comic.bacakomik(url);
1789
+ usedServer = "Bacakomik";
1790
+ break;
1791
+ case "manhwaindo":
1792
+ res = await scrapr.comic.manhwaindo(url);
1793
+ usedServer = "ManhwaIndo";
1794
+ break;
1795
+ case "asurascans":
1796
+ res = await scrapr.comic.asurascans(url);
1797
+ usedServer = "AsuraScans";
1798
+ break;
1799
+ case "mangabats":
1800
+ res = await scrapr.comic.mangabats(url);
1801
+ usedServer = "MangaBats";
1802
+ break;
1803
+ // Anime
1804
+ case "otakudesu":
1805
+ res = await scrapr.anime.otakudesu(url);
1806
+ usedServer = "Otakudesu";
1807
+ break;
1808
+ case "nimegami":
1809
+ res = await scrapr.anime.nimegami(url);
1810
+ usedServer = "Nimegami";
1811
+ break;
1812
+ case "gogoanime":
1813
+ res = await scrapr.anime.gogoanime(url);
1814
+ usedServer = "Gogoanime";
1815
+ break;
1816
+ case "animetosho":
1817
+ res = await scrapr.anime.animetosho(url);
1818
+ usedServer = "AnimeTosho";
1819
+ break;
1459
1820
  default:
1460
1821
  throw new Error(`Scrapr does not support platform: ${platform}`);
1461
1822
  }
@@ -1749,11 +2110,17 @@ export function sanitizeFilename(title, ext = "mp4") {
1749
2110
  }
1750
2111
 
1751
2112
  // 8. Stream Downloader with Progress Reporting
1752
- export async function downloadMediaFile(downloadUrl, outputPath, onProgress) {
2113
+ export async function downloadMediaFile(
2114
+ downloadUrl,
2115
+ outputPath,
2116
+ onProgress,
2117
+ extraHeaders = {},
2118
+ ) {
1753
2119
  const res = await fetch(downloadUrl, {
1754
2120
  headers: {
1755
2121
  "User-Agent": CHROME_UA,
1756
2122
  Accept: "*/*",
2123
+ ...extraHeaders,
1757
2124
  },
1758
2125
  });
1759
2126
 
@@ -1761,6 +2128,17 @@ export async function downloadMediaFile(downloadUrl, outputPath, onProgress) {
1761
2128
  throw new Error(`Download HTTP error: ${res.status} ${res.statusText}`);
1762
2129
  }
1763
2130
 
2131
+ const contentType = (res.headers.get("content-type") || "").toLowerCase();
2132
+ if (
2133
+ contentType.includes("text/html") &&
2134
+ !outputPath.endsWith(".html") &&
2135
+ !outputPath.endsWith(".txt")
2136
+ ) {
2137
+ throw new Error(
2138
+ "Received HTML webpage instead of a direct media stream. Please select a Direct MP4 stream.",
2139
+ );
2140
+ }
2141
+
1764
2142
  const totalBytes = parseInt(res.headers.get("content-length") || "0", 10);
1765
2143
  const fileStream = fs.createWriteStream(outputPath);
1766
2144