react-native-consumet 2.0.0 → 3.0.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.
Files changed (211) hide show
  1. package/android/src/main/java/com/consumet/HttpRequestModule.kt +88 -33
  2. package/android/src/main/java/com/consumet/WebViewTask.kt +18 -3
  3. package/ios/Consumet.mm +172 -72
  4. package/lib/commonjs/NativeConsumet.ts +11 -5
  5. package/lib/commonjs/extension-registry.json +6 -6
  6. package/lib/commonjs/extension-registry.json.sig +1 -1
  7. package/lib/commonjs/extractors/kwik.js +28 -29
  8. package/lib/commonjs/extractors/kwik.js.map +1 -1
  9. package/lib/commonjs/index.js +18 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/models/types.js +6 -0
  12. package/lib/commonjs/models/types.js.map +1 -1
  13. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js +12 -13
  14. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js.map +1 -1
  15. package/lib/commonjs/providers/manga/asurascans.js +160 -96
  16. package/lib/commonjs/providers/manga/asurascans.js.map +1 -1
  17. package/lib/commonjs/providers/manga/flamescans.js +173 -91
  18. package/lib/commonjs/providers/manga/flamescans.js.map +1 -1
  19. package/lib/commonjs/providers/manga/index.js +1 -15
  20. package/lib/commonjs/providers/manga/index.js.map +1 -1
  21. package/lib/commonjs/providers/manga/mangadex.js +234 -227
  22. package/lib/commonjs/providers/manga/mangadex.js.map +1 -1
  23. package/lib/commonjs/providers/manga/mangahere.js +279 -135
  24. package/lib/commonjs/providers/manga/mangahere.js.map +1 -1
  25. package/lib/commonjs/providers/manga/mangakakalot.js +206 -107
  26. package/lib/commonjs/providers/manga/mangakakalot.js.map +1 -1
  27. package/lib/commonjs/providers/manga/mangapill.js +126 -38
  28. package/lib/commonjs/providers/manga/mangapill.js.map +1 -1
  29. package/lib/commonjs/providers/meta/anilist.js +41 -12
  30. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  31. package/lib/commonjs/utils/index.js +19 -0
  32. package/lib/commonjs/utils/index.js.map +1 -1
  33. package/lib/commonjs/utils/manga.js +60 -0
  34. package/lib/commonjs/utils/manga.js.map +1 -0
  35. package/lib/module/NativeConsumet.ts +11 -5
  36. package/lib/module/extension-registry.json +6 -6
  37. package/lib/module/extension-registry.json.sig +1 -1
  38. package/lib/module/extractors/kwik.js +28 -29
  39. package/lib/module/extractors/kwik.js.map +1 -1
  40. package/lib/module/index.js +2 -2
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/models/types.js +9 -0
  43. package/lib/module/models/types.js.map +1 -1
  44. package/lib/module/providers/anime/animepahe/create-animepahe.js +12 -13
  45. package/lib/module/providers/anime/animepahe/create-animepahe.js.map +1 -1
  46. package/lib/module/providers/manga/asurascans.js +161 -96
  47. package/lib/module/providers/manga/asurascans.js.map +1 -1
  48. package/lib/module/providers/manga/flamescans.js +174 -91
  49. package/lib/module/providers/manga/flamescans.js.map +1 -1
  50. package/lib/module/providers/manga/index.js +1 -15
  51. package/lib/module/providers/manga/index.js.map +1 -1
  52. package/lib/module/providers/manga/mangadex.js +236 -228
  53. package/lib/module/providers/manga/mangadex.js.map +1 -1
  54. package/lib/module/providers/manga/mangahere.js +276 -132
  55. package/lib/module/providers/manga/mangahere.js.map +1 -1
  56. package/lib/module/providers/manga/mangakakalot.js +207 -107
  57. package/lib/module/providers/manga/mangakakalot.js.map +1 -1
  58. package/lib/module/providers/manga/mangapill.js +128 -39
  59. package/lib/module/providers/manga/mangapill.js.map +1 -1
  60. package/lib/module/providers/meta/anilist.js +41 -12
  61. package/lib/module/providers/meta/anilist.js.map +1 -1
  62. package/lib/module/utils/index.js +1 -0
  63. package/lib/module/utils/index.js.map +1 -1
  64. package/lib/module/utils/manga.js +54 -0
  65. package/lib/module/utils/manga.js.map +1 -0
  66. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +11 -5
  67. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/src/extractors/kwik.d.ts +1 -1
  69. package/lib/typescript/commonjs/src/extractors/kwik.d.ts.map +1 -1
  70. package/lib/typescript/commonjs/src/index.d.ts +2 -2
  71. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  72. package/lib/typescript/commonjs/src/models/types.d.ts +38 -5
  73. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts +14 -4
  76. package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts +18 -3
  78. package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/providers/manga/index.d.ts +0 -14
  80. package/lib/typescript/commonjs/src/providers/manga/index.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts +22 -5
  82. package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts +15 -3
  84. package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts.map +1 -1
  85. package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts +26 -4
  86. package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts +16 -2
  88. package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts.map +1 -1
  89. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/src/utils/index.d.ts +1 -0
  91. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/utils/manga.d.ts +19 -0
  93. package/lib/typescript/commonjs/src/utils/manga.d.ts.map +1 -0
  94. package/lib/typescript/module/src/NativeConsumet.d.ts +11 -5
  95. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  96. package/lib/typescript/module/src/extractors/kwik.d.ts +1 -1
  97. package/lib/typescript/module/src/extractors/kwik.d.ts.map +1 -1
  98. package/lib/typescript/module/src/index.d.ts +2 -2
  99. package/lib/typescript/module/src/index.d.ts.map +1 -1
  100. package/lib/typescript/module/src/models/types.d.ts +38 -5
  101. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  102. package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  103. package/lib/typescript/module/src/providers/manga/asurascans.d.ts +14 -4
  104. package/lib/typescript/module/src/providers/manga/asurascans.d.ts.map +1 -1
  105. package/lib/typescript/module/src/providers/manga/flamescans.d.ts +18 -3
  106. package/lib/typescript/module/src/providers/manga/flamescans.d.ts.map +1 -1
  107. package/lib/typescript/module/src/providers/manga/index.d.ts +0 -14
  108. package/lib/typescript/module/src/providers/manga/index.d.ts.map +1 -1
  109. package/lib/typescript/module/src/providers/manga/mangadex.d.ts +22 -5
  110. package/lib/typescript/module/src/providers/manga/mangadex.d.ts.map +1 -1
  111. package/lib/typescript/module/src/providers/manga/mangahere.d.ts +15 -3
  112. package/lib/typescript/module/src/providers/manga/mangahere.d.ts.map +1 -1
  113. package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts +26 -4
  114. package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts.map +1 -1
  115. package/lib/typescript/module/src/providers/manga/mangapill.d.ts +16 -2
  116. package/lib/typescript/module/src/providers/manga/mangapill.d.ts.map +1 -1
  117. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  118. package/lib/typescript/module/src/utils/index.d.ts +1 -0
  119. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  120. package/lib/typescript/module/src/utils/manga.d.ts +19 -0
  121. package/lib/typescript/module/src/utils/manga.d.ts.map +1 -0
  122. package/package.json +1 -1
  123. package/src/NativeConsumet.ts +11 -5
  124. package/src/extension-registry.json +6 -6
  125. package/src/extension-registry.json.sig +1 -1
  126. package/src/extractors/kwik.ts +30 -43
  127. package/src/index.tsx +6 -0
  128. package/src/models/types.ts +38 -3
  129. package/src/providers/anime/animepahe/create-animepahe.ts +15 -14
  130. package/src/providers/manga/asurascans.ts +200 -135
  131. package/src/providers/manga/flamescans.ts +221 -118
  132. package/src/providers/manga/index.ts +0 -14
  133. package/src/providers/manga/mangadex.ts +335 -282
  134. package/src/providers/manga/mangahere.ts +309 -156
  135. package/src/providers/manga/mangakakalot.ts +249 -152
  136. package/src/providers/manga/mangapill.ts +163 -64
  137. package/src/providers/meta/anilist.ts +50 -14
  138. package/src/utils/index.ts +1 -0
  139. package/src/utils/manga.ts +58 -0
  140. package/lib/commonjs/providers/manga/brmangas.js +0 -110
  141. package/lib/commonjs/providers/manga/brmangas.js.map +0 -1
  142. package/lib/commonjs/providers/manga/comick.js +0 -154
  143. package/lib/commonjs/providers/manga/comick.js.map +0 -1
  144. package/lib/commonjs/providers/manga/mangahost.js +0 -113
  145. package/lib/commonjs/providers/manga/mangahost.js.map +0 -1
  146. package/lib/commonjs/providers/manga/mangapark.js +0 -97
  147. package/lib/commonjs/providers/manga/mangapark.js.map +0 -1
  148. package/lib/commonjs/providers/manga/mangareader.js +0 -106
  149. package/lib/commonjs/providers/manga/mangareader.js.map +0 -1
  150. package/lib/commonjs/providers/manga/mangasee123.js +0 -161
  151. package/lib/commonjs/providers/manga/mangasee123.js.map +0 -1
  152. package/lib/commonjs/providers/manga/readmanga.js +0 -269
  153. package/lib/commonjs/providers/manga/readmanga.js.map +0 -1
  154. package/lib/commonjs/providers/manga/vyvymanga.js +0 -166
  155. package/lib/commonjs/providers/manga/vyvymanga.js.map +0 -1
  156. package/lib/module/providers/manga/brmangas.js +0 -105
  157. package/lib/module/providers/manga/brmangas.js.map +0 -1
  158. package/lib/module/providers/manga/comick.js +0 -149
  159. package/lib/module/providers/manga/comick.js.map +0 -1
  160. package/lib/module/providers/manga/mangahost.js +0 -108
  161. package/lib/module/providers/manga/mangahost.js.map +0 -1
  162. package/lib/module/providers/manga/mangapark.js +0 -92
  163. package/lib/module/providers/manga/mangapark.js.map +0 -1
  164. package/lib/module/providers/manga/mangareader.js +0 -101
  165. package/lib/module/providers/manga/mangareader.js.map +0 -1
  166. package/lib/module/providers/manga/mangasee123.js +0 -156
  167. package/lib/module/providers/manga/mangasee123.js.map +0 -1
  168. package/lib/module/providers/manga/readmanga.js +0 -264
  169. package/lib/module/providers/manga/readmanga.js.map +0 -1
  170. package/lib/module/providers/manga/vyvymanga.js +0 -161
  171. package/lib/module/providers/manga/vyvymanga.js.map +0 -1
  172. package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts +0 -18
  173. package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts.map +0 -1
  174. package/lib/typescript/commonjs/src/providers/manga/comick.d.ts +0 -39
  175. package/lib/typescript/commonjs/src/providers/manga/comick.d.ts.map +0 -1
  176. package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts +0 -18
  177. package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts.map +0 -1
  178. package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts +0 -14
  179. package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts.map +0 -1
  180. package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts +0 -18
  181. package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts.map +0 -1
  182. package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts +0 -17
  183. package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts.map +0 -1
  184. package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts +0 -31
  185. package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts.map +0 -1
  186. package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts +0 -17
  187. package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts.map +0 -1
  188. package/lib/typescript/module/src/providers/manga/brmangas.d.ts +0 -18
  189. package/lib/typescript/module/src/providers/manga/brmangas.d.ts.map +0 -1
  190. package/lib/typescript/module/src/providers/manga/comick.d.ts +0 -39
  191. package/lib/typescript/module/src/providers/manga/comick.d.ts.map +0 -1
  192. package/lib/typescript/module/src/providers/manga/mangahost.d.ts +0 -18
  193. package/lib/typescript/module/src/providers/manga/mangahost.d.ts.map +0 -1
  194. package/lib/typescript/module/src/providers/manga/mangapark.d.ts +0 -14
  195. package/lib/typescript/module/src/providers/manga/mangapark.d.ts.map +0 -1
  196. package/lib/typescript/module/src/providers/manga/mangareader.d.ts +0 -18
  197. package/lib/typescript/module/src/providers/manga/mangareader.d.ts.map +0 -1
  198. package/lib/typescript/module/src/providers/manga/mangasee123.d.ts +0 -17
  199. package/lib/typescript/module/src/providers/manga/mangasee123.d.ts.map +0 -1
  200. package/lib/typescript/module/src/providers/manga/readmanga.d.ts +0 -31
  201. package/lib/typescript/module/src/providers/manga/readmanga.d.ts.map +0 -1
  202. package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts +0 -17
  203. package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts.map +0 -1
  204. package/src/providers/manga/brmangas.ts +0 -148
  205. package/src/providers/manga/comick.ts +0 -285
  206. package/src/providers/manga/mangahost.ts +0 -134
  207. package/src/providers/manga/mangapark.ts +0 -115
  208. package/src/providers/manga/mangareader.ts +0 -132
  209. package/src/providers/manga/mangasee123.ts +0 -187
  210. package/src/providers/manga/readmanga.ts +0 -380
  211. package/src/providers/manga/vyvymanga.ts +0 -237
@@ -1,4 +1,4 @@
1
- import { load } from 'cheerio';
1
+ import { load, type CheerioAPI } from 'cheerio';
2
2
 
3
3
  import {
4
4
  MangaParser,
@@ -6,14 +6,100 @@ import {
6
6
  type IMangaInfo,
7
7
  type IMangaResult,
8
8
  MediaStatus,
9
+ type IMangaChapter,
9
10
  type IMangaChapterPage,
10
11
  type ProviderContext,
11
12
  } from '../../models';
12
13
  import { createProviderContext } from '../../utils/create-provider-context';
14
+ import { parseChapterNumber, parseVolumeNumber, sortChaptersForReading } from '../../utils/manga';
15
+
16
+ const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
17
+ const MINUTE = 60 * 1000;
18
+ const UNITS: Record<string, number> = {
19
+ second: 1000,
20
+ sec: 1000,
21
+ minute: MINUTE,
22
+ min: MINUTE,
23
+ hour: 60 * MINUTE,
24
+ day: 24 * 60 * MINUTE,
25
+ week: 7 * 24 * 60 * MINUTE,
26
+ };
27
+ // How many chapterfun.ashx requests run at once while collecting a chapter's page images.
28
+ const PAGE_REQUESTS_AT_ONCE = 4;
29
+
30
+ /** Undoes a JavaScript string literal's backslash escapes (`\'` → `'`). */
31
+ const unescapeJs = (text: string) =>
32
+ text.replace(/\\(.)/g, (_, char: string) => (char === 'n' ? '\n' : char === 'r' ? '\r' : char === 't' ? '\t' : char));
33
+
34
+ /**
35
+ * Runs Dean Edwards' packer (`eval(function(p,a,c,k,e,d){...}('payload',a,c,'k|e|y|s'.split('|'),0,{}))`)
36
+ * in reverse without evaluating any code: every word of the payload is looked up in the keyword list.
37
+ * Undefined when `source` holds no packed script.
38
+ */
39
+ function unpackPackedScript(source: string): string | undefined {
40
+ const match =
41
+ /\}\s*\(\s*'((?:[^'\\]|\\[\s\S])*)'\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*'((?:[^'\\]|\\[\s\S])*)'\.split\(\s*'\|'\s*\)/.exec(
42
+ source
43
+ );
44
+ if (!match) return undefined;
45
+ const radix = Number(match[2]);
46
+ const count = Number(match[3]);
47
+ const keywords = unescapeJs(match[4]!).split('|');
48
+ const encode = (value: number): string => {
49
+ const rest = value % radix;
50
+ return (
51
+ (value < radix ? '' : encode(Math.floor(value / radix))) +
52
+ (rest > 35 ? String.fromCharCode(rest + 29) : rest.toString(36))
53
+ );
54
+ };
55
+ const words = new Map<string, string>();
56
+ for (let index = 0; index < count; index++) words.set(encode(index), keywords[index] || encode(index));
57
+ return unescapeJs(match[1]!).replace(/\b\w+\b/g, (word) => words.get(word) ?? word);
58
+ }
59
+
60
+ /** The strings inside a JavaScript array literal's quotes (`'a','b'` or `"a","b"`). */
61
+ const quotedStrings = (list: string, quote: "'" | '"') =>
62
+ (list.match(quote === "'" ? /'[^']*'/g : /"[^"]*"/g) ?? []).map((item) => item.slice(1, -1));
63
+
64
+ /**
65
+ * MangaHere's chapter dates as ISO 8601: `Oct 24,2024` → `2024-10-24`, `7 hour ago` → that hour's
66
+ * timestamp, `Today`/`Yesterday` → that date. Other text is returned as the site wrote it.
67
+ */
68
+ function parseMangaHereDate(text: string | undefined, now: number = Date.now()): string | undefined {
69
+ const value = (text ?? '').trim();
70
+ if (!value) return undefined;
71
+ const calendar = /^([a-z]{3})[a-z]*\.?\s*(\d{1,2})\s*,\s*(\d{4})$/i.exec(value);
72
+ if (calendar) {
73
+ const month = MONTHS.indexOf(calendar[1]!.toLowerCase());
74
+ const date = new Date(Date.UTC(Number(calendar[3]), month, Number(calendar[2])));
75
+ if (month >= 0 && date.getUTCDate() === Number(calendar[2])) return date.toISOString().slice(0, 10);
76
+ return value;
77
+ }
78
+ const relative = /^(\d+)\s*(second|sec|minute|min|hour|day|week)s?\s+ago$/i.exec(value);
79
+ if (relative) {
80
+ // Rounded down to the unit, so the date doesn't change on every fetch.
81
+ const unit = UNITS[relative[2]!.toLowerCase()]!;
82
+ return new Date(Math.floor((now - Number(relative[1]) * unit) / unit) * unit).toISOString();
83
+ }
84
+ if (/^today$/i.test(value)) return new Date(now).toISOString().slice(0, 10);
85
+ if (/^yesterday$/i.test(value)) return new Date(now - UNITS.day!).toISOString().slice(0, 10);
86
+ return value;
87
+ }
88
+
89
+ const parseStatus = (text: string): MediaStatus | undefined => {
90
+ switch (text.trim().toLowerCase()) {
91
+ case 'ongoing':
92
+ return MediaStatus.ONGOING;
93
+ case 'completed':
94
+ return MediaStatus.COMPLETED;
95
+ default:
96
+ return undefined;
97
+ }
98
+ };
13
99
 
14
100
  export class MangaHere extends MangaParser {
15
101
  override readonly name = 'MangaHere';
16
- protected override baseUrl = 'http://www.mangahere.cc';
102
+ protected override baseUrl = 'https://www.mangahere.cc';
17
103
  protected override logo = 'https://i.pinimg.com/564x/51/08/62/51086247ed16ff8abae2df0bb06448e4.jpg';
18
104
  protected override classPath = 'MANGA.MangaHere';
19
105
 
@@ -22,49 +108,87 @@ export class MangaHere extends MangaParser {
22
108
  super();
23
109
  }
24
110
 
111
+ /** Covers and page images are refused (403) without a MangaHere Referer. */
112
+ private get imageHeaders(): Record<string, string> {
113
+ return { Referer: `${this.baseUrl}/` };
114
+ }
115
+
116
+ /**
117
+ * GET with the cookie that opens titles marked adult. withCredentials: false keeps React Native's
118
+ * native cookie jar from replacing that Cookie header on Android.
119
+ */
120
+ private request = async (url: string, headers: Record<string, string> = {}) => {
121
+ const { data } = await this.ctx.axios.get(url, {
122
+ headers: { ...headers, Cookie: 'isAdult=1' },
123
+ withCredentials: false,
124
+ });
125
+ return typeof data === 'string' ? data : String(data ?? '');
126
+ };
127
+
128
+ private absoluteUrl = (url: string | undefined): string | undefined => {
129
+ const value = url?.trim();
130
+ if (!value) return undefined;
131
+ if (value.startsWith('//')) return `https:${value}`;
132
+ if (value.startsWith('/')) return `${this.baseUrl}${value}`;
133
+ return /^https?:\/\//.test(value) ? value : undefined;
134
+ };
135
+
25
136
  override fetchMangaInfo = async (mangaId: string): Promise<IMangaInfo> => {
26
- const mangaInfo: IMangaInfo = {
27
- id: mangaId,
28
- title: '',
29
- };
30
137
  try {
31
- const { data } = await this.ctx.axios.get(`${this.baseUrl}/manga/${mangaId}`, {
32
- headers: {
33
- cookie: 'isAdult=1',
34
- },
35
- });
36
-
37
- const $ = load(data);
38
-
39
- mangaInfo.title = $('span.detail-info-right-title-font').text();
40
- mangaInfo.description = $('div.detail-info-right > p.fullcontent').text();
41
- mangaInfo.headers = { Referer: this.baseUrl };
42
- mangaInfo.image = $('div.detail-info-cover > img').attr('src');
43
- mangaInfo.genres = $('p.detail-info-right-tag-list > a')
44
- .map((i, el) => $(el).attr('title')?.trim())
45
- .get();
46
- switch ($('span.detail-info-right-title-tip').text()) {
47
- case 'Ongoing':
48
- mangaInfo.status = MediaStatus.ONGOING;
49
- break;
50
- case 'Completed':
51
- mangaInfo.status = MediaStatus.COMPLETED;
52
- break;
53
- default:
54
- mangaInfo.status = MediaStatus.UNKNOWN;
55
- break;
138
+ const url = `${this.baseUrl}/manga/${mangaId}/`;
139
+ const $ = load(await this.request(url));
140
+
141
+ const title = $('span.detail-info-right-title-font').first().text().trim();
142
+ // Unknown ids redirect to the search page, which has no title.
143
+ if (!title) throw new Error(`MangaHere has no manga '${mangaId}'`);
144
+
145
+ const mangaInfo: IMangaInfo = { id: mangaId, title, url };
146
+ const description = $('div.detail-info-right > p.fullcontent').text().trim();
147
+ if (description) mangaInfo.description = description;
148
+ const image = this.absoluteUrl($('div.detail-info-cover > img').attr('src'));
149
+ if (image) {
150
+ mangaInfo.image = image;
151
+ mangaInfo.headerForImage = this.imageHeaders;
56
152
  }
57
- mangaInfo.rating = parseFloat($('span.detail-info-right-title-star > span').last().text());
58
- mangaInfo.authors = $('p.detail-info-right-say > a')
59
- .map((i, el) => $(el).attr('title'))
60
- .get();
61
- mangaInfo.chapters = $('ul.detail-main-list > li')
62
- .map((i, el) => ({
63
- id: $(el).find('a').attr('href')?.split('/manga/')[1]?.slice(0, -7)!,
64
- title: $(el).find('a > div > p.title3').text(),
65
- releasedDate: $(el).find('a > div > p.title2').text().trim(),
66
- }))
67
- .get();
153
+ const genres = $('p.detail-info-right-tag-list > a')
154
+ .map((_, el) => ($(el).attr('title') || $(el).text()).trim())
155
+ .get()
156
+ .filter(Boolean);
157
+ if (genres.length) mangaInfo.genres = genres;
158
+ const status = parseStatus($('span.detail-info-right-title-tip').text());
159
+ if (status) mangaInfo.status = status;
160
+ const rating = parseFloat($('span.detail-info-right-title-star span.item-score').text());
161
+ if (Number.isFinite(rating)) mangaInfo.rating = rating;
162
+ const authors = $('p.detail-info-right-say > a')
163
+ .map((_, el) => ($(el).attr('title') || $(el).text()).trim())
164
+ .get()
165
+ .filter(Boolean);
166
+ if (authors.length) mangaInfo.authors = authors;
167
+
168
+ // The site lists the newest chapter first.
169
+ const seen = new Set<string>();
170
+ const chapters: IMangaChapter[] = [];
171
+ $('ul.detail-main-list > li > a').each((_, el) => {
172
+ const href = $(el).attr('href') ?? '';
173
+ const id = /\/manga\/(.+?)\/(?:\d+\.html)?$/.exec(href)?.[1];
174
+ if (!id || seen.has(id)) return;
175
+ seen.add(id);
176
+ const label = $(el).find('p.title3').text().trim();
177
+ const chapterNumber = parseChapterNumber(label) ?? numberIn(/\/c(\d+(?:\.\d+)?)$/, id);
178
+ const volumeNumber = parseVolumeNumber(label) ?? numberIn(/\/v(\d+(?:\.\d+)?)\//, id);
179
+ const chapter: IMangaChapter = {
180
+ id,
181
+ title: label || (chapterNumber !== undefined ? `Chapter ${chapterNumber}` : id.split('/').pop()!),
182
+ };
183
+ if (chapterNumber !== undefined) chapter.chapterNumber = chapterNumber;
184
+ if (volumeNumber !== undefined) chapter.volumeNumber = volumeNumber;
185
+ const releaseDate = parseMangaHereDate($(el).find('p.title2').text());
186
+ if (releaseDate) chapter.releaseDate = releaseDate;
187
+ const chapterUrl = this.absoluteUrl(href);
188
+ if (chapterUrl) chapter.url = chapterUrl;
189
+ chapters.push(chapter);
190
+ });
191
+ mangaInfo.chapters = sortChaptersForReading(chapters.reverse());
68
192
 
69
193
  return mangaInfo;
70
194
  } catch (err) {
@@ -73,92 +197,120 @@ export class MangaHere extends MangaParser {
73
197
  };
74
198
 
75
199
  override fetchChapterPages = async (chapterId: string): Promise<IMangaChapterPage[]> => {
76
- const chapterPages: IMangaChapterPage[] = [];
77
200
  const url = `${this.baseUrl}/manga/${chapterId}/1.html`;
78
201
 
79
202
  try {
80
- const { data } = await this.ctx.axios.get(url, {
81
- headers: {
82
- cookie: 'isAdult=1',
83
- },
84
- });
85
-
86
- const $ = load(data);
87
-
88
- const copyrightHandle =
89
- $('p.detail-block-content').text().match('Dear user') || $('p.detail-block-content').text().match('blocked');
90
- if (copyrightHandle) {
91
- throw Error(copyrightHandle.input?.trim());
92
- }
203
+ const html = await this.request(url);
204
+ const $ = load(html);
205
+
206
+ const notice = $('p.detail-block-content').text().trim();
207
+ if (/Dear user|blocked/.test(notice)) throw new Error(notice);
208
+
209
+ const scripts = $('script')
210
+ .map((_, el) => $(el).html() ?? '')
211
+ .get()
212
+ .filter((script) => script.includes('eval(function(p,a,c,k,e,d)'))
213
+ .map((script) => unpackPackedScript(script) ?? '');
214
+
215
+ // The long-strip (webtoon) reader lists every image in one packed script.
216
+ const strip = scripts.map((script) => /newImgs\s*=\s*\[([^\]]*)\]/.exec(script)?.[1]).find(Boolean);
217
+ const images =
218
+ strip !== undefined ? quotedStrings(strip, "'") : await this.fetchReaderImages(url, $, html, scripts);
219
+
220
+ const pages = images.map((img) => this.absoluteUrl(img));
221
+ if (pages.length === 0 || pages.some((img) => !img))
222
+ throw new Error(`MangaHere found no pages for '${chapterId}'`);
223
+ return pages.map((img, index) => ({ page: index + 1, img: img!, headerForImage: this.imageHeaders }));
224
+ } catch (err) {
225
+ throw new Error((err as Error).message);
226
+ }
227
+ };
93
228
 
94
- const bar = $('script[src*=chapter_bar]').data();
95
- const html = $.html();
96
- if (typeof bar !== 'undefined') {
97
- const ss = html.indexOf('eval(function(p,a,c,k,e,d)');
98
- const se = html.indexOf('</script>', ss);
99
- const s = html.substring(ss, se).replace('eval', '');
100
- const ds = eval(s) as string;
101
-
102
- const urls = ds.split("['")[1]?.split("']")[0]?.split("','")!;
103
-
104
- urls.map((url, i) =>
105
- chapterPages.push({
106
- page: i,
107
- img: `https:${url}`,
108
- headerForImage: { Referer: url },
109
- })
229
+ /**
230
+ * The page-by-page reader loads each image from chapterfun.ashx, whose packed answer names the
231
+ * image of the page asked for and of the page after it; so every other page is asked for, then any
232
+ * page still missing on its own.
233
+ */
234
+ private fetchReaderImages = async (
235
+ chapterUrl: string,
236
+ $: CheerioAPI,
237
+ html: string,
238
+ scripts: string[]
239
+ ): Promise<string[]> => {
240
+ const chapterId = /var\s+chapterid\s*=\s*(\d+)/.exec(html)?.[1];
241
+ // imagecount, else the highest page the pager links to.
242
+ const pageCount =
243
+ Number(/var\s+imagecount\s*=\s*(\d+)/.exec(html)?.[1]) ||
244
+ Math.max(
245
+ 0,
246
+ ...$('.pager-list-left a[data-page]')
247
+ .map((_, el) => Number($(el).attr('data-page')) || 0)
248
+ .get()
249
+ );
250
+ if (!chapterId || !pageCount) return [];
251
+
252
+ // guidkey=''+'4'+'2'+...; the site also answers with an empty key, which is the fallback.
253
+ const keyScript = scripts.map((script) => /guidkey\s*=\s*([^;]*);/.exec(script)?.[1]).find(Boolean);
254
+ const key = keyScript ? quotedStrings(keyScript, "'").join('') : '';
255
+
256
+ const pageBase = chapterUrl.slice(0, chapterUrl.lastIndexOf('/'));
257
+ const images: (string | undefined)[] = new Array(pageCount).fill(undefined);
258
+ let failure: unknown;
259
+ const fetchFrom = async (page: number) => {
260
+ try {
261
+ const found = await this.fetchChapterFun(
262
+ `${pageBase}/chapterfun.ashx?cid=${chapterId}&page=${page}`,
263
+ chapterUrl,
264
+ key
110
265
  );
111
- } else {
112
- let sKey = this.extractKey(html);
113
- const chapterIdsl = html.indexOf('chapterid');
114
- const chapterId = html.substring(chapterIdsl + 11, html.indexOf(';', chapterIdsl)).trim();
115
-
116
- const chapterPagesElmnt = $('body > div:nth-child(6) > div > span').children('a');
117
-
118
- const pages = parseInt(chapterPagesElmnt.last().prev().attr('data-page') ?? '0');
119
-
120
- const pageBase = url.substring(0, url.lastIndexOf('/'));
121
-
122
- let resText = '';
123
- for (let i = 1; i <= pages; i++) {
124
- const pageLink = `${pageBase}/chapterfun.ashx?cid=${chapterId}&page=${i}&key=${sKey}`;
125
-
126
- for (let j = 1; j <= 3; j++) {
127
- const { data } = await this.ctx.axios.get(pageLink, {
128
- headers: {
129
- 'Referer': url,
130
- 'X-Requested-With': 'XMLHttpRequest',
131
- 'cookie': 'isAdult=1',
132
- },
133
- });
134
-
135
- resText = data as string;
136
-
137
- if (resText) break;
138
- else sKey = '';
139
- }
140
-
141
- const ds = eval(resText.replace('eval', ''));
266
+ found.slice(0, 2).forEach((img, offset) => {
267
+ const index = page - 1 + offset;
268
+ if (index < pageCount && !images[index]) images[index] = img;
269
+ });
270
+ } catch (err) {
271
+ // The page is asked for again on its own; the error is thrown if it stays missing.
272
+ failure = err;
273
+ }
274
+ };
275
+ const missingPages = () => images.map((img, index) => (img ? 0 : index + 1)).filter((page) => page > 0);
142
276
 
143
- const baseLinksp = ds.indexOf('pix=') + 5;
144
- const baseLinkes = ds.indexOf(';', baseLinksp) - 1;
145
- const baseLink = ds.substring(baseLinksp, baseLinkes);
277
+ const everyOther: number[] = [];
278
+ for (let page = 1; page <= pageCount; page += 2) everyOther.push(page);
279
+ await inBatches(everyOther, PAGE_REQUESTS_AT_ONCE, fetchFrom);
280
+ await inBatches(missingPages(), PAGE_REQUESTS_AT_ONCE, fetchFrom);
146
281
 
147
- const imageLinksp = ds.indexOf('pvalue=') + 9;
148
- const imageLinkes = ds.indexOf('"', imageLinksp);
149
- const imageLink = ds.substring(imageLinksp, imageLinkes);
282
+ const lost = missingPages();
283
+ if (lost.length) {
284
+ if (failure) throw failure;
285
+ throw new Error(`MangaHere returned no image for page ${lost.join(', ')} of ${chapterUrl}`);
286
+ }
287
+ return images as string[];
288
+ };
150
289
 
151
- chapterPages.push({
152
- page: i - 1,
153
- img: `https:${baseLink}${imageLink}`,
154
- headerForImage: { Referer: url },
155
- });
156
- }
290
+ /** The image URLs one chapterfun.ashx answer names, retried (with an empty key) when it is empty. */
291
+ private fetchChapterFun = async (url: string, chapterUrl: string, key: string): Promise<string[]> => {
292
+ let sKey = key;
293
+ for (let attempt = 1; attempt <= 3; attempt++) {
294
+ let text = '';
295
+ try {
296
+ text = await this.request(`${url}&key=${sKey}`, {
297
+ 'Referer': chapterUrl,
298
+ 'X-Requested-With': 'XMLHttpRequest',
299
+ });
300
+ } catch (err) {
301
+ if (attempt === 3) throw err;
302
+ continue;
157
303
  }
158
- return chapterPages;
159
- } catch (err) {
160
- throw new Error((err as Error).message);
304
+ const script = unpackPackedScript(text) ?? text;
305
+ const pix = /var\s+pix\s*=\s*"([^"]*)"/.exec(script)?.[1] ?? '';
306
+ const list = /var\s+pvalue\s*=\s*\[([^\]]*)\]/.exec(script)?.[1];
307
+ // The first file is joined to a literal base (the same as pix so far), the others to pix.
308
+ const firstBase = /pvalue\[i\]\s*=\s*"([^"]*)"\s*\+\s*pvalue\[i\]/.exec(script)?.[1] ?? pix;
309
+ const files = list ? quotedStrings(list, '"') : [];
310
+ if (files.length) return files.map((file, index) => `${index === 0 ? firstBase : pix}${file}`);
311
+ sKey = '';
161
312
  }
313
+ return [];
162
314
  };
163
315
 
164
316
  override search = async (query: string, page: number = 1): Promise<ISearch<IMangaResult>> => {
@@ -167,49 +319,50 @@ export class MangaHere extends MangaParser {
167
319
  results: [],
168
320
  };
169
321
  try {
170
- const { data } = await this.ctx.axios.get(`${this.baseUrl}/search?title=${query}&page=${page}`);
171
- const $ = load(data);
172
-
173
- searchRes.hasNextPage = $('div.pager-list-left > a.active').next().text() !== '>';
174
-
175
- searchRes.results = $('div.container > div > div > ul > li')
176
- .map(
177
- (i, el): IMangaResult => ({
178
- id: $(el).find('a').attr('href')?.split('/')[2]!,
179
- title: $(el).find('p.manga-list-4-item-title > a').text(),
180
- headerForImage: { Referer: this.baseUrl },
181
- image: $(el).find('a > img').attr('src'),
182
- description: $(el).find('p').last().text(),
183
- status:
184
- $(el).find('p.manga-list-4-show-tag-list-2 > a').text() === 'Ongoing'
185
- ? MediaStatus.ONGOING
186
- : $(el).find('p.manga-list-4-show-tag-list-2 > a').text() === 'Completed'
187
- ? MediaStatus.COMPLETED
188
- : MediaStatus.UNKNOWN,
189
- })
190
- )
191
- .get();
322
+ const $ = load(await this.request(`${this.baseUrl}/search?title=${encodeURIComponent(query)}&page=${page}`));
323
+
324
+ // The last pager link is `>`; it goes nowhere (javascript:void(0)) on the last page.
325
+ const next = $('div.pager-list-left > a').last();
326
+ searchRes.hasNextPage = next.text().trim() === '>' && /^\//.test(next.attr('href') ?? '');
327
+
328
+ $('ul.manga-list-4-list > li').each((_, el) => {
329
+ const link = $(el).find('p.manga-list-4-item-title > a').first();
330
+ const id = /\/manga\/([^/]+)/.exec(link.attr('href') ?? $(el).find('a').first().attr('href') ?? '')?.[1];
331
+ const title = (link.text() || link.attr('title') || '').trim();
332
+ if (!id || !title) return;
333
+ const result: IMangaResult = { id, title, url: `${this.baseUrl}/manga/${id}/` };
334
+ const image = this.absoluteUrl($(el).find('img.manga-list-4-cover').attr('src'));
335
+ if (image) {
336
+ result.image = image;
337
+ result.headerForImage = this.imageHeaders;
338
+ }
339
+ // The tips are the author, the latest chapter and then the synopsis.
340
+ const description = $(el)
341
+ .find('p.manga-list-4-item-tip')
342
+ .filter((_index, tip) => !/^(Author|Latest Chapter)\s*:/i.test($(tip).text().trim()))
343
+ .last()
344
+ .text()
345
+ .trim();
346
+ if (description) result.description = description;
347
+ const status = parseStatus($(el).find('p.manga-list-4-show-tag-list-2 > a').text());
348
+ if (status) result.status = status;
349
+ searchRes.results.push(result);
350
+ });
192
351
  return searchRes;
193
352
  } catch (err) {
194
353
  throw new Error((err as Error).message);
195
354
  }
196
355
  };
356
+ }
197
357
 
198
- /**
199
- * credit: [tachiyomi-extensions](https://github.com/tachiyomiorg/tachiyomi-extensions/blob/master/src/en/mangahere/src/eu/kanade/tachiyomi/extension/en/mangahere/Mangahere.kt)
200
- */
201
- private extractKey = (html: string) => {
202
- const skss = html.indexOf('eval(function(p,a,c,k,e,d)');
203
- const skse = html.indexOf('</script>', skss);
204
- const sks = html.substring(skss, skse).replace('eval', '');
205
-
206
- const skds = eval(sks);
207
-
208
- const sksl = skds.indexOf("'");
209
- const skel = skds.indexOf(';');
210
-
211
- const skrs = skds.substring(sksl, skel);
358
+ const numberIn = (pattern: RegExp, text: string): number | undefined => {
359
+ const digits = pattern.exec(text)?.[1];
360
+ return digits === undefined ? undefined : Number(digits);
361
+ };
212
362
 
213
- return eval(skrs) as string;
214
- };
363
+ /** Runs `task` over `items`, `size` at a time. */
364
+ async function inBatches<T>(items: T[], size: number, task: (item: T) => Promise<void>): Promise<void> {
365
+ for (let start = 0; start < items.length; start += size) {
366
+ await Promise.all(items.slice(start, start + size).map((item) => task(item)));
367
+ }
215
368
  }