Fix: non-english broken plugins (#701)

* fix epiknovel

* fix: hasutl

* fix: Novelas Ligera

* fix: ReinoWuxia

* fix: Oasis

* fix: json script

* fix: Skynovels

* fix: Yuuki Tls

* fix: Agitoon

* fix: Syosetu

* fix: IndoWebNovel

* fix: Novel Ringan

* fix: Sakura Novel

* fix: Hako

* minor: type checking when PRing
This commit is contained in:
nyagami
2024-01-20 21:20:28 +07:00
committed by GitHub
parent ba718784a5
commit 65ae9ba112
45 changed files with 5606 additions and 1998 deletions
+57 -46
View File
@@ -1,7 +1,8 @@
import { CheerioAPI, load as parseHTML } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { fetchFile } from "@libs/fetch";
import { Plugin } from "@typings/plugin";
import { isUrlAbsolute } from "@libs/isAbsoluteUrl";
import { NovelStatus } from "@libs/novelStatus";
class HakoPlugin implements Plugin.PluginBase {
id: string;
name: string;
@@ -9,18 +10,16 @@ class HakoPlugin implements Plugin.PluginBase {
site: string;
version: string;
constructor() {
this.id = "ln.hako";
this.name = "Hako";
this.icon = "src/vi/hakolightnovel/icon.png";
this.site = "https://ln.hako.vn";
this.version = "1.0.0";
}
parseNovels(loadedCheerio: CheerioAPI) {
const novels: Plugin.NovelItem[] = [];
loadedCheerio(".row > .thumb-item-flow").each((index, ele) => {
loadedCheerio("#mainpart .row .thumb-item-flow").each((index, ele) => {
let url = loadedCheerio(ele)
.find("div.thumb_attr.series-title > a")
.attr("href");
@@ -71,7 +70,7 @@ class HakoPlugin implements Plugin.PluginBase {
let loadedCheerio = parseHTML(body);
novel.name = loadedCheerio(".series-name").text();
novel.name = loadedCheerio(".series-name").text().trim();
const background =
loadedCheerio(".series-cover > .a6-ratio > div").attr("style") ||
@@ -89,52 +88,64 @@ class HakoPlugin implements Plugin.PluginBase {
novel.summary = loadedCheerio(".summary-content").text().trim();
novel.author = loadedCheerio(
"#mainpart > div:nth-child(2) > div > div:nth-child(1) > section > main > div.top-part > div > div.col-12.col-md-9 > div.series-information > div:nth-child(2) > span.info-value > a"
)
.text()
.trim();
novel.genres = loadedCheerio(".series-gernes")
novel.genres = loadedCheerio(".series-information > div:nth-child(1)")
.text()
.trim()
.replace(/ +/g, " ")
.split("\n")
.filter((e) => e.trim())
.join(", ");
novel.status = loadedCheerio(
"#mainpart > div:nth-child(2) > div > div:nth-child(1) > section > main > div.top-part > div > div.col-12.col-md-9 > div.series-information > div:nth-child(4) > span.info-value > a"
)
.split(/\n[\s\n]*/).join(',');
novel.author = loadedCheerio('.series-information > div:nth-child(2) > .info-value')
.text()
.trim();
novel.artist = loadedCheerio('.series-information > div:nth-child(3) > .info-value')
.text()
.trim();
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio(".list-chapters li").each((index, ele) => {
let chapterUrl = loadedCheerio(ele).find("a").attr("href");
novel.status = loadedCheerio('.series-information > div:nth-child(4) > .info-value')
.text()
.trim();
switch (novel.status) {
case 'Đang tiến hành':
novel.status = NovelStatus.Ongoing;
break;
case 'Tạm ngưng':
novel.status = NovelStatus.OnHiatus;
break;
case 'Completed':
novel.status = NovelStatus.Completed;
break;
default:
novel.status = NovelStatus.Unknown;
}
if (chapterUrl && !isUrlAbsolute(chapterUrl)) {
chapterUrl = this.site + chapterUrl;
let num = 0, part = 1;
const chapters: Plugin.ChapterItem[] = loadedCheerio('.list-chapters li').toArray().map((ele) => {
let chapterUrl = this.site + loadedCheerio(ele).find("a").attr("href");
const chapterName = loadedCheerio(ele)
.find(".chapter-name")
.text()
.trim();
let chapterNumber = Number(chapterName.match(/Chương\s*(\d+)/i)?.[1]);
if(chapterNumber){
num = chapterNumber;
part = 1;
}else{
chapterNumber = num + part / 10;
part ++;
}
const chapterTime = loadedCheerio(ele)
.find(".chapter-time")
.text()
.split('/')
.map(x => Number(x));
return {
url: chapterUrl || '',
name: chapterName,
releaseTime: new Date(chapterTime[2], chapterTime[1], chapterTime[0]).toISOString(),
chapterNumber: chapterNumber,
};
}).filter(c => c.url);
if (chapterUrl) {
const chapterName = loadedCheerio(ele)
.find(".chapter-name")
.text()
.trim();
const releaseTime = loadedCheerio(ele)
.find(".chapter-time")
.text();
const chapter = {
name: chapterName,
releaseTime: releaseTime,
url: chapterUrl,
};
chapters.push(chapter);
}
});
novel.chapters = chapters;
return novel;
}
@@ -150,11 +161,11 @@ class HakoPlugin implements Plugin.PluginBase {
}
async searchNovels(
searchTerm: string,
pageNo?: number | undefined
pageNo: number
): Promise<Plugin.NovelItem[]> {
const url = this.site + "/tim-kiem?keywords=" + searchTerm;
const url = this.site + "/tim-kiem?keywords=" + searchTerm + '&page=' + pageNo;
const result = await fetch(url);
const body = await result.text();
const body = await result.text();
const loadedCheerio = parseHTML(body);
return this.parseNovels(loadedCheerio);
}