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
@@ -2,151 +2,254 @@ import { load } 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
9
  type IMangaChapterPage,
9
10
  type IMangaChapter,
10
- MediaStatus,
11
11
  type ProviderContext,
12
12
  } from '../../models';
13
13
  import { createProviderContext } from '../../utils/create-provider-context';
14
+ import { parseChapterNumber, sortChaptersForReading } from '../../utils/manga';
15
+
16
+ /** Covers and chapter pages; the CDN serves them without a Referer. */
17
+ const IMAGE_CDN = 'https://cdn.flamecomics.xyz/uploads/images/series';
18
+
19
+ /** A series as the site's browse and series pages describe it. */
20
+ interface FlameSeries {
21
+ series_id?: number;
22
+ /** Set (instead of `series_id`) on the web novels the browse page also lists. */
23
+ novel_id?: number | null;
24
+ title?: string;
25
+ altTitles?: string[];
26
+ /** HTML on the series page, plain text on the browse page. */
27
+ description?: string | null;
28
+ tags?: string[];
29
+ author?: string[];
30
+ artist?: string[];
31
+ year?: number | null;
32
+ status?: string;
33
+ cover?: string;
34
+ last_edit?: number;
35
+ }
36
+
37
+ interface FlameChapter {
38
+ series_id?: number;
39
+ /** `"12.00"`, `"10.50"` */
40
+ chapter?: string;
41
+ /** The chapter's name; null or empty when it has none. */
42
+ title?: string | null;
43
+ token: string;
44
+ release_date?: number | null;
45
+ }
46
+
47
+ interface FlameReaderChapter {
48
+ edit_time?: number;
49
+ images?: Record<string, { name?: string }> | { name?: string }[];
50
+ }
14
51
 
52
+ const STATUS: Record<string, MediaStatus> = {
53
+ 'ongoing': MediaStatus.ONGOING,
54
+ 'completed': MediaStatus.COMPLETED,
55
+ 'hiatus': MediaStatus.HIATUS,
56
+ 'dropped': MediaStatus.CANCELLED,
57
+ 'cancelled': MediaStatus.CANCELLED,
58
+ 'coming soon': MediaStatus.NOT_YET_AIRED,
59
+ };
60
+
61
+ /** Lower-case words without punctuation, so `returners magic` finds "A Returner's Magic". */
62
+ const searchable = (text: string) =>
63
+ text
64
+ .toLowerCase()
65
+ .replace(/['`\u2018\u2019]/g, '')
66
+ .replace(/[^a-z0-9\u00c0-\u1fff\u2070-\uffff]+/g, ' ')
67
+ .trim();
68
+
69
+ /** Plain text of the site's HTML descriptions (paragraphs become blank-line separated). */
70
+ const plainText = (html: string | null | undefined): string | undefined => {
71
+ if (!html) return undefined;
72
+ const $ = load(html);
73
+ $('br').replaceWith('\n');
74
+ $('p').after('\n\n');
75
+ const text = $.root()
76
+ .text()
77
+ .replace(/[ \t]+\n/g, '\n')
78
+ .replace(/\n{3,}/g, '\n\n')
79
+ .trim();
80
+ return text || undefined;
81
+ };
82
+
83
+ /** The non-empty strings of a list, trimmed and without repeats. */
84
+ const strings = (values: unknown): string[] =>
85
+ Array.isArray(values)
86
+ ? [...new Set(values.filter((v): v is string => typeof v === 'string').map((v) => v.trim()))].filter(Boolean)
87
+ : [];
88
+
89
+ const parseJson = (data: unknown): any => {
90
+ if (typeof data !== 'string') return data;
91
+ try {
92
+ return JSON.parse(data);
93
+ } catch {
94
+ return undefined;
95
+ }
96
+ };
97
+
98
+ const isoDate = (unixSeconds: number | null | undefined): string | undefined =>
99
+ typeof unixSeconds === 'number' && unixSeconds > 0 ? new Date(unixSeconds * 1000).toISOString() : undefined;
100
+
101
+ /**
102
+ * Flame Comics (https://flamecomics.xyz), the scanlation group formerly at flamescans.org. The site
103
+ * is a Next.js app: every page's data comes as JSON from `/_next/data/<buildId>/<page>.json`.
104
+ */
15
105
  export class FlameScans extends MangaParser {
16
- override readonly name = 'FlameScans';
17
- protected override baseUrl = 'https://flamescans.org/';
18
- protected override logo = 'https://i.imgur.com/Nt1MW3H.png';
106
+ override readonly name = 'FlameComics';
107
+ protected override baseUrl = 'https://flamecomics.xyz';
108
+ protected override logo = 'https://flamecomics.xyz/og-default.png';
19
109
  protected override classPath = 'MANGA.FlameScans';
20
110
 
111
+ private buildIdRequest?: Promise<string>;
112
+
21
113
  /** @param ctx provider context; requests go through its axios (default: `createProviderContext()`) */
22
114
  constructor(private readonly ctx: ProviderContext = createProviderContext()) {
23
115
  super();
24
116
  }
25
117
 
26
118
  /**
119
+ * The site has no search endpoint: its browse page lists every series, and this keeps the ones
120
+ * whose title has every word of the query. All matches come on page 1.
27
121
  *
28
122
  * @param query Search query
29
- *
123
+ * @param page Page number (default 1)
30
124
  */
31
-
32
- override search = async (query: string): Promise<ISearch<IMangaResult>> => {
33
- try {
34
- const { data } = await this.ctx.axios.get(`${this.baseUrl}/series/?title=${query.replace(/ /g, '%20')}`);
35
- const $ = load(data);
36
-
37
- const searchMangaSelector = '.utao .uta .imgu, .listupd .bs .bsx, .listo .bs .bsx';
38
- const results = $(searchMangaSelector)
39
- .map(
40
- (i, el): IMangaResult => ({
41
- id: $(el).find('a').attr('href')?.split('/series/')[1]!.replace('/', '') ?? '',
42
- title: $(el).find('a').attr('title') ?? '',
43
- image: $(el).find('img').attr('src'),
44
- })
45
- )
46
- .get();
47
-
48
- return {
49
- results: results,
50
- };
51
- } catch (err) {
52
- throw new Error((err as Error).message);
53
- }
125
+ override search = async (query: string, page: number = 1): Promise<ISearch<IMangaResult>> => {
126
+ const { series = [] } = await this.nextData<{ series?: FlameSeries[] }>('browse');
127
+ const words = searchable(query).split(' ').filter(Boolean);
128
+ const results =
129
+ page > 1
130
+ ? []
131
+ : series
132
+ .filter((entry) => typeof entry.series_id === 'number' && entry.title?.trim())
133
+ .filter((entry) => words.every((word) => searchable(entry.title!).includes(word)))
134
+ .map((entry) => this.toResult(entry));
135
+ return { currentPage: page, hasNextPage: false, results };
54
136
  };
55
137
 
138
+ /** @param mangaId series id from `search` (`"101"`) */
56
139
  override fetchMangaInfo = async (mangaId: string): Promise<IMangaInfo> => {
57
- const mangaInfo: IMangaInfo = {
58
- id: mangaId,
59
- title: '',
60
- };
61
- try {
62
- const { data } = await this.ctx.axios.get(`${this.baseUrl}/manga/${mangaId}`);
63
- const $ = load(data);
64
-
65
- // base from https://github.com/tachiyomiorg/tachiyomi-extensions/blob/661311c13b3b550e3fa906c1130b77a037ef7a11/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt#L233
66
- const seriesTitleSelector = 'h1.entry-title';
67
- const seriesArtistSelector =
68
- ".infotable tr:icontains('artist') td:last-child, .tsinfo .imptdt:icontains('artist') i, .fmed b:icontains('artist')+span, span:icontains('artist')";
69
- const seriesAuthorSelector =
70
- ".infotable tr:icontains('author') td:last-child, .tsinfo .imptdt:icontains('author') i, .fmed b:icontains('author')+span, span:icontains('author')";
71
- const seriesDescriptionSelector = '.desc, .entry-content[itemprop=description]';
72
- const seriesAltNameSelector = ".alternative > div, .wd-full:icontains('alt') span, .alter, .seriestualt";
73
- const seriesGenreSelector = 'div.gnr a, .mgen a, .seriestugenre a';
74
- const seriesStatusSelector =
75
- ".infotable tr:icontains('status') td:last-child, .tsinfo .imptdt:icontains('status') i, .fmed b:icontains('status')+span span:icontains('status')";
76
- const seriesThumbnailSelector = '.infomanga > div[itemprop=image] img, .thumb img';
77
- const seriesChaptersSelector = 'div.bxcl li, div.cl li, #chapterlist li, ul li:has(div.chbox):has(div.eph-num)';
78
-
79
- mangaInfo.title = $(seriesTitleSelector).text().trim();
80
- mangaInfo.altTitles = $(seriesAltNameSelector).text()
81
- ? $(seriesAltNameSelector)
82
- .first()
83
- .text()
84
- .split('|')
85
- .map((item) => item.replace(/\n/g, ' ').trim())
86
- : [];
87
- mangaInfo.description = $(seriesDescriptionSelector).text().trim();
88
- mangaInfo.headerForImage = { Referer: this.baseUrl };
89
- mangaInfo.image = $(seriesThumbnailSelector).attr('src');
90
- mangaInfo.genres = $(seriesGenreSelector)
91
- .map((i, el) => $(el).text())
92
- .get();
93
- switch ($(seriesStatusSelector).text().trim()) {
94
- case 'Completed':
95
- mangaInfo.status = MediaStatus.COMPLETED;
96
- break;
97
- case 'Ongoing':
98
- mangaInfo.status = MediaStatus.ONGOING;
99
- break;
100
- case 'Dropped':
101
- mangaInfo.status = MediaStatus.CANCELLED;
102
- break;
103
- default:
104
- mangaInfo.status = MediaStatus.UNKNOWN;
105
- break;
106
- }
107
- mangaInfo.authors = $(seriesAuthorSelector).text().replace('-', '').trim()
108
- ? $(seriesAuthorSelector)
109
- .text()
110
- .split(',')
111
- .map((item) => item.trim())
112
- : [];
113
- mangaInfo.artist = $(seriesArtistSelector).text().trim() ? $(seriesArtistSelector).text().trim() : 'N/A';
114
- mangaInfo.chapters = $(seriesChaptersSelector)
115
- .map(
116
- (i, el): IMangaChapter => ({
117
- id: $(el).find('a').attr('href')?.split('/')[3] ?? '',
118
- title: $(el).find('.lch a, .chapternum').text().trim().replace(/\n/g, ' '),
119
- releasedDate: $(el).find('.chapterdate').text(),
120
- })
121
- )
122
- .get();
123
-
124
- return mangaInfo;
125
- } catch (err) {
126
- throw new Error((err as Error).message);
140
+ const id = String(mangaId).trim();
141
+ if (!/^\d+$/.test(id))
142
+ throw new Error(`FlameComics: invalid series id '${mangaId}' (expected a number like '101')`);
143
+
144
+ const { series, chapters = [] } = await this.nextData<{ series?: FlameSeries; chapters?: FlameChapter[] }>(
145
+ `series/${id}`
146
+ );
147
+ if (!series?.title) throw new Error(`FlameComics: series ${id} not found`);
148
+
149
+ const info: IMangaInfo = this.toResult({ ...series, series_id: series.series_id ?? Number(id) });
150
+ const title = info.title as string;
151
+ const altTitles = strings(series.altTitles).filter((alt) => alt.toLowerCase() !== title.toLowerCase());
152
+ if (altTitles.length) info.altTitles = altTitles;
153
+ for (const [field, values] of [
154
+ ['genres', series.tags],
155
+ ['authors', series.author],
156
+ ['artists', series.artist],
157
+ ] as const) {
158
+ const list = strings(values);
159
+ if (list.length) info[field] = list;
127
160
  }
161
+ // The site lists the newest chapter first.
162
+ info.chapters = sortChaptersForReading(chapters.map((chapter) => this.toChapter(chapter, id)).reverse());
163
+ return info;
128
164
  };
129
165
 
166
+ /** @param chapterId chapter id from `fetchMangaInfo` (`"101/327c2f17ef9cacd3"`: series id / chapter token) */
130
167
  override fetchChapterPages = async (chapterId: string): Promise<IMangaChapterPage[]> => {
131
- try {
132
- const { data } = await this.ctx.axios.get(`${this.baseUrl}/${chapterId}`);
133
- const $ = load(data);
134
-
135
- const pageSelector = 'div#readerarea img, #readerarea div.figure_container div.composed_figure';
136
-
137
- const pages = $(pageSelector)
138
- .map(
139
- (i, el): IMangaChapterPage => ({
140
- img: $(el).attr('src')!,
141
- page: i,
142
- headerForImage: { Referer: this.baseUrl },
143
- })
144
- )
145
- .get();
146
-
147
- return pages;
148
- } catch (err) {
149
- throw new Error((err as Error).message);
150
- }
168
+ const match = /^(\d+)\/([A-Za-z0-9]+)$/.exec(String(chapterId).trim());
169
+ if (!match) throw new Error(`FlameComics: invalid chapter id '${chapterId}' (expected '<seriesId>/<token>')`);
170
+ const seriesId = match[1]!;
171
+ const token = match[2]!;
172
+
173
+ const { chapter } = await this.nextData<{ chapter?: FlameReaderChapter }>(`series/${seriesId}/${token}`);
174
+ if (!chapter) throw new Error(`FlameComics: chapter ${chapterId} not found`);
175
+
176
+ // `images` is keyed by position ("0", "1", ...); the site adds the chapter's edit time to bust caches.
177
+ const version = chapter.edit_time ? `?${chapter.edit_time}` : '';
178
+ return Object.entries(chapter.images ?? {})
179
+ .sort(([a], [b]) => Number(a) - Number(b))
180
+ .map(([, image]) => image?.name)
181
+ .filter((name): name is string => typeof name === 'string' && name.length > 0)
182
+ .map((name, i) => ({
183
+ img: `${IMAGE_CDN}/${seriesId}/${token}/${encodeURIComponent(name)}${version}`,
184
+ page: i + 1,
185
+ }));
151
186
  };
187
+
188
+ private toResult(series: FlameSeries): IMangaResult {
189
+ const id = String(series.series_id);
190
+ const result: IMangaResult = { id, title: series.title!.trim(), url: `${this.baseUrl}/series/${id}` };
191
+ // The site adds the series' edit time to cover URLs to bust caches.
192
+ if (series.cover) {
193
+ const version = series.last_edit ? `?${series.last_edit}` : '';
194
+ result.image = `${IMAGE_CDN}/${id}/${encodeURIComponent(series.cover)}${version}`;
195
+ }
196
+ const description = plainText(series.description);
197
+ if (description) result.description = description;
198
+ const status = series.status?.trim();
199
+ if (status) result.status = STATUS[status.toLowerCase()] ?? MediaStatus.UNKNOWN;
200
+ if (typeof series.year === 'number' && series.year > 0) result.releaseDate = series.year;
201
+ return result;
202
+ }
203
+
204
+ private toChapter(chapter: FlameChapter, seriesId: string): IMangaChapter {
205
+ const id = `${chapter.series_id ?? seriesId}/${chapter.token}`;
206
+ const chapterNumber = parseChapterNumber(chapter.chapter);
207
+ // Labelled like the site: "Chapter 151 - Season 4 Start", or "Chapter 152" when it has no name.
208
+ const label = `Chapter ${chapterNumber ?? chapter.chapter ?? ''}`.trim();
209
+ const name = chapter.title?.trim();
210
+ const result: IMangaChapter = { id, title: name ? `${label} - ${name}` : label };
211
+ if (chapterNumber !== undefined) result.chapterNumber = chapterNumber;
212
+ const releaseDate = isoDate(chapter.release_date);
213
+ if (releaseDate) result.releaseDate = releaseDate;
214
+ result.url = `${this.baseUrl}/series/${id}`;
215
+ return result;
216
+ }
217
+
218
+ /** `pageProps` of a site page (`browse`, `series/101`), from its Next.js data route. */
219
+ private async nextData<T>(path: string, retried = false): Promise<T> {
220
+ const buildIdRequest = this.buildId();
221
+ const buildId = await buildIdRequest;
222
+ const { status, data } = await this.ctx.axios.get(`${this.baseUrl}/_next/data/${buildId}/${path}.json`, {
223
+ validateStatus: (code: number) => (code >= 200 && code < 300) || code === 404,
224
+ });
225
+ const json = parseJson(data);
226
+ if (status === 404) {
227
+ // A missing page answers `{ notFound: true }`. Otherwise a deploy replaced the build id, and every
228
+ // data route of the old one answers 404: look the id up again, once.
229
+ if (json?.notFound || retried) throw new Error(`FlameComics: /${path} not found`);
230
+ if (this.buildIdRequest === buildIdRequest) this.buildIdRequest = undefined;
231
+ return this.nextData<T>(path, true);
232
+ }
233
+ if (!json?.pageProps) throw new Error(`FlameComics: no page data for /${path}`);
234
+ return json.pageProps as T;
235
+ }
236
+
237
+ /** The site's current Next.js build id, from the home page (looked up once, then reused). */
238
+ private buildId(): Promise<string> {
239
+ if (!this.buildIdRequest) {
240
+ this.buildIdRequest = this.ctx.axios
241
+ .get(`${this.baseUrl}/`)
242
+ .then(({ data }) => {
243
+ const buildId = /"buildId"\s*:\s*"([^"]+)"/.exec(String(data))?.[1];
244
+ if (!buildId) throw new Error('FlameComics: no Next.js build id on the home page');
245
+ return buildId;
246
+ })
247
+ .catch((err) => {
248
+ // Look it up again next time.
249
+ this.buildIdRequest = undefined;
250
+ throw err;
251
+ });
252
+ }
253
+ return this.buildIdRequest;
254
+ }
152
255
  }
@@ -1,29 +1,15 @@
1
1
  import { MangaDex } from './mangadex';
2
- import { ComicK } from './comick';
3
2
  import { MangaHere } from './mangahere';
4
3
  import { MangaKakalot } from './mangakakalot';
5
- import { Mangasee123 } from './mangasee123';
6
- import { Mangapark } from './mangapark';
7
4
  import { MangaPill } from './mangapill';
8
- import { MangaReader } from './mangareader';
9
5
  import { AsuraScans } from './asurascans';
10
6
  import { FlameScans } from './flamescans';
11
- import { MangaHost } from './mangahost';
12
- import { BRMangas } from './brmangas';
13
- import { VyvyManga } from './vyvymanga';
14
7
 
15
8
  export const MANGA = {
16
9
  MangaDex,
17
- ComicK,
18
10
  MangaHere,
19
11
  MangaKakalot,
20
- Mangasee123,
21
- Mangapark,
22
12
  MangaPill,
23
- MangaReader,
24
13
  AsuraScans,
25
14
  FlameScans,
26
- MangaHost,
27
- BRMangas,
28
- VyvyManga,
29
15
  };