react-native-consumet 2.0.0 → 3.0.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/lib/commonjs/extension-registry.json.sig +1 -1
- package/lib/commonjs/index.js +18 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/types.js +6 -0
- package/lib/commonjs/models/types.js.map +1 -1
- package/lib/commonjs/providers/manga/asurascans.js +160 -96
- package/lib/commonjs/providers/manga/asurascans.js.map +1 -1
- package/lib/commonjs/providers/manga/flamescans.js +173 -91
- package/lib/commonjs/providers/manga/flamescans.js.map +1 -1
- package/lib/commonjs/providers/manga/index.js +1 -15
- package/lib/commonjs/providers/manga/index.js.map +1 -1
- package/lib/commonjs/providers/manga/mangadex.js +234 -227
- package/lib/commonjs/providers/manga/mangadex.js.map +1 -1
- package/lib/commonjs/providers/manga/mangahere.js +279 -135
- package/lib/commonjs/providers/manga/mangahere.js.map +1 -1
- package/lib/commonjs/providers/manga/mangakakalot.js +206 -107
- package/lib/commonjs/providers/manga/mangakakalot.js.map +1 -1
- package/lib/commonjs/providers/manga/mangapill.js +126 -38
- package/lib/commonjs/providers/manga/mangapill.js.map +1 -1
- package/lib/commonjs/providers/meta/anilist.js +41 -12
- package/lib/commonjs/providers/meta/anilist.js.map +1 -1
- package/lib/commonjs/utils/index.js +19 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/manga.js +60 -0
- package/lib/commonjs/utils/manga.js.map +1 -0
- package/lib/module/extension-registry.json.sig +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/types.js +9 -0
- package/lib/module/models/types.js.map +1 -1
- package/lib/module/providers/manga/asurascans.js +161 -96
- package/lib/module/providers/manga/asurascans.js.map +1 -1
- package/lib/module/providers/manga/flamescans.js +174 -91
- package/lib/module/providers/manga/flamescans.js.map +1 -1
- package/lib/module/providers/manga/index.js +1 -15
- package/lib/module/providers/manga/index.js.map +1 -1
- package/lib/module/providers/manga/mangadex.js +236 -228
- package/lib/module/providers/manga/mangadex.js.map +1 -1
- package/lib/module/providers/manga/mangahere.js +276 -132
- package/lib/module/providers/manga/mangahere.js.map +1 -1
- package/lib/module/providers/manga/mangakakalot.js +207 -107
- package/lib/module/providers/manga/mangakakalot.js.map +1 -1
- package/lib/module/providers/manga/mangapill.js +128 -39
- package/lib/module/providers/manga/mangapill.js.map +1 -1
- package/lib/module/providers/meta/anilist.js +41 -12
- package/lib/module/providers/meta/anilist.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/manga.js +54 -0
- package/lib/module/utils/manga.js.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/types.d.ts +38 -5
- package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts +14 -4
- package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts +18 -3
- package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/index.d.ts +0 -14
- package/lib/typescript/commonjs/src/providers/manga/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts +22 -5
- package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts +15 -3
- package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts +26 -4
- package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts +16 -2
- package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts +1 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/manga.d.ts +19 -0
- package/lib/typescript/commonjs/src/utils/manga.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +2 -2
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/models/types.d.ts +38 -5
- package/lib/typescript/module/src/models/types.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/asurascans.d.ts +14 -4
- package/lib/typescript/module/src/providers/manga/asurascans.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/flamescans.d.ts +18 -3
- package/lib/typescript/module/src/providers/manga/flamescans.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/index.d.ts +0 -14
- package/lib/typescript/module/src/providers/manga/index.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangadex.d.ts +22 -5
- package/lib/typescript/module/src/providers/manga/mangadex.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangahere.d.ts +15 -3
- package/lib/typescript/module/src/providers/manga/mangahere.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts +26 -4
- package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangapill.d.ts +16 -2
- package/lib/typescript/module/src/providers/manga/mangapill.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/index.d.ts +1 -0
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/manga.d.ts +19 -0
- package/lib/typescript/module/src/utils/manga.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/extension-registry.json.sig +1 -1
- package/src/index.tsx +6 -0
- package/src/models/types.ts +38 -3
- package/src/providers/manga/asurascans.ts +200 -135
- package/src/providers/manga/flamescans.ts +221 -118
- package/src/providers/manga/index.ts +0 -14
- package/src/providers/manga/mangadex.ts +335 -282
- package/src/providers/manga/mangahere.ts +309 -156
- package/src/providers/manga/mangakakalot.ts +249 -152
- package/src/providers/manga/mangapill.ts +163 -64
- package/src/providers/meta/anilist.ts +50 -14
- package/src/utils/index.ts +1 -0
- package/src/utils/manga.ts +58 -0
- package/lib/commonjs/providers/manga/brmangas.js +0 -110
- package/lib/commonjs/providers/manga/brmangas.js.map +0 -1
- package/lib/commonjs/providers/manga/comick.js +0 -154
- package/lib/commonjs/providers/manga/comick.js.map +0 -1
- package/lib/commonjs/providers/manga/mangahost.js +0 -113
- package/lib/commonjs/providers/manga/mangahost.js.map +0 -1
- package/lib/commonjs/providers/manga/mangapark.js +0 -97
- package/lib/commonjs/providers/manga/mangapark.js.map +0 -1
- package/lib/commonjs/providers/manga/mangareader.js +0 -106
- package/lib/commonjs/providers/manga/mangareader.js.map +0 -1
- package/lib/commonjs/providers/manga/mangasee123.js +0 -161
- package/lib/commonjs/providers/manga/mangasee123.js.map +0 -1
- package/lib/commonjs/providers/manga/readmanga.js +0 -269
- package/lib/commonjs/providers/manga/readmanga.js.map +0 -1
- package/lib/commonjs/providers/manga/vyvymanga.js +0 -166
- package/lib/commonjs/providers/manga/vyvymanga.js.map +0 -1
- package/lib/module/providers/manga/brmangas.js +0 -105
- package/lib/module/providers/manga/brmangas.js.map +0 -1
- package/lib/module/providers/manga/comick.js +0 -149
- package/lib/module/providers/manga/comick.js.map +0 -1
- package/lib/module/providers/manga/mangahost.js +0 -108
- package/lib/module/providers/manga/mangahost.js.map +0 -1
- package/lib/module/providers/manga/mangapark.js +0 -92
- package/lib/module/providers/manga/mangapark.js.map +0 -1
- package/lib/module/providers/manga/mangareader.js +0 -101
- package/lib/module/providers/manga/mangareader.js.map +0 -1
- package/lib/module/providers/manga/mangasee123.js +0 -156
- package/lib/module/providers/manga/mangasee123.js.map +0 -1
- package/lib/module/providers/manga/readmanga.js +0 -264
- package/lib/module/providers/manga/readmanga.js.map +0 -1
- package/lib/module/providers/manga/vyvymanga.js +0 -161
- package/lib/module/providers/manga/vyvymanga.js.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts +0 -18
- package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/comick.d.ts +0 -39
- package/lib/typescript/commonjs/src/providers/manga/comick.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts +0 -18
- package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts +0 -14
- package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts +0 -18
- package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts +0 -17
- package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts +0 -31
- package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts +0 -17
- package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/brmangas.d.ts +0 -18
- package/lib/typescript/module/src/providers/manga/brmangas.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/comick.d.ts +0 -39
- package/lib/typescript/module/src/providers/manga/comick.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangahost.d.ts +0 -18
- package/lib/typescript/module/src/providers/manga/mangahost.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangapark.d.ts +0 -14
- package/lib/typescript/module/src/providers/manga/mangapark.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangareader.d.ts +0 -18
- package/lib/typescript/module/src/providers/manga/mangareader.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangasee123.d.ts +0 -17
- package/lib/typescript/module/src/providers/manga/mangasee123.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/readmanga.d.ts +0 -31
- package/lib/typescript/module/src/providers/manga/readmanga.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts +0 -17
- package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts.map +0 -1
- package/src/providers/manga/brmangas.ts +0 -148
- package/src/providers/manga/comick.ts +0 -285
- package/src/providers/manga/mangahost.ts +0 -134
- package/src/providers/manga/mangapark.ts +0 -115
- package/src/providers/manga/mangareader.ts +0 -132
- package/src/providers/manga/mangasee123.ts +0 -187
- package/src/providers/manga/readmanga.ts +0 -380
- 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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
*
|
|
211
|
+
* The synopsis under the `<title> summary:` heading, as plain text. Some titles store it as
|
|
212
|
+
* escaped HTML (`&quot;`, `<br>`), so its text is read as HTML once more: whitespace
|
|
213
|
+
* collapses as a browser would and `<br>` breaks lines.
|
|
162
214
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
215
|
+
private description = ($: CheerioAPI): string | undefined => {
|
|
216
|
+
const box = $('#contentBox').first().clone();
|
|
217
|
+
box.find('h2').remove();
|
|
218
|
+
box.find('br').replaceWith('<br>');
|
|
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
|
}
|