-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathykmh.js
More file actions
883 lines (819 loc) · 36.5 KB
/
Copy pathykmh.js
File metadata and controls
883 lines (819 loc) · 36.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
/** @type {import('./_venera_.js')} */
class YKMHSource extends ComicSource {
name = "优酷漫画"
key = "ykmh"
version = "1.0.0"
minAppVersion = "1.4.0"
url = "https://cdn.jsdelivr.net/gh/venera-app/venera-configs@main/ykmh.js"
get baseUrl() {
return "https://www.ykmh.net";
}
explore = [
{
title: "优酷漫画",
type: "multiPartPage",
load: async (page) => {
let res = await Network.get("https://www.ykmh.net")
if (res.status !== 200) {
throw `Invalid status code: ${res.status}`
}
function parseHotCarousel(html) {
let hotComics = []
let carouselPattern = /<div class="sub-item">\s*<a href="([^"]+)" target="_blank"><img src="([^"]+)" alt="[^"]*"><\/a>\s*<div class="carousel-caption">\s*([^<]+)\s*<\/div>/g
let match
while ((match = carouselPattern.exec(html)) !== null) {
let cover = match[2]
if (!cover.startsWith('http')) {
cover = 'https://www.ykmh.net' + (cover.startsWith('/') ? cover : '/' + cover)
}
hotComics.push(new Comic({
id: match[1],
title: match[3].trim(),
cover: cover,
tags: [`热门推荐`],
description: "热门推荐漫画"
}))
}
if (hotComics.length === 0) {
let keywordPattern = /<li data-key="(\d+)"><a href="(https:\/\/www\.ykmh\.net\/manhua\/[^"]+)"[^>]*>([^<]+)<\/a><\/li>/g
while ((match = keywordPattern.exec(html)) !== null) {
hotComics.push(new Comic({
id: match[2],
title: match[3],
cover: "https://www.ykmh.net/images/default/cover.png",
tags: [`热门关键词`],
description: ""
}))
}
}
return hotComics.slice(0, 10)
}
function parseLatestComics(html) {
let latestComics = []
let comicPattern = /<li data-key="(\d+)"><a class="image-link" href="([^"]+)" title="([^"]+)"><img src="([^"]+)"[^>]*><span class="tip"><p>([^<]*)<\/p><\/span><\/a><p><a href="[^"]*" title="[^"]*">([^<]+)<\/a><\/p>/g
let match
while ((match = comicPattern.exec(html)) !== null) {
let cover = match[4]
if (!cover.startsWith('http')) {
cover = 'https://www.ykmh.net' + (cover.startsWith('/') ? cover : '/' + cover)
}
latestComics.push(new Comic({
id: match[2],
title: match[3],
cover: cover,
tags: [match[5]],
description: `更新至:${match[5]}`
}))
}
return latestComics.slice(0, 15)
}
let hotComics = parseHotCarousel(res.body)
let latestComics = parseLatestComics(res.body)
return [
{
title: "热门推荐",
comics: hotComics
},
{
title: "最新更新",
comics: latestComics
}
]
}
}
]
static category_param_dict = {
"全部": "",
"爱情": "aiqing",
"剧情": "juqing",
"欢乐向": "huanlexiang",
"格斗": "gedou",
"科幻": "kehuan",
"伪娘": "weiniang",
"节操": "jiecao",
"恐怖": "kongbu",
"悬疑": "xuanyi",
"冒险": "maoxian",
"校园": "xiaoyuan",
"治愈": "zhiyu",
"恋爱": "lianai",
"奇幻": "qihuan",
"热血": "rexue",
"限制级": "xianzhiji",
"魔法": "mofa",
"后宫": "hougong",
"魔幻": "mohuan",
"轻小说": "qingxiaoshuo",
"震撼": "zhenhan",
"纯爱": "chunai",
"少女": "shaonv",
"战争": "zhanzheng",
"武侠": "wuxia",
"搞笑": "gaoxiao",
"神鬼": "shengui",
"竞技": "jingji",
"幻想": "huanxiang",
"神魔": "shenmo",
"灵异": "lingyi",
"百合": "baihe",
"运动": "yundong",
"体育": "tiyu",
"惊悚": "jingsong",
"日常": "richang",
"绅士": "shenshi",
"颜艺": "yanyi",
"生活": "shenghuo",
"四格": "sige",
"萌系": "mengxi",
"都市": "dushi",
"同人": "tongren",
"推理": "tuili",
"耽美": "danmei",
"卖肉": "mairou",
"职场": "zhichang",
"侦探": "zhentan",
"战斗": "zhandou",
"爆笑": "baoxiao",
"总裁": "zongcai",
"美食": "meishi",
"性转换": "xingzhuanhuan",
"励志": "lizhi",
"西方魔幻": "xifangmohuan",
"改编": "gaibian",
"其他": "qita",
"宅系": "zhaixi",
"机战": "jizhan",
"乙女": "yinv",
"秀吉": "xiuji",
"舰娘": "jianniang",
"历史": "lishi",
"猎奇": "lieqi",
"社会": "shehui",
"青春": "qingchun",
"高清单行": "gaoqingdanxing",
"东方": "dongfang",
"橘味": "juwei",
"音乐舞蹈": "yinyuewudao",
"家庭": "jiating",
"ゆり": "unknown",
"彩虹": "caihong",
"少年": "shaonian",
"泡泡": "paopao",
"宫斗": "gongdou",
"动作": "dongzuo",
"青年": "qingnian",
"虐心": "nuexin",
"泛爱": "fanai",
"机甲": "jijia",
"装逼": "zhuangbi",
"#愛情": "aiqing2",
"#長條": "zhangtiao",
"#穿越": "chuanyue",
"#生活": "shenghuo2",
"TS": "TS",
"#耽美": "danmei2",
"#后宫": "hougong2",
"#节操": "jiecao2",
"#轻小说": "qingxiaoshuo2",
"#奇幻": "qihuan2",
"#悬疑": "xuanyi2",
"#校园": "xiaoyuan2",
"#爱情": "aiqing3",
"#百合": "baihe2",
"#长条": "changtiao",
"#冒险": "maoxian2",
"#搞笑": "gaoxiao2",
"#欢乐向": "huanlexiang2",
"#职场": "zhichang2",
"#神鬼": "shengui2",
"#生存": "shengcun",
"#治愈": "zhiyu2",
"#竞技": "jingji2",
"#美食": "meishi2",
"#其他": "qita2",
"#机战": "jizhan2",
"#战争": "zhanzheng2",
"#科幻": "kehuan2",
"#四格": "sige2",
"#武侠": "wuxia2",
"#重生": "zhongsheng",
"#性转换": "xingzhuanhuan2",
"#热血": "rexue2",
"#伪娘": "weiniang2",
"#异世界": "yishijie",
"#萌系": "mengxi2",
"#格斗": "gedou2",
"#励志": "lizhi2",
"#都市": "dushi2",
"#惊悚": "jingsong2",
"#侦探": "zhentan2",
"#舰娘": "jianniang2",
"#音乐舞蹈": "yinyuewudao2",
"#TL": "TL",
"#AA": "AA",
"#转生": "zhuansheng",
"#魔幻": "mohuan2",
"---": "unknown2",
"#彩色": "caise",
"福瑞": "furui",
"#FATE": "FATE",
"西幻": "xihuan",
"#C99": "C99",
"#C101": "C101",
"#历史": "lishi2",
"#C102": "C102",
"#无修正": "wuxiuzheng",
"#C103": "C103",
"#东方": "dongfang2",
"栏目": "lanmu",
"异世界": "yishijie2",
"恶搞": "egao",
"霸总": "bazong",
"古风": "gufeng",
"穿越": "chuanyue2",
"玄幻": "xuanhuan",
"日更": "rigeng",
"吸血": "xixie",
"萝莉": "luoli",
"漫改": "mangai",
"唯美": "weimei",
"宅男腐女": "zhainanfunv",
"老师": "laoshi",
"诱惑": "youhuo",
"杂志": "zazhi",
"脑洞": "naodong",
"其它": "qita3",
"#恐怖": "kongbu2",
"#C105": "C105",
"权谋": "quanmou",
"大陆": "dalu",
"日本": "riben",
"香港": "hongkong",
"台湾": "taiwan",
"欧美": "oumei",
"韩国": "hanguo",
"其它": "qita",
"儿童漫画": "ertong",
"少年漫画": "shaonian",
"少女漫画": "shaonv",
"青年漫画": "qingnian",
"已完结": "wanjie",
"连载中": "lianzai"
}
static comic_status = {
"连载中": "ongoing",
"已完结": "completed",
"暂停": "paused",
"完结": "completed",
"连载": "ongoing",
"休刊": "paused",
"未知状态": "unknown"
}
category = {
title: "优酷漫画",
parts: [
{
name: "主题",
type: "fixed",
categories: Object.keys(YKMHSource.category_param_dict),
itemType: "category",
categoryParams: Object.values(YKMHSource.category_param_dict),
}
],
enableRankingPage: false,
}
categoryComics = {
load: async (category, param, options, page) => {
let sort = "";
temp = options[1].split("-")[0]
if(temp==0){sort=""}else{sort="-"}
sort = sort + options[0].split("-")[0]
let url;
if (param === "" || param === undefined) {
url = `https://www.ykmh.net/list/${sort}/?page=${page}`;
} else {
url = `https://www.ykmh.net/list/${param}/${sort}/${page}/`;
}
let res = await Network.get(url);
if (res.status !== 200) {
throw `Invalid status code: ${res.status}`;
}
function parseComicsList(html) {
let comics = []
let comicPattern = /<li class="list-comic" data-key="(\d+)">\s*<a class="comic_img"\s+href="([^"]+)"><img src="([^"]+)" alt="([^"]*)"[^>]*><\/a>\s*<span class="comic_list_det"[^>]*>\s*<h3><a href="[^"]*">([^<]+)<\/a><\/h3>/g
let match
while ((match = comicPattern.exec(html)) !== null) {
let cover = match[3]
if (!cover.startsWith('http')) {
cover = 'https://www.ykmh.net' + (cover.startsWith('/') ? cover : '/' + cover)
}
comics.push(new Comic({
id: match[2],
title: match[5] || match[4],
cover: cover,
tags: [],
description: ""
}))
}
return comics
}
let comics = parseComicsList(res.body)
let maxPage = 1
let pagePattern = /<li class="last"><a href="[^"]*\/(\d+)\/" data-page="\d+">尾页<\/a><\/li>/
let pageMatch = res.body.match(pagePattern)
if (pageMatch) {
maxPage = parseInt(pageMatch[1])
} else {
let altPagePattern = /<li class="last"><a href="[^"]*" data-page="(\d+)">尾页<\/a><\/li>/
let altMatch = res.body.match(altPagePattern)
if (altMatch) {
maxPage = parseInt(altMatch[1]) + 1
}
}
return {
comics: comics,
maxPage: maxPage
};
},
optionList: [
{options:[
"update-更新时间",
"post-发布时间",
"click-点击量"
]},
{options:[
"0-降序",
"1-升序"
]},
]
}
/// search related
search = {
load: async (keyword, options, page) => {
let encodedKeyword = encodeURIComponent(keyword);
let url;
if (page && page > 1) {
url = `https://www.ykmh.net/search/?keywords=${encodedKeyword}&page=${page}`;
} else {
url = `https://www.ykmh.net/search/?keywords=${encodedKeyword}`;
}
let res = await Network.get(url);
if (res.status !== 200) {
throw `Request Error: ${res.status}`;
}
function parseSearchResults(html) {
let comics = []
let comicPattern = /<li class="list-comic" data-key="(\d+)"><a class="image-link"\s+href="([^"]+)"\s+title="([^"]+)"><img src="([^"]+)"[^>]*><\/a>\s*<p><a href="[^"]*"[^>]*>([^<]+)<\/a><\/p>\s*<p class="auth"><a href="[^"]*">([^<]*)<\/a><\/p>\s*<p class="newPage">([^<]*)<\/p>/g
let match
while ((match = comicPattern.exec(html)) !== null) {
let cover = match[4]
if (!cover.startsWith('http')) {
cover = 'https://www.ykmh.net' + (cover.startsWith('/') ? cover : '/' + cover)
}
comics.push(new Comic({
id: match[2],
title: match[3],
cover: cover,
tags: [match[6] || "未知作者", match[7] || ""],
description: `作者:${match[6] || "未知作者"} | 更新至:${match[7] || "未知"}`
}))
}
return comics
}
let comics = parseSearchResults(res.body)
let maxPage = 1
let pagePattern = /<li class="last"><a href="[^"]*page=(\d+)"[^>]*>尾页<\/a><\/li>/
let pageMatch = res.body.match(pagePattern)
if (pageMatch) {
maxPage = parseInt(pageMatch[1])
} else {
let altPagePattern = /<a href="[^"]*page=(\d+)"[^>]*>\s*(\d+)\s*<\/a>/g
let matches = [...res.body.matchAll(altPagePattern)]
if (matches.length > 0) {
maxPage = Math.max(...matches.map(m => parseInt(m[2])))
}
}
return {
comics: comics,
maxPage: maxPage
};
},
optionList: []
}
/// single comic related
comic = {
id: null,
buildId: null,
loadInfo: async (id) => {
if (!id || typeof id !== 'string') {
throw "ID不能为空";
}
let targetUrl = id;
if (id.startsWith('https://www.ykmh.net/')) {
targetUrl = id.replace('https://www.ykmh.net/', 'https://m.ykmh.net/');
}
else if (id.startsWith('/')) {
targetUrl = 'https://m.ykmh.net' + id;
}
else {
targetUrl = 'https://m.ykmh.net/' + id;
}
if (!targetUrl.endsWith('/')) {
targetUrl += '/';
}
let res = await Network.get(targetUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36 Edg/139.0.0.0'
}
});
if (res.status !== 200) {
throw `请求失败,状态码: ${res.status},URL: ${targetUrl}`;
}
function parseComicInfo(html) {
try {
if (!html || typeof html !== 'string') {
return {
title: "未知标题",
cover: "https://m.ykmh.net/images/default/cover.png",
author: "未知作者",
status: "未知状态",
tags: [],
description: "暂无描述"
};
}
let title = "未知标题";
try {
let titleMatch = html.match(/<div class="BarTit" id="comicName">([^<]+)<\/div>/);
if (titleMatch && titleMatch[1]) {
title = titleMatch[1].trim();
}
} catch (e) {
console.warn("解析标题失败:", e);
}
let cover = "https://m.ykmh.net/images/default/cover.png";
try {
let coverMatch = html.match(/<div class="pic" id="Cover">\s*<mip-img src="([^"]+)"/);
if (coverMatch && coverMatch[1]) {
cover = coverMatch[1];
} else {
let backupMatch = html.match(/<mip-img src="([^"]+)"/);
if (backupMatch && backupMatch[1]) {
cover = backupMatch[1];
}
}
} catch (e) {
console.warn("解析封面失败:", e);
}
let author = "未知作者";
try {
let authorMatch = html.match(/<p class="txtItme">\s*<span class="icon icon01"><\/span>\s*<a href="[^"]*">([^<]+)<\/a>\s*<\/p>/);
if (authorMatch && authorMatch[1]) {
author = authorMatch[1].trim();
} else {
let authorMatch2 = html.match(/<span class="icon icon01"><\/span>\s*<a href="[^"]*">([^<]+)<\/a>/);
if (authorMatch2 && authorMatch2[1]) {
author = authorMatch2[1].trim();
}
}
console.log("解析到作者:", author);
} catch (e) {
console.warn("解析作者失败:", e);
}
let status = "未知状态";
let tags = [];
try {
let txtItems = html.match(/<p class="txtItme">[\s\S]*?<\/p>/g);
if (txtItems) {
console.log("找到txtItme元素数量:", txtItems.length);
for (let item of txtItems) {
if (item.includes('icon icon02')) {
let tagMatches = item.matchAll(/<a href="[^"]*\/list\/[^"]*\/">([^<]+)<\/a>/g);
if (tagMatches) {
for (let tagMatch of tagMatches) {
if (tagMatch && tagMatch[1]) {
let tagText = tagMatch[1].trim();
if (tagText && !tags.includes(tagText)) {
tags.push(tagText);
if (tagText === '连载中' || tagText === '已完结' || tagText === '完结' ||
tagText === '连载' || tagText === '暂停' || tagText === '休刊') {
status = tagText;
console.log("找到状态标签:", tagText);
}
}
}
}
}
}
}
}
console.log("解析到状态:", status, "标签:", tags);
} catch (e) {
console.warn("解析标签失败:", e);
tags = [];
}
let description = "暂无描述";
try {
let descMatch = html.match(/<mip-showmore[^>]*id="showmore-des">\s*([^<]+(?:<[^>]+>[^<]*<\/[^>]+>[^<]*)*?)\s*<\/mip-showmore>/);
if (descMatch && descMatch[1]) {
description = descMatch[1].replace(/<[^>]+>/g, '').replace(/^\s*介绍:\s*/, '').trim();
}
} catch (e) {
console.warn("解析描述失败:", e);
}
return {
title: title || "未知标题",
cover: cover || "https://m.ykmh.net/images/default/cover.png",
author: author || "未知作者",
status: status || "未知状态",
tags: tags || [],
description: description || "暂无描述"
};
} catch (error) {
console.error("parseComicInfo 总体错误:", error);
return {
title: "未知标题",
cover: "https://m.ykmh.net/images/default/cover.png",
author: "未知作者",
status: "未知状态",
tags: [],
description: "暂无描述"
};
}
}
function parseChapters(html) {
let allChaptersMap = new Map();
let groupedChapters = new Map();
try {
if (!html || typeof html !== 'string') {
return allChaptersMap;
}
let chapterGroupsPattern = /<div class="comic-chapters">[\s\S]*?<span class="Title">([^<]+)<\/span>[\s\S]*?<ul id="chapter-list-(\d+)"[^>]*>([\s\S]*?)<\/ul>/g;
let groupMatch;
while ((groupMatch = chapterGroupsPattern.exec(html)) !== null) {
try {
if (groupMatch && groupMatch[1] && groupMatch[3]) {
let groupTitle = groupMatch[1].trim();
let groupContent = groupMatch[3];
let groupChapters = new Map();
let chapterPattern = /<li>\s*<a href="([^"]+)"[^>]*>\s*<span>([^<]+)<\/span>\s*<\/a>\s*<\/li>/g;
let chapterMatch;
while ((chapterMatch = chapterPattern.exec(groupContent)) !== null) {
try {
if (chapterMatch && chapterMatch[1] && chapterMatch[2]) {
let chapterUrl = chapterMatch[1];
let chapterTitle = chapterMatch[2].trim();
if (!chapterUrl.startsWith('http')) {
chapterUrl = 'https://m.ykmh.net' + (chapterUrl.startsWith('/') ? chapterUrl : '/' + chapterUrl);
}
groupChapters.set(chapterUrl, chapterTitle);
let finalChapterTitle = chapterTitle;
if (groupTitle !== "连载列表") {
finalChapterTitle = `[${groupTitle}] ${chapterTitle}`;
}
allChaptersMap.set(chapterUrl, finalChapterTitle);
}
} catch (e) {
console.warn("解析单个章节失败:", e);
continue;
}
}
if (groupChapters.size > 0) {
groupedChapters.set(groupTitle, groupChapters);
}
}
} catch (e) {
console.warn("解析章节组别失败:", e);
continue;
}
}
if (allChaptersMap.size === 0) {
console.warn("使用备用章节解析方法");
let allChapterPattern = /<li>\s*<a href="([^"]+)"[^>]*>\s*<span>([^<]+)<\/span>\s*<\/a>\s*<\/li>/g;
let match;
while ((match = allChapterPattern.exec(html)) !== null) {
try {
if (match && match[1] && match[2]) {
let chapterUrl = match[1];
let chapterTitle = match[2].trim();
if (!chapterUrl.startsWith('http')) {
chapterUrl = 'https://m.ykmh.net' + (chapterUrl.startsWith('/') ? chapterUrl : '/' + chapterUrl);
}
allChaptersMap.set(chapterUrl, chapterTitle);
}
} catch (e) {
console.warn("解析单个章节失败:", e);
continue;
}
}
}
if (groupedChapters.size > 1) {
console.log("使用多分组模式");
return groupedChapters;
}
console.log("使用合并模式");
return allChaptersMap;
} catch (error) {
console.error("parseChapters 总体错误:", error);
}
return allChaptersMap;
}
function parseRecommends(html) {
let recommends = [];
try {
if (!html || typeof html !== 'string') {
return recommends;
}
let recommendPattern = /<li class="list-comic" data-key="[^"]*">\s*<a class="ImgA" href="([^"]+)"><mip-img src="([^"]+)"[^>]*alt="([^"]*)"[^>]*><\/mip-img><\/a>\s*<a class="txtA" href="[^"]+">([^<]+)<\/a>/g;
let match;
let count = 0;
while ((match = recommendPattern.exec(html)) !== null && count < 10) {
try {
if (match && match[1] && match[2]) {
let recUrl = match[1];
let recCover = match[2];
let recTitle = (match[4] && match[4].trim()) || (match[3] && match[3].trim()) || "未知标题";
recommends.push(new Comic({
id: recUrl,
title: recTitle,
cover: recCover
}));
count++;
}
} catch (e) {
console.warn("解析单个推荐漫画失败:", e);
continue;
}
}
} catch (error) {
console.error("parseRecommends 总体错误:", error);
}
return recommends;
}
try {
this.comic.id = id;
if (!res.body || typeof res.body !== 'string') {
throw "响应内容为空或格式错误";
}
let comicInfo = parseComicInfo(res.body);
let chapters = parseChapters(res.body);
let recommends = parseRecommends(res.body);
comicInfo = comicInfo || {};
if (!comicInfo.title) comicInfo.title = "未知标题";
if (!comicInfo.author) comicInfo.author = "未知作者";
if (!comicInfo.status) comicInfo.status = "未知状态";
if (!comicInfo.description) comicInfo.description = "暂无描述";
if (!comicInfo.cover) comicInfo.cover = "https://m.ykmh.net/images/default/cover.png";
if (!comicInfo.tags || !Array.isArray(comicInfo.tags)) comicInfo.tags = [];
let updateInfo = "暂无更新";
try {
if (chapters && chapters.size > 0) {
let latestChapter = null;
let firstValue = Array.from(chapters.values())[0];
if (firstValue instanceof Map) {
for (let groupChapters of chapters.values()) {
if (groupChapters.size > 0) {
latestChapter = Array.from(groupChapters.values())[0];
break;
}
}
} else {
latestChapter = firstValue;
}
if (latestChapter) {
updateInfo = `更新至:${latestChapter}`;
}
}
} catch (e) {
console.warn("获取更新信息失败:", e);
}
let mappedStatus = comicInfo.status;
try {
if (YKMHSource.comic_status && comicInfo.status) {
mappedStatus = YKMHSource.comic_status[comicInfo.status];
if (!mappedStatus) {
if (comicInfo.status.includes('连载')) {
mappedStatus = "ongoing";
} else if (comicInfo.status.includes('完结')) {
mappedStatus = "completed";
} else if (comicInfo.status.includes('暂停') || comicInfo.status.includes('休刊')) {
mappedStatus = "paused";
} else {
mappedStatus = comicInfo.status; // 保持原状态
}
}
}
} catch (e) {
console.warn("状态映射失败:", e);
mappedStatus = comicInfo.status;
}
return {
title: comicInfo.title,
cover: comicInfo.cover,
description: comicInfo.description,
tags: {
"作者": [comicInfo.author],
"状态": [mappedStatus],
"更新": [updateInfo],
"标签": comicInfo.tags
},
chapters: chapters || new Map(),
recommend: recommends || []
};
} catch (error) {
console.error("loadInfo详细错误:", error);
throw `解析漫画信息失败: ${error.message || error}`;
}
},
loadEp: async (comicId, epId) => {
if (!comicId || typeof comicId !== 'string') {
throw "漫画ID不能为空";
}
if (!epId || typeof epId !== 'string') {
throw "章节ID不能为空";
}
let chapterUrl = epId;
if (!chapterUrl.startsWith('http')) {
chapterUrl = 'https://m.ykmh.net' + (chapterUrl.startsWith('/') ? chapterUrl : '/' + chapterUrl);
} else if (chapterUrl.startsWith('https://www.ykmh.net/')) {
chapterUrl = chapterUrl.replace('https://www.ykmh.net/', 'https://m.ykmh.net/');
}
let res = await Network.get(chapterUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1'
}
});
if (res.status !== 200) {
throw `请求章节失败,状态码: ${res.status}`;
}
function parseChapterImages(html) {
let images = [];
let scriptMatch = html.match(/var\s+chapterImages\s*=\s*(\[.*?\]);/);
if (scriptMatch) {
try {
let imageList = JSON.parse(scriptMatch[1]);
images = imageList.map(img => {
if (!img.startsWith('http')) {
return 'https://m.ykmh.net' + (img.startsWith('/') ? img : '/' + img);
}
return img;
});
} catch (e) {
}
}
if (images.length === 0) {
let imgPattern = /<img[^>]+src="([^"]+)"[^>]*>/g;
let match;
while ((match = imgPattern.exec(html)) !== null) {
let imgSrc = match[1];
if (imgSrc.includes('cover') || imgSrc.includes('avatar') ||
imgSrc.includes('logo') || imgSrc.includes('icon') ||
imgSrc.includes('banner')) {
continue;
}
if (!imgSrc.startsWith('http')) {
imgSrc = 'https://m.ykmh.net' + (imgSrc.startsWith('/') ? imgSrc : '/' + imgSrc);
}
images.push(imgSrc);
}
}
if (images.length === 0) {
let containerPattern = /<div[^>]*class="[^"]*chapter[^"]*"[^>]*>(.*?)<\/div>/gs;
let containerMatch = html.match(containerPattern);
if (containerMatch) {
let containerHtml = containerMatch[1];
let imgPattern = /<img[^>]+src="([^"]+)"/g;
let match;
while ((match = imgPattern.exec(containerHtml)) !== null) {
let imgSrc = match[1];
if (!imgSrc.startsWith('http')) {
imgSrc = 'https://m.ykmh.net' + (imgSrc.startsWith('/') ? imgSrc : '/' + imgSrc);
}
images.push(imgSrc);
}
}
}
return images;
}
try {
let images = parseChapterImages(res.body);
if (images.length === 0) {
console.warn("未找到章节图片,可能需要进一步的页面解析");
}
return { images: images || [] };
} catch (error) {
throw `解析章节图片失败: ${error.message || error}`;
}
},
onClickTag: (namespace, tag) => {
if (namespace === "标签") {
let r_tag = YKMHSource.category_param_dict[tag];
return {
action: 'category',
keyword: `${tag}`,
param: `${r_tag}`,
}
}
throw "未支持此类Tag检索"
}
}
}