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,21 +1,59 @@
1
- import { load } from 'cheerio';
1
+ import { load, type CheerioAPI } from 'cheerio';
2
2
 
3
3
  import {
4
4
  MangaParser,
5
+ MediaStatus,
5
6
  type ISearch,
6
7
  type IMangaInfo,
7
8
  type IMangaResult,
8
- MediaStatus,
9
9
  type IMangaChapterPage,
10
10
  type IMangaChapter,
11
11
  type ProviderContext,
12
12
  } from '../../models';
13
13
  import { createProviderContext } from '../../utils/create-provider-context';
14
+ import { parseChapterNumber, parseVolumeNumber, sortChaptersForReading } from '../../utils/manga';
15
+
16
+ /** One chapter as the site's chapter-list API (`/api/manga/<slug>/chapters`) returns it. */
17
+ interface ChapterRow {
18
+ chapter_name?: string;
19
+ chapter_slug?: string;
20
+ chapter_num?: number | string | null;
21
+ updated_at?: string;
22
+ view?: number;
23
+ }
24
+
25
+ // The chapter-list API pages through a title's chapters, newest first. The site's own page asks
26
+ // for 50 at a time; 500 keeps long series to a few requests (Cloudflare blocks `limit=1000`).
27
+ const CHAPTERS_PER_REQUEST = 500;
28
+ const MAX_CHAPTER_REQUESTS = 40;
29
+ /** Titles per search page, in both the HTML and the JSON form. */
30
+ const SEARCH_PAGE_SIZE = 20;
31
+
32
+ /**
33
+ * The search word the site's own search box sends: punctuation and spaces become `_`, which the
34
+ * site reads as a space (`Re:Zero` → `re_zero`).
35
+ */
36
+ const searchWord = (query: string): string =>
37
+ query
38
+ .toLowerCase()
39
+ .replace(/[\s!-/:-@[-`{-~]+/g, '_')
40
+ .replace(/^_+|_+$/g, '');
41
+
42
+ /** `2024-11-03T11:37:28.000000Z` (the API's microseconds) → `2024-11-03T11:37:28.000Z`. */
43
+ const toIsoDate = (value: string | undefined): string | undefined => {
44
+ if (!value) return undefined;
45
+ const match = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d+))?Z$/.exec(value.trim());
46
+ if (match) return `${match[1]}.${(match[2] ?? '').padEnd(3, '0').slice(0, 3)}Z`;
47
+ const time = Date.parse(value);
48
+ return Number.isNaN(time) ? value : new Date(time).toISOString();
49
+ };
14
50
 
15
51
  export class MangaKakalot extends MangaParser {
16
52
  override readonly name = 'MangaKakalot';
17
- protected override baseUrl = 'https://mangakakalot.com';
18
- protected override logo = 'https://techbigs.com/uploads/2022/1/mangakakalot-apkoptimized.jpg';
53
+ // mangakakalot.com is gone; mangakakalot.gg redirects here, and manganato.gg is the same site
54
+ // (same titles, ids and image hosts) under another name.
55
+ protected override baseUrl = 'https://www.kakamanga.com';
56
+ protected override logo = 'https://www.kakamanga.com/images/svg/logo-kkl.svg';
19
57
  protected override classPath = 'MANGA.MangaKakalot';
20
58
 
21
59
  /** @param ctx provider context; requests go through its axios (default: `createProviderContext()`) */
@@ -23,163 +61,222 @@ export class MangaKakalot extends MangaParser {
23
61
  super();
24
62
  }
25
63
 
26
- override fetchMangaInfo = async (mangaId: string): Promise<IMangaInfo> => {
27
- const mangaInfo: IMangaInfo = {
28
- id: mangaId,
29
- title: '',
30
- };
31
- const url = mangaId.includes('read') ? this.baseUrl : 'https://chapmanganato.to';
32
- try {
33
- const { data } = await this.ctx.axios.get(`${url}/${mangaId}`);
34
- const $ = load(data);
35
-
36
- if (url.includes('mangakakalot')) {
37
- mangaInfo.title = $('div.manga-info-top > ul > li:nth-child(1) > h1').text();
38
- mangaInfo.altTitles = $('div.manga-info-top > ul > li:nth-child(1) > h2')
39
- .text()
40
- .replace('Alternative :', '')
41
- .split(';');
42
- mangaInfo.description = $('#noidungm')
43
- .text()
44
- .replace(`${mangaInfo.title} summary:`, '')
45
- .replace(/\n/g, '')
46
- .trim();
47
- mangaInfo.headerForImage = { Referer: this.baseUrl };
48
- mangaInfo.image = $('div.manga-info-top > div > img').attr('src');
49
- mangaInfo.genres = $('div.manga-info-top > ul > li:nth-child(7) > a')
50
- .map((i, el) => $(el).text())
51
- .get();
52
-
53
- switch ($('div.manga-info-top > ul > li:nth-child(3)').text().replace('Status :', '').trim()) {
54
- case 'Completed':
55
- mangaInfo.status = MediaStatus.COMPLETED;
56
- break;
57
- case 'Ongoing':
58
- mangaInfo.status = MediaStatus.ONGOING;
59
- break;
60
- default:
61
- mangaInfo.status = MediaStatus.UNKNOWN;
62
- }
63
- mangaInfo.views = parseInt(
64
- $('div.manga-info-top > ul > li:nth-child(6)').text().replace('View : ', '').replace(/,/g, '').trim()
65
- );
66
- mangaInfo.authors = $('div.manga-info-top > ul > li:nth-child(2) > a')
67
- .map((i, el) => $(el).text())
68
- .get();
69
-
70
- mangaInfo.chapters = $('div.chapter-list > div.row')
71
- .map(
72
- (i, el): IMangaChapter => ({
73
- id: $(el).find('span > a').attr('href')?.split('chapter/')[1]!,
74
- title: $(el).find('span > a').text(),
75
- views: parseInt($(el).find('span:nth-child(2)').text()!.replace(/,/g, '').trim()),
76
- releasedDate: $(el).find('span:nth-child(3)').attr('title'),
77
- })
78
- )
79
- .get();
80
- } else {
81
- mangaInfo.title = $(' div.panel-story-info > div.story-info-right > h1').text();
82
- mangaInfo.altTitles = $('div.story-info-right > table > tbody > tr:nth-child(1) > td.table-value > h2')
83
- .text()
84
- .split(';');
85
- mangaInfo.description = $('#panel-story-info-description')
86
- .text()
87
- .replace(`Description :`, '')
88
- .replace(/\n/g, '')
89
- .trim();
90
- mangaInfo.headerForImage = { Referer: 'https://readmanganato.com' };
91
- mangaInfo.image = $('div.story-info-left > span.info-image > img').attr('src');
92
- mangaInfo.genres = $('div.story-info-right > table > tbody > tr:nth-child(4) > td.table-value > a')
93
- .map((i, el) => $(el).text())
94
- .get();
95
-
96
- switch ($('div.story-info-right > table > tbody > tr:nth-child(3) > td.table-value').text().trim()) {
97
- case 'Completed':
98
- mangaInfo.status = MediaStatus.COMPLETED;
99
- break;
100
- case 'Ongoing':
101
- mangaInfo.status = MediaStatus.ONGOING;
102
- break;
103
- default:
104
- mangaInfo.status = MediaStatus.UNKNOWN;
105
- }
106
- mangaInfo.views = parseInt(
107
- $('div.story-info-right > div > p:nth-child(2) > span.stre-value').text().replace(/,/g, '').trim()
108
- );
109
- mangaInfo.authors = $('div.story-info-right > table > tbody > tr:nth-child(2) > td.table-value > a')
110
- .map((i, el) => $(el).text())
111
- .get();
112
-
113
- mangaInfo.chapters = $('div.container-main-left > div.panel-story-chapter-list > ul > li')
114
- .map(
115
- (i, el): IMangaChapter => ({
116
- id: $(el).find('a').attr('href')?.split(`${mangaId}/`)[1]!,
117
- title: $(el).find('a').text(),
118
- views: parseInt($(el).find('span.chapter-view.text-nowrap').text()!.replace(/,/g, '').trim()),
119
- releasedDate: $(el).find('span.chapter-time.text-nowrap').attr('title'),
120
- })
121
- )
122
- .get();
123
- }
64
+ /**
65
+ * Covers and pages are on 2xstorage.com, which answers 403 unless the Referer is the site's
66
+ * origin (exactly `https://www.kakamanga.com/`; a page URL is refused too).
67
+ */
68
+ private imageHeaders = (): Record<string, string> => ({ Referer: `${this.baseUrl}/` });
124
69
 
125
- return mangaInfo;
126
- } catch (err) {
127
- throw new Error((err as Error).message);
128
- }
70
+ private absoluteUrl = (url: string | undefined): string | undefined => {
71
+ const value = url?.trim();
72
+ if (!value) return undefined;
73
+ if (value.startsWith('//')) return `https:${value}`;
74
+ if (value.startsWith('/')) return `${this.baseUrl}${value}`;
75
+ return /^https?:\/\//.test(value) ? value : undefined;
129
76
  };
130
77
 
131
- override fetchChapterPages = async (chapterId: string, mangaId: string): Promise<IMangaChapterPage[]> => {
132
- try {
133
- const url = chapterId.includes('$$READMANGANATO')
134
- ? `${this.baseUrl}/chapter/${chapterId}`
135
- : `https://chapmanganato.to/${mangaId}/${chapterId}`;
136
- const { data } = await this.ctx.axios.get(url);
137
- const $ = load(data);
138
-
139
- const pages = $('div.container-chapter-reader > img')
140
- .map(
141
- (i, el): IMangaChapterPage => ({
142
- img: $(el).attr('src')!,
143
- page: i,
144
- title: $(el)
145
- .attr('alt')
146
- ?.replace(/(- Mangakakalot.com)|(- MangaNato.com)/g, ' ')
147
- .trim()!,
148
- headerForImage: { Referer: this.baseUrl },
149
- })
78
+ /** The title's slug (its id) in `https://www.kakamanga.com/manga/<slug>`. */
79
+ private slugFromUrl = (url: string | undefined): string | undefined => /\/manga\/([^/?#]+)/.exec(url ?? '')?.[1];
80
+
81
+ /**
82
+ * @param query Search query
83
+ * @param page Page number (default: 1)
84
+ */
85
+ override search = async (query: string, page: number = 1): Promise<ISearch<IMangaResult>> => {
86
+ // /search/story/<word> is behind a Cloudflare challenge. The search box's endpoint serves the
87
+ // same results page, and JSON to requests sent with X-Requested-With (the search box's own).
88
+ // Cloudflare caches whichever it answered first for a URL, so either can come back.
89
+ const { data } = await this.ctx.axios.get(
90
+ `${this.baseUrl}/home/search/json?searchword=${encodeURIComponent(searchWord(query))}&page=${page}`
91
+ );
92
+ const json = typeof data === 'string' && /^\s*\[/.test(data) ? JSON.parse(data) : data;
93
+ if (Array.isArray(json)) return this.searchFromJson(json, page);
94
+
95
+ const $ = load(data);
96
+ const results: IMangaResult[] = [];
97
+ $('.panel_story_list .story_item').each((_, el) => {
98
+ const link = $(el).find('.story_name a').first();
99
+ const result = this.searchResult(link.attr('href'), link.text(), $(el).find('img').first().attr('src'));
100
+ if (result) results.push(result);
101
+ });
102
+
103
+ const next = $('.panel_page_number .group_page a')
104
+ .filter((_, el) => $(el).text().trim().toLowerCase() === 'next')
105
+ .first();
106
+ return {
107
+ currentPage: Number($('.panel_page_number .page_select').first().text().trim()) || page,
108
+ hasNextPage: next.attr('href') !== undefined && !next.hasClass('page_disabled'),
109
+ results,
110
+ };
111
+ };
112
+
113
+ /** The JSON form of a search page: `[{ name, url, thumb, slug, ... }]`, with no pagination. */
114
+ private searchFromJson = (items: any[], page: number): ISearch<IMangaResult> => {
115
+ const results = items
116
+ .map((item) =>
117
+ this.searchResult(
118
+ typeof item?.url === 'string' ? item.url : `/manga/${item?.slug}`,
119
+ load(String(item?.name ?? ''), null, false)
120
+ .root()
121
+ .text(),
122
+ item?.thumb
150
123
  )
151
- .get();
124
+ )
125
+ .filter((result): result is IMangaResult => result !== undefined);
126
+ // Pages hold SEARCH_PAGE_SIZE titles, so a full page is taken to have a next one.
127
+ return { currentPage: page, hasNextPage: items.length >= SEARCH_PAGE_SIZE, results };
128
+ };
152
129
 
153
- return pages;
154
- } catch (err) {
155
- throw new Error((err as Error).message);
156
- }
130
+ private searchResult = (href: unknown, name: string, cover: unknown): IMangaResult | undefined => {
131
+ const url = this.absoluteUrl(typeof href === 'string' ? href : undefined);
132
+ const id = this.slugFromUrl(url);
133
+ const title = name.replace(/\s+/g, ' ').trim();
134
+ if (!url || !id || !title) return undefined;
135
+ const result: IMangaResult = { id, title, url };
136
+ const image = this.absoluteUrl(typeof cover === 'string' ? cover : undefined);
137
+ if (image) Object.assign(result, { image, headerForImage: this.imageHeaders() });
138
+ return result;
139
+ };
140
+
141
+ /** @param mangaId the title's slug, e.g. `tomodachi-game` (from search results) */
142
+ override fetchMangaInfo = async (mangaId: string): Promise<IMangaInfo> => {
143
+ const [{ data }, chapters] = await Promise.all([
144
+ this.ctx.axios.get(`${this.baseUrl}/manga/${mangaId}`),
145
+ this.fetchChapters(mangaId),
146
+ ]);
147
+ const $ = load(data);
148
+
149
+ const title = $('.manga-info-text h1').first().text().trim();
150
+ const info: IMangaInfo = { id: mangaId, title, url: `${this.baseUrl}/manga/${mangaId}` };
151
+
152
+ // `Alternative : A; B`, which can repeat the title itself.
153
+ const altTitles = $('.manga-info-text h2.story-alternative')
154
+ .first()
155
+ .text()
156
+ .replace(/^\s*Alternative\s*:/i, '')
157
+ .split(';')
158
+ .map((alt) => alt.replace(/\s+/g, ' ').trim())
159
+ .filter((alt, i, all) => alt && alt !== title && all.indexOf(alt) === i);
160
+ if (altTitles.length) info.altTitles = altTitles;
161
+
162
+ const image = this.absoluteUrl($('.manga-info-pic img').first().attr('src'));
163
+ if (image) Object.assign(info, { image, headerForImage: this.imageHeaders() });
164
+
165
+ const description = this.description($);
166
+ if (description) info.description = description;
167
+
168
+ // `Author(s) : A, B`, `Status : Ongoing`, `View : 41,148,877`, ...
169
+ const fields: Record<string, string> = {};
170
+ $('.manga-info-text > li:not(:has(h1))').each((_, el) => {
171
+ const match = /^([^:]+?)\s*:\s*(.*)$/.exec($(el).text().replace(/\s+/g, ' ').trim());
172
+ if (match) fields[match[1]!.toLowerCase()] = match[2]!.trim();
173
+ });
174
+
175
+ const authors = (fields['author(s)'] ?? '')
176
+ .split(',')
177
+ .map((author) => author.trim())
178
+ .filter((author) => author && author.toLowerCase() !== 'unknown');
179
+ if (authors.length) info.authors = authors;
180
+
181
+ const status = (fields.status ?? '').toLowerCase();
182
+ if (status === 'ongoing') info.status = MediaStatus.ONGOING;
183
+ else if (status === 'completed') info.status = MediaStatus.COMPLETED;
184
+
185
+ const genres = $('.manga-info-text li.genres a')
186
+ .map((_, el) => $(el).text().trim())
187
+ .get()
188
+ .filter(Boolean);
189
+ if (genres.length) info.genres = genres;
190
+
191
+ const views = parseInt((fields.view ?? '').replace(/,/g, ''), 10);
192
+ if (Number.isFinite(views)) info.views = views;
193
+
194
+ info.chapters = chapters;
195
+ return info;
196
+ };
197
+
198
+ /** @param chapterId `<title slug>/<chapter slug>`, e.g. `tomodachi-game/chapter-127-5` */
199
+ override fetchChapterPages = async (chapterId: string): Promise<IMangaChapterPage[]> => {
200
+ const { data } = await this.ctx.axios.get(`${this.baseUrl}/manga/${chapterId}`);
201
+ const $ = load(data);
202
+
203
+ return $('.container-chapter-reader img')
204
+ .map((_, el) => this.absoluteUrl($(el).attr('src') ?? $(el).attr('data-src')))
205
+ .get()
206
+ .filter((img): img is string => Boolean(img))
207
+ .map((img, i): IMangaChapterPage => ({ img, page: i + 1, headerForImage: this.imageHeaders() }));
157
208
  };
158
209
 
159
210
  /**
160
- *
161
- * @param query Search query
211
+ * The synopsis under the `<title> summary:` heading, as plain text. Some titles store it as
212
+ * escaped HTML (`&amp;quot;`, `&lt;br&gt;`), so its text is read as HTML once more: whitespace
213
+ * collapses as a browser would and `<br>` breaks lines.
162
214
  */
163
- override search = async (query: string): Promise<ISearch<IMangaResult>> => {
164
- try {
165
- const { data } = await this.ctx.axios.get(`${this.baseUrl}/search/story/${query.replace(/ /g, '_')}`);
166
- const $ = load(data);
167
-
168
- const results = $('div.daily-update > div > div')
169
- .map(
170
- (i, el): IMangaResult => ({
171
- id: $(el).find('div > h3 > a').attr('href')?.split('/')[3]!,
172
- title: $(el).find('div > h3 > a').text(),
173
- image: $(el).find('a > img').attr('src'),
174
- headerForImage: { Referer: this.baseUrl },
175
- })
176
- )
177
- .get();
178
- return {
179
- results: results,
180
- };
181
- } catch (err) {
182
- throw new Error((err as Error).message);
215
+ private description = ($: CheerioAPI): string | undefined => {
216
+ const box = $('#contentBox').first().clone();
217
+ box.find('h2').remove();
218
+ box.find('br').replaceWith('&lt;br&gt;');
219
+ const html = box
220
+ .text()
221
+ .replace(/\s+/g, ' ')
222
+ .replace(/<br\s*\/?>/gi, '\n');
223
+ const text = load(html, null, false)
224
+ .root()
225
+ .text()
226
+ .split('\n')
227
+ .map((line) => line.trim())
228
+ .join('\n')
229
+ .replace(/\n{3,}/g, '\n\n')
230
+ .trim();
231
+ return text || undefined;
232
+ };
233
+
234
+ /** Every chapter of a title from the chapter-list API, in reading order. */
235
+ private fetchChapters = async (mangaId: string): Promise<IMangaChapter[]> => {
236
+ const rows: ChapterRow[] = [];
237
+ for (let request = 0; request < MAX_CHAPTER_REQUESTS; request++) {
238
+ const { data } = await this.ctx.axios.get(
239
+ `${this.baseUrl}/api/manga/${mangaId}/chapters?limit=${CHAPTERS_PER_REQUEST}&offset=${rows.length}`
240
+ );
241
+ const body = typeof data === 'string' ? JSON.parse(data) : data;
242
+ const page: ChapterRow[] | undefined = body?.data?.chapters;
243
+ if (!body?.success || !Array.isArray(page)) {
244
+ throw new Error(`MangaKakalot: no chapter list for '${mangaId}' (${body?.message ?? 'unexpected response'})`);
245
+ }
246
+ rows.push(...page);
247
+ if (!body.data.pagination?.has_more || page.length === 0) break;
183
248
  }
249
+
250
+ // A chapter published while paging shifts the offsets, so a row can come twice.
251
+ const seen = new Set<string>();
252
+ const chapters: IMangaChapter[] = [];
253
+ for (const row of rows) {
254
+ const chapter = this.toChapter(mangaId, row);
255
+ if (!chapter || seen.has(chapter.id)) continue;
256
+ seen.add(chapter.id);
257
+ chapters.push(chapter);
258
+ }
259
+ return sortChaptersForReading(chapters.reverse());
260
+ };
261
+
262
+ private toChapter = (mangaId: string, row: ChapterRow): IMangaChapter | undefined => {
263
+ const slug = row.chapter_slug?.trim();
264
+ if (!slug) return undefined;
265
+ const label = row.chapter_name?.replace(/\s+/g, ' ').trim() ?? '';
266
+ const apiNumber = row.chapter_num === null || row.chapter_num === '' ? NaN : Number(row.chapter_num);
267
+ const chapterNumber = parseChapterNumber(label) ?? (Number.isFinite(apiNumber) ? apiNumber : undefined);
268
+
269
+ const chapter: IMangaChapter = {
270
+ id: `${mangaId}/${slug}`,
271
+ title: label || (chapterNumber !== undefined ? `Chapter ${chapterNumber}` : slug),
272
+ };
273
+ if (chapterNumber !== undefined) chapter.chapterNumber = chapterNumber;
274
+ const volumeNumber = parseVolumeNumber(label);
275
+ if (volumeNumber !== undefined) chapter.volumeNumber = volumeNumber;
276
+ const releaseDate = toIsoDate(row.updated_at);
277
+ if (releaseDate) chapter.releaseDate = releaseDate;
278
+ if (typeof row.view === 'number') chapter.views = row.view;
279
+ chapter.url = `${this.baseUrl}/manga/${mangaId}/${slug}`;
280
+ return chapter;
184
281
  };
185
282
  }