Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Commit 9da0bdd

Browse files
committed
Better parsing
1 parent 2eadad8 commit 9da0bdd

File tree

2 files changed

+91
-3
lines changed

2 files changed

+91
-3
lines changed

‎src/CatManga/CatManga.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const BASE = "https://catmanga.org"
1515

1616
export const CatMangaInfo: SourceInfo = {
1717
icon: "icon.png",
18-
version: "1.0.2",
18+
version: "1.1.0",
1919
name: "CatManga",
2020
author: "PythonCoderAS",
2121
authorWebsite: "https://github.com/PythonCoderAS",

‎src/CatManga/CatMangaParser.ts

+90-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,39 @@ export class CatMangaParser {
7070
return [];
7171
}
7272

73-
parseChapterList($: CheerioStatic, mangaId: string) {
73+
parseChapterList($: CheerioStatic, mangaId: string){
74+
const chapters = []
75+
const json = JSON.parse($("script#__NEXT_DATA__").html() || "{}");
76+
if (json){
77+
const props = json.props;
78+
if (props){
79+
const pageProps = props.pageProps;
80+
if (pageProps){
81+
const series = pageProps.series;
82+
if (series && series.chapters && (series.chapters.length || 0) > 0){
83+
for (let i = 0; i < series.chapters.length; i++) {
84+
const chapter = series.chapters[i];
85+
if (chapter.number){
86+
chapters.push(createChapter({
87+
chapNum: chapter.number,
88+
id: String(chapter.number),
89+
langCode: LanguageCode.ENGLISH,
90+
mangaId: mangaId,
91+
name: chapter.title,
92+
group: (chapter.groups || []).join(", ")
93+
}))}
94+
}
95+
if (chapters.length > 0){
96+
return chapters;
97+
}
98+
}
99+
}
100+
}
101+
}
102+
return this.parseChapterListFallback($, mangaId);
103+
}
104+
105+
parseChapterListFallback($: CheerioStatic, mangaId: string) {
74106
const chapters: Chapter[] = [];
75107
$('a[class^="chaptertile_element"]').map((index, element) => {
76108
const chapNumString = $("p", element).first().text().replace("Chapter ", "")
@@ -91,7 +123,63 @@ export class CatMangaParser {
91123
return chapters
92124
}
93125

94-
parseManga($: CheerioStatic, mangaId: string) {
126+
parseManga($: CheerioStatic, mangaId: string){
127+
const json = JSON.parse($("script#__NEXT_DATA__").html() || "{}");
128+
if (json){
129+
const props = json.props;
130+
if (props){
131+
const pageProps = props.pageProps;
132+
if (pageProps){
133+
const series = pageProps.series;
134+
if (series && series.genres && (series.genres.length || 0) > 0 && series.title && series.decription && series.status && series.cover_art && series.conver_art.source){
135+
let titles = [series.title]
136+
const covers = [];
137+
const tags = []
138+
if (series.alt_titles){
139+
titles = titles.concat(series.alt_titles)
140+
}
141+
if (series.all_covers){
142+
for (let i = 0; i < series.all_covers.length; i++) {
143+
const cover = series.all_covers[i];
144+
covers.push(`https://images.catmanga.org${cover.source || ""}`)
145+
}
146+
}
147+
let status;
148+
if ((series.status || "").toLowerCase().includes("ongoing")){
149+
status = MangaStatus.ONGOING;
150+
} else {
151+
status = MangaStatus.COMPLETED;
152+
}
153+
for (let i = 0; i < series.genres.length; i++) {
154+
const tag = series.genres[i];
155+
tags.push(createTag({
156+
id: tag,
157+
label: tag
158+
}))
159+
}
160+
return createManga({
161+
author: (series.authors || []).join(", "),
162+
covers: covers,
163+
desc: series.description,
164+
id: mangaId,
165+
image: series.cover_art.source,
166+
rating: 0,
167+
status: status,
168+
tags: [createTagSection({
169+
id: "genres",
170+
label: "Genres",
171+
tags: tags
172+
})],
173+
titles: titles
174+
})
175+
}
176+
}
177+
}
178+
}
179+
return this.parseMangaFallback($, mangaId);
180+
}
181+
182+
parseMangaFallback($: CheerioStatic, mangaId: string) {
95183
const tags: Tag[] = [];
96184
$('div[class^="series_tags"] p').map((index, element) => {
97185
const text = $(element).text().trim();

0 commit comments

Comments
 (0)