Change RoyalRoad regex, fix Faqwiki (#849)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||||
import { FilterTypes, Filters } from "@libs/filterInputs";
|
|
||||||
import { Plugin } from "@typings/plugin";
|
import { Plugin } from "@typings/plugin";
|
||||||
import { defaultCover } from "@libs/defaultCover";
|
import { defaultCover } from "@libs/defaultCover";
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ class DDLPlugin implements Plugin.PluginBase {
|
|||||||
id = "DDL.com";
|
id = "DDL.com";
|
||||||
name = "Divine Dao Library";
|
name = "Divine Dao Library";
|
||||||
site = "https://www.divinedaolibrary.com/";
|
site = "https://www.divinedaolibrary.com/";
|
||||||
version = "1.0.0";
|
version = "1.0.1";
|
||||||
icon = "src/en/divinedaolibrary/icon.png";
|
icon = "src/en/divinedaolibrary/icon.png";
|
||||||
filters?: undefined;
|
filters?: undefined;
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ class DDLPlugin implements Plugin.PluginBase {
|
|||||||
.each((i,el) => {
|
.each((i,el) => {
|
||||||
const novelName = loadedCheerio(el).find("a").text();
|
const novelName = loadedCheerio(el).find("a").text();
|
||||||
const novelCover = defaultCover;
|
const novelCover = defaultCover;
|
||||||
const novelUrl = loadedCheerio(el).find(" a").attr("href");
|
const novelUrl = loadedCheerio(el).find("a").attr("href");
|
||||||
|
|
||||||
if (!novelUrl) return;
|
if (!novelUrl) return;
|
||||||
|
|
||||||
@@ -135,4 +134,5 @@ class DDLPlugin implements Plugin.PluginBase {
|
|||||||
return await fetchFile(url);
|
return await fetchFile(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new DDLPlugin();
|
export default new DDLPlugin();
|
||||||
@@ -1,15 +1,41 @@
|
|||||||
import { Plugin } from "@typings/plugin";
|
import { Plugin } from "@typings/plugin";
|
||||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||||
import { NovelStatus } from "@libs/novelStatus";
|
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||||
import { load as parseHTML } from "cheerio";
|
|
||||||
|
|
||||||
class FaqWikiUs implements Plugin.PluginBase {
|
class FaqWikiUs implements Plugin.PluginBase {
|
||||||
id = "FWK.US";
|
id = "FWK.US";
|
||||||
name = "Faq Wiki";
|
name = "Faq Wiki";
|
||||||
site = "https://faqwiki.us/";
|
site = "https://faqwiki.us/";
|
||||||
version = "1.0.0";
|
version = "1.1.0";
|
||||||
icon = "src/en/faqwikius/icon.png";
|
icon = "src/en/faqwikius/icon.png";
|
||||||
|
|
||||||
|
parseNovels(loadedCheerio:CheerioAPI, searchTerm?: string) {
|
||||||
|
let novels: Plugin.NovelItem[] = [];
|
||||||
|
|
||||||
|
loadedCheerio("figure.wp-block-image").each((index, element) => {
|
||||||
|
const name = loadedCheerio(element).text();
|
||||||
|
let cover = loadedCheerio(element).find("img").attr("data-ezsrc");
|
||||||
|
|
||||||
|
// Remove the appended query string
|
||||||
|
if (cover) {
|
||||||
|
cover = cover.replace(/\?ezimgfmt=.*$/, ''); // Regular expression magic!
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = loadedCheerio(element).find("a").attr("href")?.slice(this.site.length);
|
||||||
|
if (!path) return;
|
||||||
|
|
||||||
|
novels.push({ name, cover, path });
|
||||||
|
})
|
||||||
|
|
||||||
|
if (searchTerm) {
|
||||||
|
novels = novels.filter((novel) =>
|
||||||
|
novel.name.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return novels;
|
||||||
|
}
|
||||||
|
|
||||||
async popularNovels(
|
async popularNovels(
|
||||||
page: number,
|
page: number,
|
||||||
{ showLatestNovels }: Plugin.PopularNovelsOptions,
|
{ showLatestNovels }: Plugin.PopularNovelsOptions,
|
||||||
@@ -18,25 +44,7 @@ class FaqWikiUs implements Plugin.PluginBase {
|
|||||||
const body = await fetchApi(this.site).then((res) => res.text());
|
const body = await fetchApi(this.site).then((res) => res.text());
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
|
|
||||||
const novels: Plugin.NovelItem[] = loadedCheerio(".wp-block-table > table > tbody > tr")
|
return this.parseNovels(loadedCheerio);
|
||||||
.map((index, element) => {
|
|
||||||
const name = loadedCheerio(element).find('a').text().replace(/–\s+Chapter\s+List\s+–.*$/i,'');
|
|
||||||
let cover = loadedCheerio(element).find("img").attr("data-ezsrc");
|
|
||||||
|
|
||||||
// Remove the appended query string
|
|
||||||
if (cover) {
|
|
||||||
cover = cover.replace(/\?ezimgfmt=.*$/, ''); // Regular expression magic!
|
|
||||||
}
|
|
||||||
|
|
||||||
const path = "" + loadedCheerio(element).find("a").attr("href")?.toString().replace(this.site, "").trim();
|
|
||||||
|
|
||||||
|
|
||||||
return { name, cover, path };
|
|
||||||
})
|
|
||||||
.get()
|
|
||||||
.filter((novel) => novel.name && novel.path);
|
|
||||||
|
|
||||||
return novels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseNovel(path: string): Promise<Plugin.SourceNovel> {
|
async parseNovel(path: string): Promise<Plugin.SourceNovel> {
|
||||||
@@ -47,23 +55,17 @@ class FaqWikiUs implements Plugin.PluginBase {
|
|||||||
path,
|
path,
|
||||||
name: ""
|
name: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
novel.name = loadedCheerio(".entry-title").text().replace("Novel – All Chapters", "").trim();
|
novel.name = loadedCheerio(".entry-title").text().replace("Novel – All Chapters", "").trim();
|
||||||
|
|
||||||
let cover = loadedCheerio(".wp-block-image").find("img").attr("data-ezsrc");
|
novel.cover = loadedCheerio(".wp-block-image").find("img").attr("src");
|
||||||
|
|
||||||
// Remove the appended query string
|
|
||||||
if (cover) {
|
|
||||||
cover = cover.replace(/\?ezimgfmt=.*$/, ''); // Regular expression magic!
|
|
||||||
}
|
|
||||||
novel.cover = cover;
|
|
||||||
|
|
||||||
novel.summary = loadedCheerio(".book-review-block__meta-item-value").text().trim();
|
novel.summary = loadedCheerio(".book-review-block__meta-item-value").text().trim();
|
||||||
|
|
||||||
const chapters: Plugin.ChapterItem[] = loadedCheerio(".lcp_catlist > li > a")
|
const chapters: Plugin.ChapterItem[] = loadedCheerio(".lcp_catlist > li > a")
|
||||||
.map((chapterIndex, element) => ({
|
.map((chapterIndex, element) => ({
|
||||||
name: loadedCheerio(element).text().replace(novel.name + "", "").replace("Novel" + "", "").trim(),
|
name: loadedCheerio(element).text().replace(novel.name + "", "").replace("Novel" + "", "").trim(),
|
||||||
path: ""+loadedCheerio(element).attr("href")?.toString().replace(this.site, "").trim(),
|
path: ""+loadedCheerio(element).attr("href")?.slice(this.site.length),
|
||||||
releaseTime: null,
|
|
||||||
chapterNumber: chapterIndex + 1,
|
chapterNumber: chapterIndex + 1,
|
||||||
}))
|
}))
|
||||||
.get();
|
.get();
|
||||||
@@ -97,32 +99,14 @@ class FaqWikiUs implements Plugin.PluginBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return chapterContent;
|
return chapterContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
|
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
|
||||||
const body = await fetchApi(this.site).then((res) => res.text());
|
const body = await fetchApi(this.site).then((res) => res.text());
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
|
|
||||||
const novels: Plugin.NovelItem[] = loadedCheerio(".wp-block-table > table > tbody > tr")
|
return this.parseNovels(loadedCheerio, searchTerm);
|
||||||
.map((index, element) => {
|
|
||||||
const name = loadedCheerio(element).find('a').text().replace(/–\s+Chapter\s+List\s+–.*$/i,'');
|
|
||||||
let cover = loadedCheerio(element).find("img").attr("data-ezsrc");
|
|
||||||
|
|
||||||
// Remove the appended query string
|
|
||||||
if (cover) {
|
|
||||||
cover = cover.replace(/\?ezimgfmt=.*$/, ''); // Regular expression magic!
|
|
||||||
}
|
|
||||||
|
|
||||||
const path = "" + loadedCheerio(element).find("a").attr("href")?.toString().replace(this.site, "").trim();
|
|
||||||
|
|
||||||
return { name, cover, path };
|
|
||||||
})
|
|
||||||
.get().filter((novel) => novel.name && novel.path);
|
|
||||||
const normalizedQuery = searchTerm.toLowerCase();
|
|
||||||
return novels.filter(novel => novel.name.toLowerCase().includes(normalizedQuery));
|
|
||||||
|
|
||||||
return novels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchImage = fetchFile;
|
fetchImage = fetchFile;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class LnMTLPlugin implements Plugin.PagePlugin {
|
|||||||
name = "LnMTL";
|
name = "LnMTL";
|
||||||
icon = "src/en/lnmtl/icon.png";
|
icon = "src/en/lnmtl/icon.png";
|
||||||
site = "https://lnmtl.com/";
|
site = "https://lnmtl.com/";
|
||||||
version = "1.0.0";
|
version = "1.0.1";
|
||||||
|
|
||||||
async sleep (ms: number) {
|
async sleep (ms: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
return new Promise(resolve => setTimeout(resolve, ms))
|
||||||
@@ -112,12 +112,6 @@ class LnMTLPlugin implements Plugin.PagePlugin {
|
|||||||
)[+page-1];
|
)[+page-1];
|
||||||
|
|
||||||
const chapter: Plugin.ChapterItem[] = [];
|
const chapter: Plugin.ChapterItem[] = [];
|
||||||
interface ChapterEntry {
|
|
||||||
number: number;
|
|
||||||
title: string;
|
|
||||||
slug: string;
|
|
||||||
created_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.sleep(1000);
|
await this.sleep(1000);
|
||||||
const volumeData = await fetchApi(
|
const volumeData = await fetchApi(
|
||||||
@@ -244,3 +238,10 @@ class LnMTLPlugin implements Plugin.PagePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default new LnMTLPlugin();
|
export default new LnMTLPlugin();
|
||||||
|
|
||||||
|
interface ChapterEntry {
|
||||||
|
number: number;
|
||||||
|
title: string;
|
||||||
|
slug: string;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CheerioAPI, load, load as parseHTML } from "cheerio";
|
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||||
import { Plugin } from "@typings/plugin";
|
import { Plugin } from "@typings/plugin";
|
||||||
import { Filters, FilterTypes } from "@libs/filterInputs";
|
import { Filters, FilterTypes } from "@libs/filterInputs";
|
||||||
@@ -6,7 +6,7 @@ import { Filters, FilterTypes } from "@libs/filterInputs";
|
|||||||
class RoyalRoad implements Plugin.PluginBase {
|
class RoyalRoad implements Plugin.PluginBase {
|
||||||
id = "royalroad";
|
id = "royalroad";
|
||||||
name = "Royal Road";
|
name = "Royal Road";
|
||||||
version = "1.0.0";
|
version = "1.0.1";
|
||||||
icon = "src/en/royalroad/icon.png";
|
icon = "src/en/royalroad/icon.png";
|
||||||
site = "https://www.royalroad.com/";
|
site = "https://www.royalroad.com/";
|
||||||
|
|
||||||
@@ -71,25 +71,27 @@ class RoyalRoad implements Plugin.PluginBase {
|
|||||||
.toArray()
|
.toArray()
|
||||||
.join(",");
|
.join(",");
|
||||||
|
|
||||||
const chapterlisting = JSON.parse(
|
const chapterJson = JSON.parse(loadedCheerio('script:contains("window.chapters")')
|
||||||
loadedCheerio('script:contains("window.chapters")')
|
|
||||||
.html()
|
.html()
|
||||||
?.match(/window.chapters = \[(.*?)\]/)![0]
|
?.match(/window.chapters = (.+])(?=;)/)![1] || "");
|
||||||
?.replace("window.chapters = ", "") || ""
|
|
||||||
);
|
|
||||||
|
|
||||||
interface ChapterEntry {
|
const volumeJson = JSON.parse(loadedCheerio('script:contains("window.chapters")')
|
||||||
title: string;
|
.html()
|
||||||
date: string;
|
?.match(/window.volumes = (.+])(?=;)/)![1] || "");
|
||||||
url: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const chapter : Plugin.ChapterItem[] = chapterlisting.map(
|
const chapter : Plugin.ChapterItem[] = chapterJson.map(
|
||||||
(chapter: ChapterEntry) => ({
|
(chapter: ChapterEntry) => {
|
||||||
|
const matchingVolume = volumeJson.find(
|
||||||
|
(volume: VolumeEntry) => volume.id === chapter.volumeId);
|
||||||
|
return {
|
||||||
name: chapter.title,
|
name: chapter.title,
|
||||||
path: chapter.url.slice(1),
|
path: chapter.url.slice(1),
|
||||||
releaseTime: chapter.date,
|
releaseTime: chapter.date,
|
||||||
}))
|
chapterNumber: chapter?.order,
|
||||||
|
page: matchingVolume ? matchingVolume.title : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
novel.chapters = chapter;
|
novel.chapters = chapter;
|
||||||
return novel;
|
return novel;
|
||||||
@@ -165,3 +167,19 @@ class RoyalRoad implements Plugin.PluginBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default new RoyalRoad();
|
export default new RoyalRoad();
|
||||||
|
|
||||||
|
interface ChapterEntry {
|
||||||
|
id: number;
|
||||||
|
volumeId: number;
|
||||||
|
title: string;
|
||||||
|
date: string;
|
||||||
|
order: number;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VolumeEntry {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
cover: string;
|
||||||
|
order: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user