fix: add sources, update icons (#693)
* allnovelfull * comrade mao and search pagination * divine dao library * early novel and icon update * make images great
This commit is contained in:
@@ -1,200 +0,0 @@
|
||||
import { load as cheerioload } from "cheerio";
|
||||
import { Chapter, Novel, Plugin } from "@typings/plugin";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
|
||||
export const id = "ANF.com";
|
||||
export const name = "AllNovelFull";
|
||||
export const site = "https://allnovelfull.com";
|
||||
export const version = "1.0.0";
|
||||
export const icon = "src/en/allnovelfull/icon.png";
|
||||
|
||||
export const popularNovels: Plugin.popularNovels = async function (page) {
|
||||
const url = `${site}/most-popular?page=${page}`;
|
||||
|
||||
const result = await fetchApi(url, {});
|
||||
if (!result.ok) {
|
||||
console.error("Cloudflare error");
|
||||
// console.error(await result.text());
|
||||
// TODO: Cloudflare protection or other error
|
||||
return [];
|
||||
}
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
const novels: Novel.Item[] = [];
|
||||
loadedCheerio(".col-truyen-main .list-truyen .row").each(function () {
|
||||
const novelName = loadedCheerio(this)
|
||||
.find("h3.truyen-title > a")
|
||||
.text();
|
||||
const novelCover =
|
||||
site + loadedCheerio(this).find("img.cover").attr("src");
|
||||
const novelUrl =
|
||||
site + loadedCheerio(this).find("h3.truyen-title > a").attr("href");
|
||||
|
||||
const novel = {
|
||||
url: novelUrl,
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
};
|
||||
novels.push(novel);
|
||||
});
|
||||
return novels;
|
||||
};
|
||||
|
||||
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
async function (novelUrl) {
|
||||
const url = novelUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
if (!result.ok) {
|
||||
console.error("Cloudflare error");
|
||||
// console.error(await result.text());
|
||||
// TODO: Cloudflare protection or other error
|
||||
return { url, chapters: [] };
|
||||
}
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = cheerioload(body);
|
||||
|
||||
let novel: Novel.instance = {
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio("div.book > img").attr("alt");
|
||||
|
||||
novel.cover = site + loadedCheerio("div.book > img").attr("src");
|
||||
|
||||
novel.summary = loadedCheerio("div.desc-text").text().trim();
|
||||
|
||||
novel.author = loadedCheerio("div.info > div > h3")
|
||||
.filter(function () {
|
||||
return loadedCheerio(this).text().trim() === "Author:";
|
||||
})
|
||||
.siblings()
|
||||
.text();
|
||||
|
||||
novel.genres = loadedCheerio("div.info > div")
|
||||
.filter(function () {
|
||||
return (
|
||||
loadedCheerio(this).find("h3").text().trim() === "Genre:"
|
||||
);
|
||||
})
|
||||
.text()
|
||||
.replace("Genre:", "");
|
||||
|
||||
novel.status = loadedCheerio("div.info > div > h3")
|
||||
.filter(function () {
|
||||
return loadedCheerio(this).text().trim() === "Status:";
|
||||
})
|
||||
.next()
|
||||
.text();
|
||||
|
||||
const novelId = loadedCheerio("#rating").attr("data-novel-id");
|
||||
|
||||
async function getChapters(id: string) {
|
||||
const chapterListUrl = site + "/ajax/chapter-option?novelId=" + id;
|
||||
|
||||
const data = await fetchApi(chapterListUrl);
|
||||
if (!data.ok) {
|
||||
console.error("Cloudflare error");
|
||||
// console.error(await result.text());
|
||||
// TODO: Cloudflare protection or other error
|
||||
return [];
|
||||
}
|
||||
const chapters = await data.text();
|
||||
|
||||
loadedCheerio = cheerioload(chapters);
|
||||
|
||||
const novelChapters: Chapter.Item[] = [];
|
||||
|
||||
loadedCheerio("select > option").each(function () {
|
||||
let chapterName = loadedCheerio(this).text();
|
||||
let releaseDate = null;
|
||||
let chapterUrl = loadedCheerio(this)
|
||||
.attr("value")
|
||||
?.replace(`/${novelUrl}`, "");
|
||||
|
||||
if (chapterUrl) {
|
||||
novelChapters.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return novelChapters;
|
||||
}
|
||||
|
||||
if (novelId) {
|
||||
novel.chapters = await getChapters(novelId);
|
||||
}
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
|
||||
const url = site + chapterUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
if (!result.ok) {
|
||||
console.error("Cloudflare error");
|
||||
// console.error(await result.text());
|
||||
// TODO: Cloudflare protection or other error
|
||||
return "Cloudflare protected site!";
|
||||
}
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
const chapterText = loadedCheerio("#chapter-content").html() || "";
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
|
||||
const url = `${site}/search?keyword=${searchTerm}`;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
if (!result.ok) {
|
||||
console.error(await result.text());
|
||||
// TODO: Cloudflare protection or other error
|
||||
return [];
|
||||
}
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio("div.col-truyen-main > div.list-truyen > .row").each(
|
||||
function () {
|
||||
const novelUrl =
|
||||
site +
|
||||
loadedCheerio(this).find("h3.truyen-title > a").attr("href");
|
||||
|
||||
const novelName = loadedCheerio(this)
|
||||
.find("h3.truyen-title > a")
|
||||
.text();
|
||||
const novelCover =
|
||||
site + loadedCheerio(this).find("img").attr("src");
|
||||
|
||||
if (novelUrl) {
|
||||
novels.push({
|
||||
url: novelUrl,
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
export const fetchImage: Plugin.fetchImage = async function (url, init) {
|
||||
return await fetchFile(url, init);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { isUrlAbsolute } from "@libs/isAbsoluteUrl";
|
||||
|
||||
class AllNovelFullPlugin implements Plugin.PluginBase {
|
||||
id = "anf.net";
|
||||
name = "AllNovelFull";
|
||||
icon = "src/en/allnovelfull/icon.png";
|
||||
site = "https://allnovelfull.net";
|
||||
version = "1.0.0";
|
||||
userAgent = "";
|
||||
parseNovels(loadedCheerio: CheerioAPI) {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio(".col-truyen-main .list-truyen .row").each((i,el) => {
|
||||
const novelName = loadedCheerio(el)
|
||||
.find("h3.truyen-title > a")
|
||||
.text();
|
||||
let novelCover = loadedCheerio(el).find("img.cover").attr("src");
|
||||
let novelUrl = loadedCheerio(el).find("h3.truyen-title > a").attr("href");
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
if (novelUrl && !isUrlAbsolute(novelUrl)) {
|
||||
novelUrl = this.site + novelUrl;
|
||||
}
|
||||
if (novelCover && !isUrlAbsolute(novelCover)){
|
||||
novelCover = this.site + novelCover;
|
||||
}
|
||||
|
||||
const novel = {
|
||||
url: novelUrl,
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
};
|
||||
novels.push(novel);
|
||||
});
|
||||
return novels;
|
||||
};
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters>
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = this.site;
|
||||
|
||||
if (filters.genres.value.length)
|
||||
link += filters.genres.value;
|
||||
else
|
||||
link += filters.order.value;
|
||||
|
||||
link += `?page=${pageNo}`;
|
||||
|
||||
const headers = new Headers();
|
||||
const body = await fetchApi(link, { headers }).then((result) =>
|
||||
result.text()
|
||||
);
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio(".book > img").attr("alt");
|
||||
|
||||
novel.cover = this.site + loadedCheerio(".book > img").attr("src");
|
||||
|
||||
novel.summary = loadedCheerio(".desc-text").text().trim();
|
||||
|
||||
loadedCheerio(".info > div").each((i,el) => {
|
||||
const detailName = loadedCheerio(el).find("h3").text();
|
||||
const detail = loadedCheerio(el)
|
||||
.find('a')
|
||||
.map((a,ex) => loadedCheerio(ex).text())
|
||||
.toArray()
|
||||
.join(', ');
|
||||
|
||||
switch (detailName) {
|
||||
case 'Author:':
|
||||
novel.author = detail;
|
||||
break;
|
||||
case 'Status:':
|
||||
novel.status = detail;
|
||||
break;
|
||||
case 'Genre:':
|
||||
novel.genres = detail;
|
||||
break;
|
||||
}});
|
||||
|
||||
const novelId = loadedCheerio("#rating").attr("data-novel-id");
|
||||
|
||||
const getChapters = async (id: string) => {
|
||||
const chaptersUrl = this.site + "/ajax/chapter-option?novelId=" + id;
|
||||
|
||||
const data = await fetchApi(chaptersUrl, { headers });
|
||||
const chapters = await data.text();
|
||||
|
||||
loadedCheerio = parseHTML(chapters);
|
||||
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
|
||||
loadedCheerio("select > option").each((i,el) => {
|
||||
const chapterName = loadedCheerio(el).text();
|
||||
const releaseDate = null;
|
||||
const cUrl = loadedCheerio(el).attr("value");
|
||||
const chapterUrl = this.site + cUrl
|
||||
|
||||
if (!cUrl) return;
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
return chapter;
|
||||
}
|
||||
|
||||
if (novelId) {
|
||||
novel.chapters = await getChapters(novelId);
|
||||
}
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(chapterUrl, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const chapterText = loadedCheerio("#chapter-content").html() || "";
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}/search?keyword=${searchTerm}&page=${pageNo}`;
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
};
|
||||
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return await fetchFile(url);
|
||||
}
|
||||
|
||||
filters = {
|
||||
order: {
|
||||
value: "/most-popular",
|
||||
label: "Order by",
|
||||
options: [
|
||||
{ label: "Latest Release", value: "/latest-release-novel" },
|
||||
{ label: "Hot Novel", value: "/hot-novel" },
|
||||
{ label: "Completed Novel", value: "/completed-novel" },
|
||||
{ label: "Most Popular", value: "/most-popular" },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
genres: {
|
||||
value: "",
|
||||
label: "Genre",
|
||||
options: [
|
||||
{ label: "None", value: "" },
|
||||
{ label: "Shounen", value: "/genre/Shounen" },
|
||||
{ label: "Harem", value: "/genre/Harem" },
|
||||
{ label: "Comedy", value: "/genre/Comedy" },
|
||||
{ label: "Martial Arts", value: "/genre/Martial+Arts" },
|
||||
{ label: "School Life", value: "/genre/School+Life" },
|
||||
{ label: "Mystery", value: "/genre/Mystery" },
|
||||
{ label: "Shoujo", value: "/genre/Shoujo" },
|
||||
{ label: "Romance", value: "/genre/Romance" },
|
||||
{ label: "Sci-fi", value: "/genre/Sci-fi" },
|
||||
{ label: "Gender Bender", value: "/genre/Gender+Bender" },
|
||||
{ label: "Mature", value: "/genre/Mature" },
|
||||
{ label: "Fantasy", value: "/genre/Fantasy" },
|
||||
{ label: "Horror", value: "/genre/Horror" },
|
||||
{ label: "Drama", value: "/genre/Drama" },
|
||||
{ label: "Tragedy", value: "/genre/Tragedy" },
|
||||
{ label: "Supernatural", value: "/genre/Supernatural" },
|
||||
{ label: "Ecchi", value: "/genre/Ecchi" },
|
||||
{ label: "Xuanhuan", value: "/genre/Xuanhuan" },
|
||||
{ label: "Adventure", value: "/genre/Adventure" },
|
||||
{ label: "Action", value: "/genre/Action" },
|
||||
{ label: "Psychological", value: "/genre/Psychological" },
|
||||
{ label: "Xianxia", value: "/genre/Xianxia" },
|
||||
{ label: "Wuxia", value: "/genre/Wuxia" },
|
||||
{ label: "Historical", value: "/genre/Historical" },
|
||||
{ label: "Slice of Life", value: "/genre/Slice+of+Life" },
|
||||
{ label: "Seinen", value: "/genre/Seinen" },
|
||||
{ label: "Lolicon", value: "/genre/Lolicon" },
|
||||
{ label: "Adult", value: "/genre/Adult" },
|
||||
{ label: "Josei", value: "/genre/Josei" },
|
||||
{ label: "Sports", value: "/genre/Sports" },
|
||||
{ label: "Smut", value: "/genre/Smut" },
|
||||
{ label: "Mecha", value: "/genre/Mecha" },
|
||||
{ label: "Yaoi", value: "/genre/Yaoi" },
|
||||
{ label: "Shounen Ai", value: "/genre/Shounen+Ai" },
|
||||
{ label: "Magical Realism", value: "/genre/Magical+Realism" },
|
||||
{ label: "Video Games", value: "/genre/Video+Games" },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new AllNovelFullPlugin();
|
||||
@@ -1,164 +0,0 @@
|
||||
import { load as cheerioload } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import dayjs from "dayjs";
|
||||
import { Chapter, Novel, Plugin } from "@typings/plugin";
|
||||
|
||||
export const id = "comrademao";
|
||||
export const name = "Comrade Mao";
|
||||
export const site = "https://comrademao.com/";
|
||||
export const version = "1.0.0";
|
||||
export const icon = "src/en/comrademao/icon.png";
|
||||
|
||||
export const popularNovels: Plugin.popularNovels = async function (page) {
|
||||
let url = site + "page/" + page + "/?post_type=novel";
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio(".listupd")
|
||||
.find("div.bs")
|
||||
.each(function () {
|
||||
const novelName = loadedCheerio(this).find(".tt").text().trim();
|
||||
const novelCover = loadedCheerio(this).find("img").attr("src");
|
||||
const novelUrl = loadedCheerio(this).find("a").attr("href");
|
||||
|
||||
if (!novelUrl) {
|
||||
// TODO: Handle error
|
||||
console.error("No novel url!");
|
||||
return;
|
||||
}
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
async function (novelUrl) {
|
||||
const url = novelUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
let novel: Novel.instance = { url };
|
||||
|
||||
novel.name = loadedCheerio(".entry-title").text().trim();
|
||||
|
||||
novel.cover = loadedCheerio("div.thumbook > div > img").attr("src");
|
||||
|
||||
novel.summary = loadedCheerio("div.infox > div:nth-child(6) > span > p")
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
novel.genres = loadedCheerio("div.infox > div:nth-child(4) > span")
|
||||
.text()
|
||||
.replace(/\s/g, "");
|
||||
|
||||
novel.status = loadedCheerio("div.infox > div:nth-child(3) > span")
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
novel.author = loadedCheerio("div.infox > div:nth-child(2) > span")
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
let novelChapters: Chapter.Item[] = [];
|
||||
|
||||
loadedCheerio("#chapterlist")
|
||||
.find("li")
|
||||
.each(function () {
|
||||
const releaseDate = dayjs(
|
||||
loadedCheerio(this).find(".chapterdate").text()
|
||||
).format("LL");
|
||||
const chapterName = loadedCheerio(this)
|
||||
.find(".chapternum")
|
||||
.text();
|
||||
const chapterUrl = loadedCheerio(this).find("a").attr("href");
|
||||
|
||||
if (!chapterUrl) {
|
||||
// TODO: Handle error
|
||||
console.error("No chapter url!");
|
||||
return;
|
||||
}
|
||||
|
||||
novelChapters.push({
|
||||
name: chapterName,
|
||||
url: chapterUrl,
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = novelChapters.reverse();
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
|
||||
const url = chapterUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
if (!result.ok) {
|
||||
const err = await result.text();
|
||||
console.error(err);
|
||||
// TODO: Cloudflare protection or other error
|
||||
return "Error!" + err;
|
||||
}
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
let chapterText = loadedCheerio("#chaptercontent").html();
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
|
||||
const url = site + "?s=" + searchTerm + "&post_type=novel";
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = cheerioload(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio(".listupd")
|
||||
.find("div.bs")
|
||||
.each(function () {
|
||||
const novelName = loadedCheerio(this).find(".tt").text().trim();
|
||||
const novelCover = loadedCheerio(this).find("img").attr("src");
|
||||
const novelUrl = loadedCheerio(this).find("a").attr("href");
|
||||
|
||||
if (!novelUrl) {
|
||||
// TODO: Handle error
|
||||
console.error("No novel url!");
|
||||
return;
|
||||
}
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
export const fetchImage: Plugin.fetchImage = (...args) => fetchFile(...args);
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { parseMadaraDate } from "@libs/parseMadaraDate";
|
||||
|
||||
class ComradeMaoPlugin implements Plugin.PluginBase {
|
||||
id = "comrademao";
|
||||
name = "Comrade Mao";
|
||||
site = "https://comrademao.com/";
|
||||
version = "1.0.0";
|
||||
icon = "src/en/comrademao/icon.png";
|
||||
userAgent = "";
|
||||
parseNovels(loadedCheerio: CheerioAPI) {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio(".listupd")
|
||||
.find("div.bs")
|
||||
.each(function () {
|
||||
const novelName = loadedCheerio(this).find(".tt").text().trim();
|
||||
const novelCover = loadedCheerio(this).find("img").attr("src");
|
||||
const novelUrl = loadedCheerio(this).find("a").attr("href");
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
}
|
||||
novels.push(novel);
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters>
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = this.site;
|
||||
|
||||
link += filters.category.value;
|
||||
|
||||
link += "page/" + pageNo + "/?post_type=novel";
|
||||
|
||||
const headers = new Headers();
|
||||
const body = await fetchApi(link, { headers }).then((result) =>
|
||||
result.text()
|
||||
);
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio(".entry-title").text().trim();
|
||||
|
||||
novel.cover = loadedCheerio("div.thumbook > div > img").attr("src");
|
||||
|
||||
loadedCheerio(".infox .wd-full").each((i,el) => {
|
||||
const detailName = loadedCheerio(el).find("b").text();
|
||||
const detail = loadedCheerio(el).find('span').text();
|
||||
|
||||
switch (detailName) {
|
||||
case 'Publisher: ':
|
||||
novel.author = detail.trim();
|
||||
break;
|
||||
case 'Status: ':
|
||||
novel.status = detail.trim();
|
||||
break;
|
||||
case 'Genres:':
|
||||
novel.genres = detail.trim().replace(/ , /g, ',');
|
||||
break;
|
||||
case 'Description: ':
|
||||
novel.summary = detail.trim();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
|
||||
loadedCheerio("#chapterlist")
|
||||
.find("li")
|
||||
.each(function () {
|
||||
const releaseDate = parseMadaraDate(
|
||||
loadedCheerio(this).find(".chapterdate").text()
|
||||
);
|
||||
const chapterName = loadedCheerio(this)
|
||||
.find(".chapternum")
|
||||
.text();
|
||||
const chapterUrl = loadedCheerio(this).find("a").attr("href");
|
||||
|
||||
if (!chapterUrl) return;
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
url: chapterUrl,
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = chapter.reverse();
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(chapterUrl, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const chapterText = loadedCheerio("#chaptercontent").html()?.trim() || "";
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}page/${pageNo}/?s=${searchTerm}&post_type=novel`;
|
||||
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
};
|
||||
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return await fetchFile(url);
|
||||
}
|
||||
|
||||
filters = {
|
||||
category: {
|
||||
value: "",
|
||||
label: "Type",
|
||||
options: [
|
||||
{ label: "None", value: "" },
|
||||
{ label: "Chinese", value: "/mtype/chinese/" },
|
||||
{ label: "Japanese", value: "/mtype/japanese/" },
|
||||
{ label: "Korean", value: "/mtype/korean/" },
|
||||
{ label: "Manhua", value: "/mtype/manhua/" },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new ComradeMaoPlugin();
|
||||
@@ -1,151 +0,0 @@
|
||||
import { load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { Chapter, Novel, Plugin } from "@typings/plugin";
|
||||
import { defaultCover } from "@libs/defaultCover";
|
||||
|
||||
export const id = "DDL.com";
|
||||
export const name = "Divine Dao Library";
|
||||
export const site = "https://www.divinedaolibrary.com/";
|
||||
export const version = "1.0.0";
|
||||
export const icon = "src/en/divinedaolibrary/icon.png";
|
||||
|
||||
const baseUrl = site;
|
||||
|
||||
export const popularNovels: Plugin.popularNovels = async function (page) {
|
||||
let url = baseUrl + "novels";
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio("#main")
|
||||
.find("li")
|
||||
.each(function () {
|
||||
const novelName = loadedCheerio(this).find("a").text();
|
||||
const novelCover = defaultCover;
|
||||
const novelUrl = loadedCheerio(this).find(" a").attr("href");
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
async function (novelUrl) {
|
||||
const url = novelUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novel: Novel.instance = { url };
|
||||
|
||||
novel.name = loadedCheerio("h1.entry-title").text().trim();
|
||||
|
||||
novel.cover =
|
||||
loadedCheerio(".entry-content").find("img").attr("data-ezsrc") ||
|
||||
defaultCover;
|
||||
|
||||
novel.summary = loadedCheerio("#main > article > div > p:nth-child(6)")
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
novel.author = loadedCheerio("#main > article > div > h3:nth-child(2)")
|
||||
.text()
|
||||
.replace(/Author:/g, "")
|
||||
.trim();
|
||||
|
||||
let novelChapters: Chapter.Item[] = [];
|
||||
|
||||
loadedCheerio("#main")
|
||||
.find("li > span > a")
|
||||
.each(function () {
|
||||
const chapterName = loadedCheerio(this).text().trim();
|
||||
const releaseDate = null;
|
||||
const chapterUrl = loadedCheerio(this).attr("href");
|
||||
|
||||
if (!chapterUrl) return;
|
||||
|
||||
novelChapters.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = novelChapters;
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
|
||||
const url = chapterUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let chapterName = loadedCheerio(".entry-title").text().trim();
|
||||
|
||||
let chapterText = loadedCheerio(".entry-content").html();
|
||||
|
||||
if (!chapterText) {
|
||||
chapterText = loadedCheerio(".page-header").html();
|
||||
}
|
||||
|
||||
chapterText = `<p><h1>${chapterName}</h1></p>` + chapterText;
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
|
||||
let url = baseUrl + "novels";
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio("#main")
|
||||
.find("li")
|
||||
.each(function () {
|
||||
const novelName = loadedCheerio(this).find("a").text();
|
||||
const novelCover = defaultCover;
|
||||
const novelUrl = loadedCheerio(this).find(" a").attr("href");
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
novels = novels.filter((novel) =>
|
||||
novel.name.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
|
||||
return novels;
|
||||
};
|
||||
export const fetchImage: Plugin.fetchImage = async function (url, init) {
|
||||
return await fetchFile(url, init);
|
||||
};
|
||||
@@ -0,0 +1,148 @@
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { defaultCover } from "@libs/defaultCover";
|
||||
|
||||
class DDLPlugin implements Plugin.PluginBase {
|
||||
id = "DDL.com";
|
||||
name = "Divine Dao Library";
|
||||
site = "https://www.divinedaolibrary.com/";
|
||||
version = "1.0.0";
|
||||
icon = "src/en/divinedaolibrary/icon.png";
|
||||
userAgent = "";
|
||||
parseNovels(loadedCheerio: CheerioAPI, searchTerm?: string){
|
||||
let novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio("#main")
|
||||
.find("li")
|
||||
.each(function () {
|
||||
const novelName = loadedCheerio(this).find("a").text();
|
||||
const novelCover = defaultCover;
|
||||
const novelUrl = loadedCheerio(this).find(" a").attr("href");
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
if (searchTerm) {
|
||||
novels = novels.filter((novel) =>
|
||||
novel.name.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
}
|
||||
return novels;
|
||||
};
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ filters }: Plugin.PopularNovelsOptions
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = this.site + "novels";
|
||||
|
||||
const headers = new Headers();
|
||||
const body = await fetchApi(link, { headers }).then((result) =>
|
||||
result.text()
|
||||
);
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio("h1.entry-title").text().trim();
|
||||
|
||||
novel.cover =
|
||||
loadedCheerio(".entry-content").find("img").attr("data-ezsrc") ||
|
||||
defaultCover;
|
||||
|
||||
novel.summary = loadedCheerio("#main > article > div > p:nth-child(6)")
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
novel.author = loadedCheerio("#main > article > div > h3:nth-child(2)")
|
||||
.text()
|
||||
.replace(/Author:/g, "")
|
||||
.trim();
|
||||
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
|
||||
loadedCheerio("#main")
|
||||
.find("li > span > a")
|
||||
.each(function () {
|
||||
const chapterName = loadedCheerio(this).text().trim();
|
||||
const releaseDate = null;
|
||||
const chapterUrl = loadedCheerio(this).attr("href");
|
||||
|
||||
if (!chapterUrl) return;
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = chapter;
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(chapterUrl, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const chapterName = loadedCheerio(".entry-title").text().trim();
|
||||
|
||||
let chapterText = loadedCheerio(".entry-content").html();
|
||||
|
||||
if (!chapterText) {
|
||||
chapterText = loadedCheerio(".page-header").html();
|
||||
}
|
||||
|
||||
chapterText = `<p><h1>${chapterName}</h1></p>` + chapterText;
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let url = this.site + "novels";
|
||||
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio, searchTerm);
|
||||
};
|
||||
|
||||
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return await fetchFile(url);
|
||||
}
|
||||
}
|
||||
export default new DDLPlugin();
|
||||
@@ -1,196 +0,0 @@
|
||||
import { load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { showToast } from "@libs/showToast";
|
||||
import { Chapter, Novel, Plugin } from "@typings/plugin";
|
||||
import { defaultCover } from "@libs/defaultCover";
|
||||
|
||||
export const id = "earlynovel";
|
||||
export const name = "Early Novel";
|
||||
export const version = "1.0.0";
|
||||
export const icon = "multisrc/madara/icons/latestnovel.png";
|
||||
export const site = "https://earlynovel.net/";
|
||||
|
||||
|
||||
const pluginId = id;
|
||||
const baseUrl = site;
|
||||
|
||||
export const popularNovels: Plugin.popularNovels = async function (page) {
|
||||
const url = `${baseUrl}most-popular?page=${page}`;
|
||||
|
||||
const body = await fetchApi(url, {}, pluginId).then((r) => r.text());
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio(".col-truyen-main > .list-truyen > .row").each(function () {
|
||||
const novelName = loadedCheerio(this)
|
||||
.find("h3.truyen-title > a")
|
||||
.attr("title");
|
||||
const novelCover =
|
||||
loadedCheerio(this).find(".lazyimg").attr("data-desk-image") ||
|
||||
loadedCheerio(this).find("img.cover").attr("src");
|
||||
const novelUrl =
|
||||
baseUrl +
|
||||
loadedCheerio(this)
|
||||
.find("h3.truyen-title > a")
|
||||
.attr("href")
|
||||
?.slice(1);
|
||||
|
||||
if (!novelUrl || !novelName) return;
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover || defaultCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
async function (novelUrl) {
|
||||
showToast("Early Novel may take 20-30 seconds");
|
||||
const url = novelUrl;
|
||||
|
||||
const body = await fetchApi(url, {}, pluginId).then((r) => r.text());
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const name = loadedCheerio(".book > img").attr("alt");
|
||||
const cover = loadedCheerio(".book > img").attr("src") || defaultCover;
|
||||
const summary = loadedCheerio(".desc-text").text().trim();
|
||||
const novel: Novel.instance = {
|
||||
url,
|
||||
chapters: [],
|
||||
name,
|
||||
summary,
|
||||
cover,
|
||||
};
|
||||
|
||||
loadedCheerio(".info > div > h3").each(function () {
|
||||
let detailName = loadedCheerio(this).text();
|
||||
let detail = loadedCheerio(this)
|
||||
.siblings()
|
||||
.map((i, el) => loadedCheerio(el).text())
|
||||
.toArray()
|
||||
.join(",");
|
||||
|
||||
switch (detailName) {
|
||||
case "Author:":
|
||||
novel.author = detail;
|
||||
break;
|
||||
case "Status:":
|
||||
novel.status = detail;
|
||||
break;
|
||||
case "Genre:":
|
||||
novel.genres = detail;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
//! Doesn't work since there are multiple pages and can't find source API
|
||||
//# Since cannot find sourceAPI i try similar function to lightnovelpub
|
||||
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
|
||||
const lastPageStr = loadedCheerio('a:contains("Last ")')
|
||||
.attr("title")
|
||||
?.match(/(\d+)/g);
|
||||
const lastPage = Number(lastPageStr?.[1] || "0");
|
||||
|
||||
async function getChapters() {
|
||||
let chapter: Chapter.Item[] = [];
|
||||
for (let i = 1; i <= lastPage; i++) {
|
||||
const chaptersUrl = `${novelUrl}?page=${i}`;
|
||||
|
||||
const chaptersHtml = await fetchApi(
|
||||
chaptersUrl,
|
||||
{},
|
||||
pluginId
|
||||
).then((r) => r.text());
|
||||
|
||||
loadedCheerio = parseHTML(chaptersHtml);
|
||||
|
||||
loadedCheerio("ul.list-chapter > li").each(function () {
|
||||
const chapterName = loadedCheerio(this)
|
||||
.find(".chapter-text")
|
||||
.text()
|
||||
.trim();
|
||||
const releaseDate = null;
|
||||
const chapterHref = loadedCheerio(this)
|
||||
.find("a")
|
||||
.attr("href")
|
||||
?.slice(1);
|
||||
if (!chapterHref) return;
|
||||
const chapterUrl = baseUrl + chapterHref;
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
await delay(1000);
|
||||
}
|
||||
|
||||
return chapter;
|
||||
}
|
||||
|
||||
novel.chapters = await getChapters();
|
||||
|
||||
return novel;
|
||||
};
|
||||
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
|
||||
const body = await fetchApi(chapterUrl, {}, pluginId).then((r) => r.text());
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const chapterText = loadedCheerio("#chapter-c").html() || "";
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
|
||||
const url = `${baseUrl}search?keyword=${searchTerm}`;
|
||||
|
||||
const body = await fetchApi(url, {}, pluginId).then((r) => r.text());
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
|
||||
loadedCheerio("div.col-truyen-main > div.list-truyen > .row").each(
|
||||
function () {
|
||||
const novelUrl =
|
||||
baseUrl +
|
||||
loadedCheerio(this).find("h3.truyen-title > a").attr("href");
|
||||
|
||||
const novelName = loadedCheerio(this)
|
||||
.find("h3.truyen-title > a")
|
||||
.text();
|
||||
const novelCover =
|
||||
baseUrl + loadedCheerio(this).find("img").attr("src");
|
||||
|
||||
if (novelUrl) {
|
||||
novels.push({
|
||||
url: novelUrl,
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
export const fetchImage: Plugin.fetchImage = async function fetchImage(url) {
|
||||
const headers = {
|
||||
Referer: baseUrl,
|
||||
};
|
||||
return await fetchFile(url, { headers: headers });
|
||||
};
|
||||
@@ -0,0 +1,241 @@
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
||||
import { showToast } from "@libs/showToast";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { defaultCover } from "@libs/defaultCover";
|
||||
|
||||
class EarlyNovelPlugin implements Plugin.PluginBase {
|
||||
id = "earlynovel";
|
||||
name = "Early Novel";
|
||||
version = "1.0.0";
|
||||
icon = "multisrc/madara/icons/latestnovel.png";
|
||||
site = "https://earlynovel.net/";
|
||||
userAgent = "";
|
||||
parseNovels(loadedCheerio: CheerioAPI){
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio(".col-truyen-main > .list-truyen > .row").each(
|
||||
(i, el) => {
|
||||
const nUrl = loadedCheerio(el).find("h3.truyen-title > a").attr("href");
|
||||
|
||||
const novelUrl = this.site + nUrl
|
||||
const novelName = loadedCheerio(el)
|
||||
.find("h3.truyen-title > a")
|
||||
.text();
|
||||
const novelCover = loadedCheerio(el).find("img.cover").attr("src");
|
||||
console.log(novelCover);
|
||||
|
||||
if (!nUrl) return;
|
||||
novels.push({
|
||||
url: novelUrl,
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters>
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = this.site;
|
||||
|
||||
if (filters.genres.value.length)
|
||||
link += filters.genres.value;
|
||||
else
|
||||
link += filters.order.value;
|
||||
|
||||
link += `?page=${pageNo}`;
|
||||
|
||||
const headers = new Headers();
|
||||
const body = await fetchApi(link, { headers }).then((result) =>
|
||||
result.text()
|
||||
);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
showToast("Early Novel may take 20-30 seconds");
|
||||
const url = novelUrl;
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
novel.name = loadedCheerio(".book > img").attr("alt");
|
||||
|
||||
novel.cover = loadedCheerio(".book > img").attr("src");
|
||||
|
||||
novel.summary = loadedCheerio(".desc-text").text().trim();
|
||||
|
||||
loadedCheerio(".info > div > h3").each(function () {
|
||||
let detailName = loadedCheerio(this).text();
|
||||
let detail = loadedCheerio(this)
|
||||
.siblings()
|
||||
.map((i, el) => loadedCheerio(el).text())
|
||||
.toArray()
|
||||
.join(",");
|
||||
|
||||
switch (detailName) {
|
||||
case "Author:":
|
||||
novel.author = detail;
|
||||
break;
|
||||
case "Status:":
|
||||
novel.status = detail;
|
||||
break;
|
||||
case "Genre:":
|
||||
novel.genres = detail;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
//! Doesn't work since there are multiple pages and can't find source API
|
||||
//# Since cannot find sourceAPI i try similar function to lightnovelpub
|
||||
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
|
||||
const lastPageStr = loadedCheerio('a:contains("Last ")')
|
||||
.attr("title")
|
||||
?.match(/(\d+)/g);
|
||||
const lastPage = Number(lastPageStr?.[1] || "0");
|
||||
|
||||
const getChapters = async () => {
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
for (let i = 1; i <= lastPage; i++) {
|
||||
const chaptersUrl = `${novelUrl}?page=${i}`;
|
||||
const data = await fetchApi(chaptersUrl, { headers });
|
||||
const chapters = await data.text();
|
||||
|
||||
loadedCheerio = parseHTML(chapters);
|
||||
|
||||
loadedCheerio("ul.list-chapter > li").each((i,el) => {
|
||||
const chapterName = loadedCheerio(el)
|
||||
.find(".chapter-text")
|
||||
.text()
|
||||
.trim();
|
||||
const releaseDate = null;
|
||||
const cUrl = loadedCheerio(el)
|
||||
.find("a")
|
||||
.attr("href")
|
||||
?.slice(1);
|
||||
if (!cUrl) return;
|
||||
const chapterUrl = this.site + cUrl;
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
await delay(1000);
|
||||
}
|
||||
|
||||
return chapter;
|
||||
}
|
||||
|
||||
novel.chapters = await getChapters();
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(chapterUrl, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const chapterText = loadedCheerio("#chapter-c").html() || "";
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}search?keyword=${searchTerm}`;
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(url, { headers });
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
};
|
||||
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return await fetchFile(url);
|
||||
}
|
||||
|
||||
filters = {
|
||||
order: {
|
||||
value: "/most-popular",
|
||||
label: "Order by",
|
||||
options: [
|
||||
{ label: "Latest Release", value: "/latest-release-novel" },
|
||||
{ label: "Hot Novel", value: "/hot-novel" },
|
||||
{ label: "Completed Novel", value: "/completed-novel" },
|
||||
{ label: "Most Popular", value: "/most-popular" },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
genres: {
|
||||
value: "",
|
||||
label: "Genre",
|
||||
options: [
|
||||
{ label: "None", value: "" },
|
||||
{ label: "Action", value: "/genre/action-1" },
|
||||
{ label: "Adult", value: "/genre/adult-2" },
|
||||
{ label: "Adventure", value: "/genre/adventure-3" },
|
||||
{ label: "Comedy", value: "/genre/comedy-4" },
|
||||
{ label: "Drama", value: "/genre/drama-5" },
|
||||
{ label: "Ecchi", value: "/genre/ecchi-6" },
|
||||
{ label: "Fantasy", value: "/genre/fantasy-7" },
|
||||
{ label: "Gender Bender", value: "/genre/gender-bender-8" },
|
||||
{ label: "Harem", value: "/genre/harem-9" },
|
||||
{ label: "Historical", value: "/genre/historical-10" },
|
||||
{ label: "Horror", value: "/genre/horror-11" },
|
||||
{ label: "Josei", value: "/genre/josei-12" },
|
||||
{ label: "Martial Arts", value: "/genre/martial-arts-13" },
|
||||
{ label: "Mature", value: "/genre/mature-14" },
|
||||
{ label: "Mecha", value: "/genre/mecha-15" },
|
||||
{ label: "Mystery", value: "/genre/mystery-16" },
|
||||
{ label: "Psychological", value: "/genre/psychological-17" },
|
||||
{ label: "Romance", value: "/genre/romance-18" },
|
||||
{ label: "School Life", value: "/genre/school-life-19" },
|
||||
{ label: "Sci-fi", value: "/genre/sci-fi-20" },
|
||||
{ label: "Seinen", value: "/genre/seinen-21" },
|
||||
{ label: "Shoujo", value: "/genre/shoujo-22" },
|
||||
{ label: "Shoujo Ai", value: "/genre/shoujo-ai-23" },
|
||||
{ label: "Shounen", value: "/genre/shounen-24" },
|
||||
{ label: "Shounen Ai", value: "/genre/shounen-ai-25" },
|
||||
{ label: "Slice of Life", value: "/genre/slice-of-life-26" },
|
||||
{ label: "Smut", value: "/genre/smut-27" },
|
||||
{ label: "Sports", value: "/genre/sports-28" },
|
||||
{ label: "Supernatural", value: "/genre/supernatural-29" },
|
||||
{ label: "Tragedy", value: "/genre/tragedy-30" },
|
||||
{ label: "Wuxia", value: "/genre/wuxia-31" },
|
||||
{ label: "Xianxia", value: "/genre/xianxia-32" },
|
||||
{ label: "Xuanhuan", value: "/genre/xuanhuan-33" },
|
||||
{ label: "Yaoi", value: "/genre/yaoi-34" },
|
||||
{ label: "Yuri", value: "/genre/yuri-35" },
|
||||
{ label: "Video Games", value: "/genre/video-games-36" },
|
||||
{ label: "Magical Realism", value: "/genre/magical-realism-37" },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new EarlyNovelPlugin();
|
||||
@@ -12,7 +12,8 @@ class TuNovelaLigera implements Plugin.PluginBase {
|
||||
icon = "src/es/tunovelaligera/icon.png";
|
||||
site = "https://tunovelaligera.com/";
|
||||
version = "1.0.0";
|
||||
userAgent = "";
|
||||
userAgent = "";
|
||||
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
@@ -20,11 +21,11 @@ class TuNovelaLigera implements Plugin.PluginBase {
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = `${this.site}`;
|
||||
|
||||
|
||||
link += filters.genres.value ? `genero/` + filters.genres.value : "novelas";
|
||||
|
||||
link += `/page/${pageNo}`;
|
||||
|
||||
|
||||
link += filters.order.value;
|
||||
|
||||
const headers = new Headers();
|
||||
const result = await fetchApi(link, { headers });
|
||||
|
||||
Reference in New Issue
Block a user