@@ -70,7 +70,39 @@ export class CatMangaParser {
70
70
return [ ] ;
71
71
}
72
72
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 ) {
74
106
const chapters : Chapter [ ] = [ ] ;
75
107
$ ( 'a[class^="chaptertile_element"]' ) . map ( ( index , element ) => {
76
108
const chapNumString = $ ( "p" , element ) . first ( ) . text ( ) . replace ( "Chapter " , "" )
@@ -91,7 +123,63 @@ export class CatMangaParser {
91
123
return chapters
92
124
}
93
125
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 ) {
95
183
const tags : Tag [ ] = [ ] ;
96
184
$ ( 'div[class^="series_tags"] p' ) . map ( ( index , element ) => {
97
185
const text = $ ( element ) . text ( ) . trim ( ) ;
0 commit comments