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,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 = '
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
mangaInfo.description =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
60
|
-
.
|
|
61
|
-
mangaInfo.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
.
|
|
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
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
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
|
}
|