Vietnamese plugins (#716)
* add Hako filters * add truyenfull * add lightnovelvn as broken (pagination) * add truyenconect as broken
This commit is contained in:
@@ -3,20 +3,14 @@ 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;
|
||||
icon: string;
|
||||
site: string;
|
||||
version: string;
|
||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
||||
|
||||
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";
|
||||
}
|
||||
class HakoPlugin implements Plugin.PluginBase {
|
||||
id = "ln.hako";
|
||||
name = "Hako";
|
||||
icon = "src/vi/hakolightnovel/icon.png";
|
||||
site = "https://ln.hako.vn";
|
||||
version = "1.0.1";
|
||||
parseNovels(loadedCheerio: CheerioAPI) {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
loadedCheerio("#mainpart .row .thumb-item-flow").each((index, ele) => {
|
||||
@@ -50,12 +44,21 @@ class HakoPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
options: Plugin.PopularNovelsOptions
|
||||
{showLatestNovels, filters}: Plugin.PopularNovelsOptions<typeof this.filters>
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const link =
|
||||
this.site +
|
||||
"/danh-sach?truyendich=1&sapxep=topthang&page=" +
|
||||
pageNo;
|
||||
let link = this.site + "/danh-sach"
|
||||
if(filters.alphabet.value){
|
||||
link += "/" + filters.alphabet.value;
|
||||
}
|
||||
const params = new URLSearchParams();
|
||||
for(const novelType of filters.type.value){
|
||||
params.append(novelType, "1");
|
||||
}
|
||||
for(const status of filters.status.value){
|
||||
params.append(status, "1");
|
||||
}
|
||||
params.append("sapxep", filters.sort.value);
|
||||
link += '?' + params.toString() + '&page=' + pageNo
|
||||
const result = await fetch(link);
|
||||
const body = await result.text();
|
||||
const loadedCheerio = parseHTML(body);
|
||||
@@ -175,6 +178,78 @@ class HakoPlugin implements Plugin.PluginBase {
|
||||
};
|
||||
return await fetchFile(url, { headers: headers });
|
||||
}
|
||||
filters = {
|
||||
alphabet: {
|
||||
type: FilterTypes.Picker,
|
||||
value: "",
|
||||
label: "Chữ cái",
|
||||
options: [
|
||||
{label: 'Tất cả', value: ''},
|
||||
{label: 'Khác', value: 'khac'},
|
||||
{label: 'A', value: 'a'},
|
||||
{label: 'B', value: 'b'},
|
||||
{label: 'C', value: 'c'},
|
||||
{label: 'D', value: 'd'},
|
||||
{label: 'E', value: 'e'},
|
||||
{label: 'F', value: 'f'},
|
||||
{label: 'G', value: 'g'},
|
||||
{label: 'H', value: 'h'},
|
||||
{label: 'I', value: 'i'},
|
||||
{label: 'J', value: 'j'},
|
||||
{label: 'K', value: 'k'},
|
||||
{label: 'L', value: 'l'},
|
||||
{label: 'M', value: 'm'},
|
||||
{label: 'N', value: 'n'},
|
||||
{label: 'O', value: 'o'},
|
||||
{label: 'P', value: 'p'},
|
||||
{label: 'Q', value: 'q'},
|
||||
{label: 'R', value: 'r'},
|
||||
{label: 'S', value: 's'},
|
||||
{label: 'T', value: 't'},
|
||||
{label: 'U', value: 'u'},
|
||||
{label: 'V', value: 'v'},
|
||||
{label: 'W', value: 'w'},
|
||||
{label: 'X', value: 'x'},
|
||||
{label: 'Y', value: 'y'},
|
||||
{label: 'Z', value: 'z'},
|
||||
]
|
||||
},
|
||||
type: {
|
||||
type: FilterTypes.CheckboxGroup,
|
||||
label: "Phân loại",
|
||||
value: [],
|
||||
options: [
|
||||
{label: "Truyện dịch", value: "truyendich"},
|
||||
{label: "Truyện sáng tác", value: "sangtac"},
|
||||
{label: "Convert", value: "convert"}
|
||||
]
|
||||
},
|
||||
status: {
|
||||
type: FilterTypes.CheckboxGroup,
|
||||
label: "Tình trạng",
|
||||
value: [],
|
||||
options: [
|
||||
{label: "Đang tiến hành", value: "dangtienhanh"},
|
||||
{label: "Tạm ngưng", value: "tamngung"},
|
||||
{label: "Đã hoàn thành", value: "hoanthanh"}
|
||||
]
|
||||
},
|
||||
sort: {
|
||||
type: FilterTypes.Picker,
|
||||
label: "Sắp xếp",
|
||||
value: "top",
|
||||
options: [
|
||||
{label: "A-Z", value: "tentruyen"},
|
||||
{label: "Z-A", value: "tentruyenza"},
|
||||
{label: "Mới cập nhật", value: "capnhat"},
|
||||
{label: "Truyện mới", value: "truyenmoi"},
|
||||
{label: "Theo dõi", value: "theodoi"},
|
||||
{label: "Top toàn thời gian", value: "top"},
|
||||
{label: "Top tháng", value: "topthang"},
|
||||
{label: "Số từ", value: "sotu"},
|
||||
]
|
||||
}
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new HakoPlugin();
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
||||
|
||||
class TruyenConect implements Plugin.PluginBase {
|
||||
id = "truyenconect";
|
||||
name = "Truyen Conect";
|
||||
icon = "src/vi/truyenconect/icon.png";
|
||||
site = "https://truyenconect.com";
|
||||
version = "1.0.0";
|
||||
parseNovels(loadedCheerio: CheerioAPI, selector: string){
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
loadedCheerio(selector).each(function () {
|
||||
const url = loadedCheerio(this).find('a').attr('href');
|
||||
if(url){
|
||||
novels.push({
|
||||
name: loadedCheerio(this).find('img').attr('alt') || '',
|
||||
url,
|
||||
cover: loadedCheerio(this).find('img').attr('data-src'),
|
||||
})
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
async popularNovels(pageNo: number, {filters, showLatestNovels}: Plugin.PopularNovelsOptions<typeof this.filters>): Promise<Plugin.NovelItem[]> {
|
||||
let link = this.site;
|
||||
let selector = '.c-page__content > .grid9.block .item-thumb.c-image-hover';
|
||||
|
||||
if(showLatestNovels){
|
||||
selector = '.c-page__content .page-content-listing.item-big_thumbnail .item-thumb.c-image-hover';
|
||||
}
|
||||
|
||||
if(filters.category.value){
|
||||
link += '/' + filters.category.value;
|
||||
selector = 'table.manga-shortcodes.manga-chapters-listing td[width="10%"]';
|
||||
if(filters.category.value === 'the-loai'){
|
||||
selector = '.item-thumb.hover-details.c-image-hover'
|
||||
link += '/' + filters.genre.value;
|
||||
}
|
||||
link += '?page=' + pageNo;
|
||||
}
|
||||
|
||||
const body = await fetch(link).then(r => r.text());
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio, selector);
|
||||
}
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio(".post-title > h1").text().trim();
|
||||
|
||||
novel.cover = loadedCheerio(".summary_image > a > img").attr(
|
||||
"data-src"
|
||||
);
|
||||
|
||||
loadedCheerio(".post-content_item").each(function () {
|
||||
const detailName = loadedCheerio(this)
|
||||
.find(".summary-heading > h5")
|
||||
.text()
|
||||
.trim();
|
||||
const detail = loadedCheerio(this).find(".summary-content").html();
|
||||
|
||||
if (!detail) return;
|
||||
|
||||
switch (detailName) {
|
||||
case "Genre":
|
||||
novel.genres = loadedCheerio(detail)
|
||||
.children("a")
|
||||
.map((i, el) => loadedCheerio(el).text())
|
||||
.toArray()
|
||||
.join(",");
|
||||
break;
|
||||
case "Author":
|
||||
novel.author = loadedCheerio(detail)
|
||||
.children("a")
|
||||
.map((i, el) => loadedCheerio(el).text())
|
||||
.toArray()
|
||||
.join(", ");
|
||||
break;
|
||||
case "Novel":
|
||||
novel.status = detail?.trim().replace(/G/g, "g");
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
loadedCheerio(
|
||||
".description-summary > div.summary__content > div"
|
||||
).remove();
|
||||
|
||||
novel.summary = loadedCheerio(
|
||||
".description-summary > div.summary__content"
|
||||
)
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
let chapter: Plugin.ChapterItem[] = [];
|
||||
loadedCheerio(".wp-manga-chapter").each(function () {
|
||||
const chapterName = loadedCheerio(this)
|
||||
.find("a")
|
||||
.text()
|
||||
.replace(/[\t\n]/g, "")
|
||||
.trim();
|
||||
const releaseDate = loadedCheerio(this).find("span").text().trim();
|
||||
const chapterUrl = loadedCheerio(this).find("a").attr("href");
|
||||
|
||||
if (!chapterUrl) return;
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = chapter.reverse();
|
||||
|
||||
return novel;
|
||||
}
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const result = await fetchApi(chapterUrl);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
loadedCheerio("img").removeAttr("srcset");
|
||||
let chapterText = loadedCheerio(".reading-content").html() || '';
|
||||
|
||||
return chapterText;
|
||||
}
|
||||
async searchNovels(searchTerm: string, pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}?s=${searchTerm}&post_type=wp-manga`;
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio(".c-tabs-item__content").each(function () {
|
||||
const novelName = loadedCheerio(this).find(".h4 > a").text();
|
||||
const novelCover = loadedCheerio(this).find("img").attr("data-src");
|
||||
const novelUrl = loadedCheerio(this).find(".h4 > a").attr("href");
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
novels.push({
|
||||
name: novelName,
|
||||
url: novelUrl,
|
||||
cover: novelCover,
|
||||
});
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return fetchFile(url);
|
||||
}
|
||||
filters = {
|
||||
category: {
|
||||
label: "Lọc theo",
|
||||
value: '',
|
||||
type: FilterTypes.Picker,
|
||||
options: [
|
||||
{label: '', value: ''},
|
||||
{label: 'Thể loại', value: 'the-loai'},
|
||||
{label: 'Truyện dịch', value: 'truyen-dich'},
|
||||
{label: 'Truyện convert', value: 'convert'}
|
||||
]
|
||||
},
|
||||
genre: {
|
||||
label: 'Thể loại',
|
||||
value: 'action',
|
||||
type: FilterTypes.Picker,
|
||||
options: [
|
||||
{label: 'Action', value: 'action'},
|
||||
{label: 'Adult', value: 'adult'},
|
||||
{label: 'Adventure', value: 'adventure'},
|
||||
{label: 'Chinese novel', value: 'chinese-novel'},
|
||||
{label: 'Chuyển Sinh', value: 'chuyen-sinh'},
|
||||
{label: 'English Novel', value: 'english-novel'},
|
||||
{label: 'Harem', value: 'harem'},
|
||||
{label: 'Ecchi', value: 'ecchi'},
|
||||
{label: 'Fantasy', value: 'fantasy'},
|
||||
{label: 'Drama', value: 'drama'},
|
||||
{label: 'Game', value: 'game'},
|
||||
{label: 'Tiên hiệp', value: 'tien-hiep'},
|
||||
{label: 'Kiếm Hiệp', value: 'kiem-hiep'},
|
||||
{label: 'Ngôn Tình', value: 'ngon-tinh'},
|
||||
{label: 'Isekai', value: 'isekai'},
|
||||
{label: 'Lịch Sử', value: 'lich-su'},
|
||||
{label: 'Web Novel', value: 'web-novel'},
|
||||
{label: 'Xuyên không', value: 'xuyen-khong'},
|
||||
{label: 'Trọng sinh', value: 'trong-sinh'},
|
||||
{label: 'Trinh thám', value: 'trinh-tham'},
|
||||
{label: 'Dị giới', value: 'di-gioi'},
|
||||
{label: 'Huyền ảo', value: 'huyen-ao'},
|
||||
{label: 'Sắc Hiệp', value: 'sac-hiep'},
|
||||
{label: 'Dị năng', value: 'di-nang'},
|
||||
{label: 'Linh dị', value: 'linh-di'},
|
||||
{label: 'Đô thị', value: 'do-thi'},
|
||||
{label: 'Comedy', value: 'comedy'},
|
||||
{label: 'School Life', value: 'school-life'},
|
||||
{label: 'Romance', value: 'romance'},
|
||||
{label: 'Martial-arts', value: 'martial-arts'},
|
||||
{label: 'Light Novel', value: 'light-novel'},
|
||||
{label: 'Huyền huyễn', value: 'huyen-huyen'},
|
||||
{label: 'Kỳ Huyễn', value: 'ky-huyen'},
|
||||
{label: 'Khoa Huyễn', value: 'khoa-huyen'},
|
||||
{label: 'Võng Du', value: 'vong-du'},
|
||||
{label: 'Đồng Nhân', value: 'dong-nhan'},
|
||||
|
||||
]
|
||||
}
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new TruyenConect();
|
||||
@@ -0,0 +1,164 @@
|
||||
import { load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { Filters } from "@libs/filterInputs";
|
||||
import { NovelStatus } from "@libs/novelStatus";
|
||||
|
||||
|
||||
class LightNovelVN implements Plugin.PluginBase {
|
||||
id = "lightnovel.vn";
|
||||
name = "Light Novel VN";
|
||||
version = "1.0.0";
|
||||
icon = "src/vi/lightnovelvn/icon.png";
|
||||
filters?: Filters | undefined;
|
||||
site = "https://lightnovel.vn/";
|
||||
baseUrl = this.site;
|
||||
headers = {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
async popularNovels(pageNo: number, options: Plugin.PopularNovelsOptions<Filters>): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.baseUrl}truyen-hot-ds?page=${pageNo}`;
|
||||
const body = await fetch(url).then((r) => r.text());
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio(".flex.flex-col[itemtype='https://schema.org/Book']").each((idx, ele) => {
|
||||
const novelName = loadedCheerio(ele).find('h3[itemprop="name"] > a').text().trim();
|
||||
const img = loadedCheerio(ele).find('noscript').html();
|
||||
const novelCover = img?.match(/srcSet="([^\s]+)/)?.[1];
|
||||
const novelUrl = this.site + loadedCheerio(ele).find('h3[itemprop="name"] > a').attr('href')?.substring(1);
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
const body = await fetch(url).then((r) => r.text());
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio('h1[itemprop="name"]').text().trim();
|
||||
|
||||
novel.cover = loadedCheerio('header div:nth-child(2) img').attr('srcset')?.split(/\s+/)[0]
|
||||
|
||||
const genres: string[] = [];
|
||||
loadedCheerio('a[itemprop="genre"]').each(function() {
|
||||
genres.push(loadedCheerio(this).text());
|
||||
})
|
||||
novel.genres = genres.join(',');
|
||||
|
||||
novel.status = loadedCheerio('span.font-bold.text-size22:last').text();
|
||||
if(novel.status === 'Đang ra'){
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
}else if(novel.status === 'Hoàn thành'){
|
||||
novel.status = NovelStatus.Completed;
|
||||
}else {
|
||||
novel.status = NovelStatus.Unknown;
|
||||
}
|
||||
novel.author = loadedCheerio('a[itemprop="author"] > span').text();
|
||||
|
||||
novel.summary = loadedCheerio('#bookIntro').text().replace(/\s+/g, ' ');
|
||||
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
await delay(1000);
|
||||
const chapterListUrl = novelUrl + '/chapters?chorder=desc';
|
||||
|
||||
const chapterListBody = await fetchApi(chapterListUrl).then(r => r.text());
|
||||
const loadedChapterList = parseHTML(chapterListBody);
|
||||
|
||||
|
||||
const lastNumber = parseInt(
|
||||
loadedChapterList('ul.chapter-list > li:nth-child(1)').attr('data-chapterno') ?? '0'
|
||||
);
|
||||
const lastChapterUrl = loadedChapterList('ul.chapter-list > li:nth-child(1) > a').attr('href');
|
||||
|
||||
if(lastChapterUrl){
|
||||
const chapterUrlPrefix = this.baseUrl + lastChapterUrl.split('/').slice(1, -1).join('/');
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
for(let i = 1; i <= lastNumber; i++){
|
||||
chapters.push({
|
||||
chapterNumber: i,
|
||||
name: 'Chapter ' + i,
|
||||
url: chapterUrlPrefix + '/chapter-' + i,
|
||||
})
|
||||
}
|
||||
novel.chapters = chapters;
|
||||
}
|
||||
return novel;
|
||||
}
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const body = await fetchApi(chapterUrl).then((r) => r.text());
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let chapterText = loadedCheerio("#chapter-container").html() || '';
|
||||
|
||||
return chapterText;
|
||||
}
|
||||
async searchNovels(searchTerm: string, pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.baseUrl}lnsearchlive`;
|
||||
const link = `${this.baseUrl}search`;
|
||||
const response = await fetchApi(link).then((r) => r.text());
|
||||
const token = parseHTML(response);
|
||||
let verifytoken = token("#novelSearchForm > input").attr("value");
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("inputContent", searchTerm);
|
||||
|
||||
const body = await fetchApi(
|
||||
url,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { LNRequestVerifyToken: verifytoken! },
|
||||
body: formData,
|
||||
},
|
||||
).then((r) => r.text());
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Plugin.NovelItem[] = [];
|
||||
|
||||
let results = JSON.parse(loadedCheerio("body").text());
|
||||
|
||||
loadedCheerio = parseHTML(results.resultview);
|
||||
|
||||
loadedCheerio(".novel-item").each((idx, ele) => {
|
||||
const novelName = loadedCheerio(ele)
|
||||
.find("h4.novel-title")
|
||||
.text()
|
||||
.trim();
|
||||
const novelCover = loadedCheerio(ele).find("img").attr("src");
|
||||
const novelUrl =
|
||||
this.baseUrl + loadedCheerio(ele).find("a").attr("href")?.substring(1);
|
||||
|
||||
novels.push({
|
||||
name: novelName,
|
||||
url: novelUrl,
|
||||
cover: novelCover,
|
||||
});
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return fetchFile(url, {headers: this.headers});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new LightNovelVN();
|
||||
@@ -0,0 +1,133 @@
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchFile } from "@libs/fetch";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { Filters } from "@libs/filterInputs";
|
||||
import { NovelStatus } from "@libs/novelStatus";
|
||||
|
||||
class TruyenFull implements Plugin.PluginBase {
|
||||
id = "truyenfull";
|
||||
name = "Truyện Full";
|
||||
icon = "src/vi/truyenfull/icon.png";
|
||||
site = "https://truyenfull.vn";
|
||||
version = "1.0.0";
|
||||
|
||||
parseNovels(loadedCheerio: CheerioAPI){
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
loadedCheerio(".list-truyen .row").each((idx, ele) => {
|
||||
const novelName = loadedCheerio(ele)
|
||||
.find("h3.truyen-title > a")
|
||||
.text();
|
||||
|
||||
const novelCover = loadedCheerio(ele).find("div[data-classname='cover']").attr("data-image");
|
||||
|
||||
const novelUrl = loadedCheerio(ele)
|
||||
.find("h3.truyen-title > a")
|
||||
.attr("href");
|
||||
if(novelUrl){
|
||||
novels.push({
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl
|
||||
});
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number, options: Plugin.PopularNovelsOptions<Filters>): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}/danh-sach/truyen-hot/trang-${pageNo}/`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio("div.book > img").attr("alt");
|
||||
|
||||
novel.cover = loadedCheerio("div.book > img").attr("src");
|
||||
|
||||
novel.summary = loadedCheerio("div.desc-text").text().trim();
|
||||
|
||||
novel.author = loadedCheerio('h3:contains("Tác giả:")')
|
||||
.parent()
|
||||
.contents()
|
||||
.text()
|
||||
.replace("Tác giả:", "");
|
||||
|
||||
novel.genres = loadedCheerio('h3:contains("Thể loại")')
|
||||
.siblings()
|
||||
.map((i, el) => loadedCheerio(el).text())
|
||||
.toArray()
|
||||
.join(",");
|
||||
|
||||
novel.status = loadedCheerio('h3:contains("Trạng thái")').next().text();
|
||||
if(novel.status === "Full"){
|
||||
novel.status = NovelStatus.Completed;
|
||||
}else if(novel.status === 'Đang ra'){
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
}else{
|
||||
novel.status = NovelStatus.Unknown;
|
||||
}
|
||||
|
||||
let lastPage = 1;
|
||||
loadedCheerio('ul.pagination.pagination-sm > li').each(function() {
|
||||
const page = Number(loadedCheerio(this).text());
|
||||
if(page && page > lastPage) lastPage = page;
|
||||
});
|
||||
|
||||
const lastPageUrl = novelUrl + 'trang-' + lastPage + '/';
|
||||
const res = await fetch(lastPageUrl).then(res => res.text());
|
||||
loadedCheerio = parseHTML(res);
|
||||
const lastChapterUrl = loadedCheerio('ul.list-chapter > li:last-child > a').attr('href');
|
||||
const lastChapter = Number(lastChapterUrl?.match(/\/chuong-(\d+)\//)?.[1]) || 1;
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
for(let i = 1; i <= lastChapter; i++){
|
||||
chapters.push({
|
||||
name: 'Chương ' + i,
|
||||
url: novelUrl + 'chuong-'+ i + '/',
|
||||
})
|
||||
}
|
||||
novel.chapters = chapters;
|
||||
return novel;
|
||||
}
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const result = await fetch(chapterUrl);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let chapterText = (loadedCheerio(".chapter-title").html() || '') + (loadedCheerio('#chapter-c').html() || '');
|
||||
|
||||
return chapterText;
|
||||
}
|
||||
async searchNovels(searchTerm: string, pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
const searchUrl = `${this.site}/tim-kiem?tukhoa=${searchTerm}&page=${pageNo}`;
|
||||
|
||||
const result = await fetch(searchUrl);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio)
|
||||
}
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return fetchFile(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new TruyenFull();
|
||||
Reference in New Issue
Block a user