fix: Update Plugins (#677)

* typo

* update

* fix

* fix

* update

* ifreedom

* fix

* fix ranobelib

* ...
This commit is contained in:
Rider21
2024-01-07 14:25:02 +03:00
committed by GitHub
parent 8a267561cb
commit f36e93d0a6
154 changed files with 68923 additions and 58660 deletions
+36
View File
@@ -0,0 +1,36 @@
import { Filters } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import defaultSettings from "./settings.json";
import { IfreedomMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list.map((metadata: IfreedomMetadata) => {
metadata.filters = Object.assign(defaultSettings.filters, metadata.filters);
console.log(`[${name}]: Generating`, metadata.id);
return generator(metadata);
});
};
const generator = function generator(metadata: IfreedomMetadata) {
const IfreedomTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const pluginScript = `
${IfreedomTemplate}
const plugin = new IfreedomPlugin(${JSON.stringify(metadata).replace(
/"type":"([^"]+)"/g,
'"type":FilterTypes.$1',
)});
export default plugin;
`.trim();
return {
lang: "russian",
filename: metadata.sourceName,
pluginScript,
};
};
+260
View File
@@ -0,0 +1,260 @@
{
"filters": {
"sort": {
"type": "Picker",
"label": "Сортировка:",
"options": [
{
"label": "По дате добавления",
"value": "По дате добавления"
},
{
"label": "По дате обновления",
"value": "По дате обновления"
},
{
"label": "По количеству глав",
"value": "По количеству глав"
},
{
"label": "По названию",
"value": "По названию"
},
{
"label": "По просмотрам",
"value": "По просмотрам"
},
{
"label": "По рейтингу",
"value": "По рейтингу"
}
],
"value": "По рейтингу"
},
"status": {
"type": "CheckboxGroup",
"label": "Статус:",
"options": [
{
"label": "Перевод активен",
"value": "Перевод активен"
},
{
"label": "Перевод приостановлен",
"value": "Перевод приостановлен"
},
{
"label": "Произведение завершено",
"value": "Произведение завершено"
}
],
"value": []
},
"lang": {
"type": "CheckboxGroup",
"label": "Язык:",
"options": [
{
"label": "Английский",
"value": "Английский"
},
{
"label": "Китайский",
"value": "Китайский"
},
{
"label": "Корейский",
"value": "Корейский"
},
{
"label": "Японский",
"value": "Японский"
}
],
"value": []
},
"genre": {
"type": "CheckboxGroup",
"label": "Жанры:",
"options": [
{
"label": "Боевик",
"value": "Боевик"
},
{
"label": "Боевые Искусства",
"value": "Боевые Искусства"
},
{
"label": "Вампиры",
"value": "Вампиры"
},
{
"label": "Виртуальный Мир",
"value": "Виртуальный Мир"
},
{
"label": "Гарем",
"value": "Гарем"
},
{
"label": "Героическое фэнтези",
"value": "Героическое фэнтези"
},
{
"label": "Детектив",
"value": "Детектив"
},
{
"label": "Дзёсэй",
"value": "Дзёсэй"
},
{
"label": "Драма",
"value": "Драма"
},
{
"label": "Игра",
"value": "Игра"
},
{
"label": "История",
"value": "История"
},
{
"label": "Киберпанк",
"value": "Киберпанк"
},
{
"label": "Комедия",
"value": "Комедия"
},
{
"label": "ЛитРПГ",
"value": "ЛитРПГ"
},
{
"label": "Меха",
"value": "Меха"
},
{
"label": "Милитари",
"value": "Милитари"
},
{
"label": "Мистика",
"value": "Мистика"
},
{
"label": "Научная Фантастика",
"value": "Научная Фантастика"
},
{
"label": "Повседневность",
"value": "Повседневность"
},
{
"label": "Постапокалипсис",
"value": "Постапокалипсис"
},
{
"label": "Приключения",
"value": "Приключения"
},
{
"label": "Психология",
"value": "Психология"
},
{
"label": "Романтика",
"value": "Романтика"
},
{
"label": "Сверхъестественное",
"value": "Сверхъестественное"
},
{
"label": "Сёдзё",
"value": "Сёдзё"
},
{
"label": "Сёнэн",
"value": "Сёнэн"
},
{
"label": "Сёнэн-ай",
"value": "Сёнэн-ай"
},
{
"label": "Спорт",
"value": "Спорт"
},
{
"label": "Сэйнэн",
"value": "Сэйнэн"
},
{
"label": "Сюаньхуа",
"value": "Сюаньхуа"
},
{
"label": "Трагедия",
"value": "Трагедия"
},
{
"label": "Триллер",
"value": "Триллер"
},
{
"label": "Ужасы",
"value": "Ужасы"
},
{
"label": "Фантастика",
"value": "Фантастика"
},
{
"label": "Фэнтези",
"value": "Фэнтези"
},
{
"label": "Школьная жизнь",
"value": "Школьная жизнь"
},
{
"label": "Экшн",
"value": "Экшн"
},
{
"label": "Эротика",
"value": "Эротика"
},
{
"label": "Этти",
"value": "Этти"
},
{
"label": "Яой",
"value": "Яой"
},
{
"label": "Adult",
"value": "Adult"
},
{
"label": "Mature",
"value": "Mature"
},
{
"label": "Xianxia",
"value": "Xianxia"
},
{
"label": "Xuanhuan",
"value": "Xuanhuan"
}
],
"value": []
}
}
}
+14
View File
@@ -0,0 +1,14 @@
[
{
"id": "ifreedom",
"sourceSite": "https://ifreedom.su",
"sourceName": "Свободный Мир Ранобэ",
"filters": {}
},
{
"id": "bookhamster",
"sourceSite": "https://bookhamster.ru",
"sourceName": "Bookhamster",
"filters": {}
}
]
+164
View File
@@ -0,0 +1,164 @@
import { fetchFile, fetchApi } from "@libs/fetch";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
// import { defaultCover } from "@libs/defaultCover";
export interface IfreedomMetadata {
id: string;
sourceSite: string;
sourceName: string;
filters?: Filters;
}
class IfreedomPlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
filters?: Filters;
constructor(metadata: IfreedomMetadata) {
this.id = metadata.id;
this.name = metadata.sourceName + "[ifreedom]";
this.icon = `multisrc/ifreedom/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.filters = metadata.filters;
}
async popularNovels(
page: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = this.site + "/vse-knigi/?sort=" +
(showLatestNovels ? "По дате обновления" : filters?.sort?.value || "По рейтингу");
if (filters?.status?.value instanceof Array) {
url += filters.status.value.map((i) => "&status[]=" + i).join("");
}
if (filters?.lang?.value instanceof Array) {
url += filters.lang.value.map((i) => "&lang[]=" + i).join("");
}
if (filters?.genre?.value instanceof Array) {
url += filters.genre.value.map((i) => "&genre[]=" + i).join("");
}
url += "&bpage=" + page;
const body = await fetchApi(url).then((res) => res.text());
const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = loadedCheerio(
"div.one-book-home > div.img-home a",
)
.map((index, element) => ({
name: loadedCheerio(element).attr("title") || "",
cover: loadedCheerio(element).find("img").attr("src"),
url: loadedCheerio(element).attr("href") || "",
}))
.get()
.filter((novel) => novel.name && novel.url);
return novels;
}
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(novelUrl).then((res) => res.text());
const loadedCheerio = parseHTML(body);
const novel: Plugin.SourceNovel = {
url: novelUrl,
name: loadedCheerio(".entry-title").text(),
cover: loadedCheerio(".img-ranobe > img").attr("src"),
summary: loadedCheerio('meta[name="description"]').attr("content"),
};
loadedCheerio("div.data-ranobe").each(function () {
switch (loadedCheerio(this).find("b").text()) {
case "Автор":
novel.author = loadedCheerio(this)
.find("div.data-value")
.text()
.trim();
break;
case "Жанры":
novel.genres = loadedCheerio("div.data-value > a")
.map((index, element) => loadedCheerio(element).text()?.trim())
.get()
.join(",");
break;
case "Статус книги":
novel.status = loadedCheerio("div.data-value")
.text()
.includes("активен")
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
if (novel.author == "Не указан") delete novel.author;
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio("div.li-ranobe").each(function () {
const name = loadedCheerio(this).find("a").text();
const url = loadedCheerio(this).find("a").attr("href");
if (!loadedCheerio(this).find("label.buy-ranobe").length && name && url) {
const releaseTime = loadedCheerio(this)
.find("div.li-col2-ranobe").text().trim();
chapters.push({ name, releaseTime, url });
}
});
novel.chapters = chapters.reverse();
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const body = await fetchApi(chapterUrl).then((res) => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio(".entry-content img").each(function () {
const srcset = loadedCheerio(this).attr("srcset")?.split?.(" ");
if (srcset?.length) {
const bestlink = srcset.filter((url) => url.startsWith("http")).unshift();
if (typeof bestlink == 'string') loadedCheerio(this).attr("src", bestlink);
}
});
const chapterText = loadedCheerio(".entry-content").html() || "";
return chapterText;
}
async searchNovels(
searchTerm: string,
page: number | undefined = 1,
): Promise<Plugin.NovelItem[]> {
const url =
this.site + "/vse-knigi/?searchname=" + searchTerm + "&bpage=" + page;
const result = await fetchApi(url).then((res) => res.text());
const loadedCheerio = parseHTML(result);
const novels: Plugin.NovelItem[] = loadedCheerio(
"div.one-book-home > div.img-home a",
)
.map((index, element) => ({
name: loadedCheerio(element).attr("title") || "",
cover: loadedCheerio(element).find("img").attr("src"),
url: loadedCheerio(element).attr("href") || "",
}))
.get()
.filter((novel) => novel.name && novel.url);
return novels;
}
fetchImage = fetchFile;
}
+4 -5
View File
@@ -13,7 +13,7 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
let d = false;
const filters: Filters = {};
for (const k in p.filters) {
const f = p.filters[k as "sort" | "genres"];
const f = p.filters[k as keyof typeof p.filters];
if (f) {
filters[k] = {
...f,
@@ -39,10 +39,9 @@ const generator = function generator(metadata: MadaraMetadata) {
const pluginScript = `
${madaraTemplate}
const plugin = new MadaraPlugin(${JSON.stringify(metadata).replace(
/"type":"Picker"/g,
`"type":FilterTypes.Picker`
)});
const plugin = new MadaraPlugin(${
JSON.stringify(metadata).replace(/"type":"([^"]+)"/g, '"type":FilterTypes.$1')
});
export default plugin;
`;
return {
+8 -7
View File
@@ -14,7 +14,8 @@ interface MadaraOptionPath {
chapter?: string;
}
const MadaraDefaultPath: MadaraOptionPath = {
const MadaraDefaultPath = {
genres: "novel-genre",
novels: "novel",
novel: "novel",
chapter: "novel",
@@ -69,12 +70,12 @@ class MadaraPlugin implements Plugin.PluginBase {
const novels: Plugin.NovelItem[] = [];
let url = this.site;
if (filters?.genres && this.options?.path?.genres) {
url += this.options?.path?.genres + filters.genres;
if (filters?.genres?.value) {
url += (this.options?.path?.genres || MadaraDefaultPath.genres) +
"/" +
filters.genres.value;
} else {
url += this.options?.path?.novels
? this.options.path.novels
: MadaraDefaultPath.novels;
url += this.options?.path?.novels || MadaraDefaultPath.novels;
}
url +=
@@ -82,7 +83,7 @@ class MadaraPlugin implements Plugin.PluginBase {
pageNo +
"/" +
"?m_orderby=" +
(showLatestNovels ? "latest" : filters?.sort || "rating");
(showLatestNovels ? "latest" : filters?.sort?.value || "rating");
const body = await fetchApi(url).then((res) => res.text());
View File
+44 -30
View File
@@ -1,45 +1,59 @@
import { FilterTypes, Filters } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import defaultSettings from "./settings.json";
import { ReadwnMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
export const generateAll: ScrpitGeneratorFunction = function () {
return list
.map((p) => {
let d = false;
const filters: Filters = {};
for (const k in p.filters) {
const f = p.filters[k as keyof typeof p.filters];
if (f) {
filters[k] = {
...f,
type: FilterTypes.Picker,
};
}
}
return { ...p, filters: d ? undefined : filters };
})
.map((metadata: ReadwnMetadata) => {
return generator(metadata);
});
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list
.map<ReadwnMetadata>((p) => {
p.filters.tags.options.unshift(...defaultSettings.filters.tags.options);
p.filters.genres.options.unshift(...defaultSettings.filters.genres.options);
p.filters = Object.assign(defaultSettings.filters, p.filters);
const d = false;
const filters: Filters = {};
for (const k in p.filters) {
const f = p.filters[k as keyof typeof p.filters];
if (f) {
filters[k] = {
...f,
type: FilterTypes.Picker,
};
}
}
return { ...p, filters: d ? undefined : filters };
})
.map((metadata: ReadwnMetadata) => {
console.log(`[${name}]: Generating`, metadata.id);
return generator(metadata);
});
};
const generator = function generator(metadata: ReadwnMetadata) {
const rulateTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const readwnTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const pluginScript = `
${rulateTemplate}
const plugin = new ReadwnPlugin(${JSON.stringify(metadata)});
//metadata.filters = {
// sort: { ...defaultSettings.filters.sort, type: FilterTypes.Picker },
// status: { ...defaultSettings.filters.status, type: FilterTypes.Picker },
// ...metadata.filters,
//};
const pluginScript = `
${readwnTemplate}
const plugin = new ReadwnPlugin(${
JSON.stringify(metadata).replace(/"type":"([^"]+)"/g, '"type":FilterTypes.$1')
});
export default plugin;
`.trim();
return {
lang: "english",
filename: metadata.sourceName,
pluginScript,
};
return {
lang: "english",
filename: metadata.sourceName,
pluginScript,
};
};
+197
View File
@@ -0,0 +1,197 @@
{
"filters": {
"sort": {
"label": "Sort By",
"options": [
{
"label": "New",
"value": "newstime"
},
{
"label": "Popular",
"value": "onclick"
},
{
"label": "Updates",
"value": "lastdotime"
}
],
"value": "newstime",
"type": "Picker"
},
"status": {
"label": "Status",
"options": [
{
"label": "All",
"value": "all"
},
{
"label": "Completed",
"value": "Completed"
},
{
"label": "Ongoing",
"value": "Ongoing"
}
],
"value": "all",
"type": "Picker"
},
"genres": {
"options": [
{
"label": "All",
"value": "all"
},
{
"label": "Action",
"value": "action"
},
{
"label": "Adventure",
"value": "adventure"
},
{
"label": "Comedy",
"value": "comedy"
},
{
"label": "Contemporary Romance",
"value": "contemporary-romance"
},
{
"label": "Drama",
"value": "drama"
},
{
"label": "Eastern Fantasy",
"value": "eastern-fantasy"
},
{
"label": "Fantasy",
"value": "fantasy"
},
{
"label": "Fantasy Romance",
"value": "fantasy-romance"
},
{
"label": "Game",
"value": "game"
},
{
"label": "Gender Bender",
"value": "gender-bender"
},
{
"label": "Harem",
"value": "harem"
},
{
"label": "Historical",
"value": "historical"
},
{
"label": "Horror",
"value": "horror"
},
{
"label": "Josei",
"value": "josei"
},
{
"label": "Lolicon",
"value": "lolicon"
},
{
"label": "Magical Realism",
"value": "magical-realism"
},
{
"label": "Martial Arts",
"value": "martial-arts"
},
{
"label": "Mecha",
"value": "mecha"
},
{
"label": "Mystery",
"value": "mystery"
},
{
"label": "Psychological",
"value": "psychological"
},
{
"label": "Romance",
"value": "romance"
},
{
"label": "School Life",
"value": "school-life"
},
{
"label": "Sci-fi",
"value": "sci-fi"
},
{
"label": "Seinen",
"value": "seinen"
},
{
"label": "Shoujo",
"value": "shoujo"
},
{
"label": "Shounen",
"value": "shounen"
},
{
"label": "Shounen Ai",
"value": "shounen-ai"
},
{
"label": "Slice of Life",
"value": "slice-of-life"
},
{
"label": "Sports",
"value": "sports"
},
{
"label": "Supernatural",
"value": "supernatural"
},
{
"label": "Tragedy",
"value": "tragedy"
},
{
"label": "Video Games",
"value": "video-games"
},
{
"label": "Wuxia",
"value": "wuxia"
},
{
"label": "Xianxia",
"value": "xianxia"
},
{
"label": "Xuanhuan",
"value": "xuanhuan"
},
{
"label": "Yaoi",
"value": "yaoi"
}
]
},
"tags": {
"options": [{ "label": "Default", "value": "" }]
}
}
}
File diff suppressed because it is too large Load Diff
+144 -176
View File
@@ -1,5 +1,5 @@
import { fetchFile, fetchApi } from "@libs/fetch";
import { Filters } from "@libs/filterInputs";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
@@ -7,205 +7,173 @@ import { parseMadaraDate } from "@libs/parseMadaraDate";
// import { defaultCover } from "@libs/defaultCover";
export interface ReadwnMetadata {
id: string;
sourceSite: string;
sourceName: string;
filters?: Filters;
id: string;
sourceSite: string;
sourceName: string;
filters?: Filters;
}
class ReadwnPlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
filters?: Filters | undefined;
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
filters?: Filters;
constructor(metadata: ReadwnMetadata) {
this.id = metadata.id;
this.name = metadata.sourceName + "[readwn]";
const iconFileName = metadata.sourceName
.replace(/\s+/g, "")
.toLowerCase();
this.icon = `multisrc/readwn/icons/${iconFileName}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.filters = metadata.filters;
constructor(metadata: ReadwnMetadata) {
this.id = metadata.id;
this.name = metadata.sourceName + "[readwn]";
const iconFileName = metadata.sourceName.replace(/\s+/g, "").toLowerCase();
this.icon = `multisrc/readwn/icons/${iconFileName}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.filters = metadata.filters;
}
async popularNovels(
pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = this.site + "/list/";
url += (filters?.genres?.value || "all") + "/";
url += (filters?.status?.value || "all") + "-";
url += showLatestNovels ? "lastdotime" : filters?.sort?.value || "newstime";
url += "-" + (pageNo - 1) + ".html";
if (filters?.tags?.value) { //only 1 page
url = this.site + "/tags/" + filters.tags.value + "-0.html";
}
async popularNovels(
pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const baseUrl = this.site;
const body = await fetchApi(url).then((res) => res.text());
const loadedCheerio = parseHTML(body);
let url = baseUrl + "/list/";
url += (filters?.genres || "all") + "/";
url += (filters?.status || "all") + "-";
url +=
(showLatestNovels ? "lastdotime" : filters?.sort || "newstime") +
"-";
url += pageNo - 1 + ".html";
const novels: Plugin.NovelItem[] = loadedCheerio("li.novel-item")
.map((index, element) => ({
name: loadedCheerio(element).find("h4").text(),
cover: this.site +
loadedCheerio(element).find(".novel-cover > img").attr("data-src"),
url: this.site + loadedCheerio(element).find("a").attr("href"),
}))
.get();
if (filters?.tags) {
url = baseUrl + "/tags/" + filters.tags + "-0.html";
}
return novels;
}
const result = await fetchApi(url);
const body = await result.text();
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(novelUrl).then((res) => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio("li.novel-item").each(function () {
const name = loadedCheerio(this).find("h4").text();
const url = loadedCheerio(this).find("a").attr("href");
const cover = loadedCheerio(this)
.find(".novel-cover > img")
.attr("data-src");
if (!name || !url) return;
const loadedCheerio = parseHTML(body);
const novel: Plugin.SourceNovel = {
url: novelUrl,
};
novels.push({
name: name,
cover: baseUrl + cover,
url: baseUrl + url,
});
});
novel.name = loadedCheerio("h1.novel-title").text();
novel.author = loadedCheerio("span[itemprop=author]").text();
novel.cover = this.site + loadedCheerio("figure.cover > img").attr("data-src");
return novels;
}
novel.summary = loadedCheerio(".summary")
.text()
.replace("Summary", "")
.trim();
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const baseUrl = this.site;
const result = await fetchApi(novelUrl);
const body = await result.text();
novel.genres = loadedCheerio("div.categories > ul > li")
.map((index, element) => loadedCheerio(element).text()?.trim())
.get()
.join(",");
let loadedCheerio = parseHTML(body);
const novel: Plugin.SourceNovel = {
url: novelUrl,
loadedCheerio("div.header-stats > span").each(function () {
if (loadedCheerio(this).find("small").text() === "Status") {
novel.status = loadedCheerio(this).find("strong").text();
}
});
const latestChapterNo = parseInt(
loadedCheerio(".header-stats")
.find("span > strong")
.first()
.text()
.trim(),
);
const chapters: Plugin.ChapterItem[] = loadedCheerio(".chapter-list li")
.map((index, element) => {
const name = loadedCheerio(element).find("a .chapter-title").text().trim();
const url = loadedCheerio(element).find("a").attr("href")?.trim();
const releaseTime = loadedCheerio(element).find("a .chapter-update").text().trim();
if (!name || !url) return null;
return {
name,
releaseTime: parseMadaraDate(releaseTime),
url: this.site + url,
};
})
.get()
.filter((chapter) => chapter);
novel.name = loadedCheerio("h1.novel-title").text();
novel.author = loadedCheerio("span[itemprop=author]").text();
novel.cover =
baseUrl + loadedCheerio("figure.cover > img").attr("data-src");
if (latestChapterNo > chapters.length) {
const lastChapterNo = parseInt(
chapters[chapters.length - 1].url.match(/_(\d+)\.html/)?.[1] || "",
10,
);
novel.summary = loadedCheerio(".summary")
.text()
.replace("Summary", "")
.trim();
novel.genres = loadedCheerio("div.categories > ul > li")
.map((index, element) => loadedCheerio(element).text()?.trim())
.get()
.join(",");
loadedCheerio("div.header-stats > span").each(function () {
if (loadedCheerio(this).find("small").text() === "Status") {
novel.status = loadedCheerio(this).find("strong").text();
}
for (let i = (lastChapterNo || chapters.length) + 1; i <= latestChapterNo; i++) {
chapters.push({
name: "Chapter " + i,
releaseTime: null,
url: novelUrl.replace(".html", "_" + i + ".html"),
});
const chapters: Plugin.ChapterItem[] = [];
const latestChapterNo = parseInt(
loadedCheerio(".header-stats")
.find("span > strong")
.first()
.text()
.trim()
);
let lastChapterNo = 1;
loadedCheerio(".chapter-list li").each(function () {
const name = loadedCheerio(this)
.find("a .chapter-title")
.text()
.trim();
const url = loadedCheerio(this).find("a").attr("href")?.trim();
const releaseTime = loadedCheerio(this)
.find("a .chapter-update")
.text()
.trim();
lastChapterNo = parseInt(
loadedCheerio(this).find("a .chapter-no").text().trim()
);
if (!name || !url) return;
chapters.push({
name,
releaseTime: parseMadaraDate(releaseTime),
url: baseUrl + url,
});
});
const novelId =
"/" + novelUrl.replace(".html", "").replace(this.site, "") + "_";
// Itterate once more before loop to finish off
lastChapterNo++;
for (let i = lastChapterNo; i <= latestChapterNo; i++) {
const name = "Chapter " + i;
const releaseTime = null;
const url = baseUrl + novelId + i + ".html";
chapters.push({ name, releaseTime, url });
}
novel.chapters = chapters;
return novel;
}
}
async parseChapter(chapterUrl: string): Promise<string> {
const result = await fetchApi(chapterUrl);
const body = await result.text();
novel.chapters = chapters;
return novel;
}
const loadedCheerio = parseHTML(body);
async parseChapter(chapterUrl: string): Promise<string> {
const body = await fetchApi(chapterUrl).then((res) => res.text());
const loadedCheerio = parseHTML(body);
const chapterText = loadedCheerio(".chapter-content").html();
return chapterText || "";
}
const chapterText = loadedCheerio(".chapter-content").html() || "";
return chapterText;
}
async searchNovels(
searchTerm: string
//page: number | undefined = 1,
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const baseUrl = this.site;
const searchUrl = baseUrl + "/e/search/index.php";
async searchNovels(keyboard: string): Promise<Plugin.NovelItem[]> {
const result = await fetchApi(this.site + "/e/search/index.php", {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Referer: this.site + "/search.html",
Origin: this.site,
"user-agent":
this.userAgent ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
},
method: "POST",
body: JSON.stringify({
show: "title",
tempid: 1,
tbname: "news",
keyboard,
}),
}).then((res) => res.text());
const loadedCheerio = parseHTML(result);
const result = await fetchApi(searchUrl, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Referer: baseUrl + "search.html",
Origin: baseUrl,
"user-agent":
this.userAgent ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
},
method: "POST",
body: JSON.stringify({
show: "title",
tempid: 1,
tbname: "news",
keyboard: searchTerm,
}),
});
const body = await result.text();
const novels: Plugin.NovelItem[] = loadedCheerio("li.novel-item")
.map((index, element) => ({
name: loadedCheerio(element).find("h4").text(),
cover: this.site + loadedCheerio(element).find("img").attr("data-src"),
url: this.site + loadedCheerio(element).find("a").attr("href"),
}))
.get();
const loadedCheerio = parseHTML(body);
loadedCheerio("li.novel-item").each(function () {
const name = loadedCheerio(this).find("h4").text();
const url = loadedCheerio(this).find("a").attr("href");
const cover = loadedCheerio(this).find("img").attr("data-src");
if (!name || !url) return;
return novels;
}
novels.push({ name, cover: baseUrl + cover, url: baseUrl + url });
});
return novels;
}
fetchImage = fetchFile;
fetchImage = fetchFile;
}
View File
+40 -30
View File
@@ -1,45 +1,55 @@
import { Filters, FilterTypes } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import defaultSettings from "./settings.json";
import { RulateMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
export const generateAll: ScrpitGeneratorFunction = function () {
return list
.map((p) => {
let d = false;
const filters: Filters = {};
for (const k in p.filters) {
const f = p.filters[k as keyof typeof p.filters];
if (f) {
filters[k] = {
...f,
type: FilterTypes.Picker,
};
}
}
return { ...p, filters: d ? undefined : filters };
})
.map((metadata: RulateMetadata) => {
return generator(metadata);
});
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list
.map<RulateMetadata>((p) => {
if (p.filters) {
p.filters.cat.options.unshift(...defaultSettings.filters.cat.options);
}
p.filters = Object.assign(defaultSettings.filters, p.filters);
let d = false;
const filters: any = {};
for (const k in p.filters) {
const f = p.filters[k as keyof typeof p.filters];
if (f) {
filters[k] = {
...f,
type: FilterTypes[f.type as keyof typeof FilterTypes],
};
}
}
return { ...p, filters: d ? undefined : filters };
})
.map((metadata: RulateMetadata) => {
console.log(`[${name}]: Generating`, metadata.id);
return generator(metadata);
});
};
const generator = function generator(metadata: RulateMetadata) {
const rulateTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const rulateTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const pluginScript = `
${rulateTemplate}
const plugin = new RulatePlugin(${JSON.stringify(metadata)});
const pluginScript = `
${rulateTemplate}
const plugin = new RulatePlugin(${JSON.stringify(metadata)
.replace(/"type":"([^"]+)"/g, '"type":FilterTypes.$1')
.replace(/\.XCheckbox/g, ".ExcludableCheckboxGroup") //remember to redo
.replace(/\.Checkbox/g, ".CheckboxGroup")});
export default plugin;
`.trim();
return {
lang: "russian",
filename: metadata.sourceName,
pluginScript,
};
return {
lang: "russian",
filename: metadata.sourceName,
pluginScript,
};
};
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+233 -240
View File
@@ -1,273 +1,266 @@
import { fetchFile, fetchApi } from "@libs/fetch";
import { Filters } from "@libs/filterInputs";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
// import { defaultCover } from "@libs/defaultCover";
export interface RulateMetadata {
id: string;
sourceSite: string;
sourceName: string;
filters?: Filters;
id: string;
sourceSite: string;
sourceName: string;
filters?: Filters;
}
class RulatePlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
filters?: Filters | undefined;
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
filters?: Filters | undefined;
constructor(metadata: RulateMetadata) {
this.id = metadata.id;
this.name = metadata.sourceName + "[rulate]";
const iconFileName = metadata.sourceName
.replace(/\s+/g, "")
.toLowerCase();
this.icon = `multisrc/rulate/icons/${iconFileName}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.filters = metadata.filters;
constructor(metadata: RulateMetadata) {
this.id = metadata.id;
this.name = metadata.sourceName + "[rulate]";
const iconFileName = metadata.sourceName.replace(/\s+/g, "").toLowerCase();
this.icon = `multisrc/rulate/icons/${iconFileName}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.filters = metadata.filters;
}
async popularNovels(
pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const baseUrl = this.site;
let url = baseUrl + "/search?t=";
url += "&cat=" + (filters?.cat?.value || "0");
url += "&s_lang=" + (filters?.s_lang?.value || "0");
url += "&t_lang=" + (filters?.t_lang?.value || "0");
url += "&type=" + (filters?.type?.value || "0");
url += "&sort=" + (showLatestNovels ? "4" : filters?.sort?.value || "6");
url += "&atmosphere=" + (filters?.atmosphere?.value || "0");
url += "&adult=" + (filters?.adult?.value || "0");
if (filters?.genres?.value instanceof Array) {
url += filters.genres.value.map((i) => "&genres[]=" + i).join("");
}
async popularNovels(
pageNo: number,
{
filters,
showLatestNovels,
}: Plugin.PopularNovelsOptions<typeof this.filters>
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const baseUrl = this.site;
//if (filters?.genres?.value?.exclude instanceof Array) {
// url += filters.genres.value.exclude
// ?.map((i) => "&genres_ex[]=" + i)
// .join("");
//}
let url = baseUrl + "/search?t=";
url += "&cat=" + (filters?.cat || "0");
url += "&s_lang=" + (filters?.s_lang || "0");
url += "&t_lang=" + (filters?.t_lang || "0");
url += "&type=" + (filters?.type || "0");
url += "&sort=" + (showLatestNovels ? "4" : filters?.sort || "6");
url += "&atmosphere=" + (filters?.atmosphere || "0");
url += "&adult=" + (filters?.adult || "0");
if (filters?.tags?.value instanceof Array) {
url += filters.tags.value.map((i) => "&tags[]=" + i).join("");
}
if (filters?.genres instanceof Array) {
url += filters.genres.map((i) => "&genres[]=" + i).join("");
//if (filters?.tags?.value?.exclude instanceof Array) {
// url += filters.tags.value.exclude
// ?.map((i) => "&tags_ex[]=" + i)
// .join("");
//}
if (filters?.fandoms?.value instanceof Array) {
url += filters.fandoms.value.map((i) => "&fandoms[]=" + i).join("");
}
// if (filters?.fandoms?.value?.exclude instanceof Array) {
// url += filters.fandoms.value.exclude
// .map((i) => "&fandoms_ex[]=" + i)
// .join("");
// }
if (filters?.trash?.value instanceof Array) {
url += filters.trash.value.map((i) => "&" + i + "=1").join("");
}
url += "&Book_page=" + pageNo;
const body = await fetchApi(url).then((res) => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio(
'ul[class="search-results"] > li:not([class="ad_type_catalog"])',
).each(function () {
loadedCheerio(this).find("p > a").text();
const name = loadedCheerio(this).find("p > a").text();
const cover = loadedCheerio(this).find("img").attr("src");
const url = loadedCheerio(this).find("p > a").attr("href");
if (!name || !url) return;
novels.push({ name, cover: baseUrl + cover, url: baseUrl + url });
});
return novels;
}
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const baseUrl = this.site;
const novel: Plugin.SourceNovel = {
url: novelUrl,
};
let result = await fetchApi(novelUrl);
if (result.url.includes("mature?path=")) {
const formData = new FormData();
formData.append("path", novelUrl);
formData.append("ok", "Да");
await fetchApi(result.url, {
method: "POST",
body: formData,
});
result = await fetchApi(novelUrl);
}
const body = await result.text();
const loadedCheerio = parseHTML(body);
novel.name = loadedCheerio(
'div[class="container"] > div > div > h1, div.span8:nth-child(1) > h1:nth-child(2)',
)
.text()
.trim();
if (novel.name?.includes?.("[")) {
novel.name = novel.name.split("[")[0].trim();
}
novel.cover =
baseUrl + loadedCheerio('div[class="images"] > div img').attr("src");
novel.summary =
loadedCheerio("#Info > div:nth-child(3), .book-description").text().trim();
novel.author = loadedCheerio(
".book-stats-icons_author > span:nth-child(2) > a:nth-child(1)",
).text();
const genres: string[] = [];
loadedCheerio("div.span5 > p, .span5 > div:nth-child(2) > p").each(
function () {
switch (loadedCheerio(this).find("strong").text()) {
case "Автор:":
novel.author = loadedCheerio(this).find("em > a").text().trim();
break;
case "Выпуск:":
novel.status =
loadedCheerio(this).find("em").text().trim() === "продолжается"
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
case "Тэги:":
loadedCheerio(this)
.find("em > a")
.each(function () {
genres.push(loadedCheerio(this).text());
});
break;
case "Жанры:":
loadedCheerio(this)
.find("em > a")
.each(function () {
genres.push(loadedCheerio(this).text());
});
break;
}
},
);
if (filters?.genres_ex instanceof Array) {
url += filters.genres_ex.map((i) => "&genres_ex[]=" + i).join("");
}
if (genres.length) {
novel.genres = genres.reverse().join(",");
}
if (filters?.tags instanceof Array) {
url += filters.tags.map((i) => "&tags[]=" + i).join("");
}
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio("table > tbody > tr.chapter_row").each(function () {
const chapterName = loadedCheerio(this)
.find('td[class="t"] > a')
.text()
.trim();
const releaseDate = loadedCheerio(this)
.find("td > span")
.attr("title")
?.trim();
const chapterUrl = loadedCheerio(this)
.find('td[class="t"] > a')
.attr("href");
if (filters?.tags_ex instanceof Array) {
url += filters.tags_ex.map((i) => "&tags_ex[]=" + i).join("");
}
if (filters?.fandoms instanceof Array) {
url += filters.fandoms.map((i) => "&fandoms[]=" + i).join("");
}
if (filters?.fandoms_ex instanceof Array) {
url += filters.fandoms_ex.map((i) => "&fandoms_ex[]=" + i).join("");
}
if (filters?.trash instanceof Array) {
url += filters.trash.map((i) => "&" + i + "=1").join("");
}
url += "&Book_page=" + pageNo;
const result = await fetchApi(url);
const body = await result.text();
const loadedCheerio = parseHTML(body);
loadedCheerio(
'ul[class="search-results"] > li:not([class="ad_type_catalog"])'
).each(function () {
loadedCheerio(this).find("p > a").text();
const name = loadedCheerio(this).find("p > a").text();
const cover = loadedCheerio(this).find("img").attr("src");
const url = loadedCheerio(this).find("p > a").attr("href");
if (!name || !url) return;
novels.push({ name, cover: baseUrl + cover, url: baseUrl + url });
if (
!loadedCheerio(this).find('td > span[class="disabled"]').length &&
releaseDate
) {
chapters.push({
name: chapterName,
releaseTime: releaseDate,
url: baseUrl + chapterUrl,
});
}
});
return novels;
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const baseUrl = this.site;
let result = await fetchApi(chapterUrl);
if (result.url.includes("mature?path=")) {
const formData = new FormData();
formData.append("ok", "Да");
await fetchApi(result.url, {
method: "POST",
body: formData,
});
result = await fetchApi(chapterUrl);
}
const body = await result.text();
const loadedCheerio = parseHTML(body);
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const baseUrl = this.site;
const novel: Plugin.SourceNovel = {
url: novelUrl,
};
let result = await fetchApi(novelUrl);
if (result.url.includes("mature?path=")) {
const formData = new FormData();
formData.append("path", novelUrl);
formData.append("ok", "Да");
loadedCheerio(".content-text img").each(function () {
if (!loadedCheerio(this).attr("src")?.startsWith("http")) {
const src = loadedCheerio(this).attr("src");
loadedCheerio(this).attr("src", baseUrl + src);
}
});
await fetchApi(result.url, {
method: "POST",
body: formData,
});
const chapterText = loadedCheerio(".content-text").html();
return chapterText || "";
}
result = await fetchApi(novelUrl);
}
const body = await result.text();
const loadedCheerio = parseHTML(body);
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const result = await fetchApi(
this.site + "/search/autocomplete?query=" + searchTerm,
);
const json = (await result.json()) as response[];
novel.name = loadedCheerio(
'div[class="container"] > div > div > h1, div.span8:nth-child(1) > h1:nth-child(2)'
)
.text()
.trim();
novel.cover =
baseUrl +
loadedCheerio('div[class="images"] > div img').attr("src");
novel.summary = loadedCheerio(
"#Info > div:nth-child(3), .book-description"
).text();
novel.author = loadedCheerio(
".book-stats-icons_author > span:nth-child(2) > a:nth-child(1)"
).text();
const genres: string[] = [];
json.forEach((novel) => {
const name = novel.title_one + " / " + novel.title_two;
if (!novel.url) return;
loadedCheerio("div.span5 > p, .span5 > div:nth-child(2) > p").each(
function () {
switch (loadedCheerio(this).find("strong").text()) {
case "Автор:":
novel.author = loadedCheerio(this)
.find("em > a")
.text()
.trim();
break;
case "Выпуск:":
novel.status =
loadedCheerio(this).find("em").text().trim() ===
"продолжается"
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
case "Тэги:":
loadedCheerio(this)
.find("em > a")
.each(function () {
genres.push(loadedCheerio(this).text());
});
break;
case "Жанры:":
loadedCheerio(this)
.find("em > a")
.each(function () {
genres.push(loadedCheerio(this).text());
});
break;
}
}
);
novels.push({
name,
cover: this.site + novel.img,
url: this.site + novel.url,
});
});
if (genres.length) {
novel.genres = genres.reverse().join(",");
}
return novels;
}
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio("table > tbody > tr.chapter_row").each(function () {
const chapterName = loadedCheerio(this)
.find('td[class="t"] > a')
.text()
.trim();
const releaseDate = loadedCheerio(this)
.find("td > span")
.attr("title")
?.trim();
const chapterUrl = loadedCheerio(this)
.find('td[class="t"] > a')
.attr("href");
if (
loadedCheerio(this).find('td > span[class="disabled"]').length <
1 &&
releaseDate
) {
chapters.push({
name: chapterName,
releaseTime: releaseDate,
url: baseUrl + chapterUrl,
});
}
});
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const baseUrl = this.site;
let result = await fetchApi(chapterUrl);
if (result.url.includes("mature?path=")) {
const formData = new FormData();
formData.append("ok", "Да");
await fetchApi(result.url, {
method: "POST",
body: formData,
});
result = await fetchApi(chapterUrl);
}
const body = await result.text();
const loadedCheerio = parseHTML(body);
loadedCheerio(".content-text img").each(function () {
if (!loadedCheerio(this).attr("src")?.startsWith("http")) {
const src = loadedCheerio(this).attr("src");
loadedCheerio(this).attr("src", baseUrl + src);
}
});
const chapterText = loadedCheerio(".content-text").html();
return chapterText || "";
}
async searchNovels(
searchTerm: string
//page: number | undefined = 1,
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const result = await fetchApi(
this.site + "/search/autocomplete?query=" + searchTerm
);
const json = (await result.json()) as response[];
json.forEach((novel) => {
const name = novel.title_one + " / " + novel.title_two;
if (!novel.url) return;
novels.push({
name,
cover: this.site + novel.img,
url: this.site + novel.url,
});
});
return novels;
}
fetchImage = fetchFile;
fetchImage = fetchFile;
}
interface response {
id: number;
title_one: string;
title_two: string;
url: string;
img: string;
id: number;
title_one: string;
title_two: string;
url: string;
img: string;
}
+21 -182
View File
@@ -1,191 +1,30 @@
import { ScrpitGeneratorFunction } from "../generate";
import { WPmangaStreamMetadata } from "./template";
import list from "./sources.json";
type sourceData = (typeof list)[number];
import { readFileSync } from "fs";
import path from "path";
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list.map((source) => {
console.log(`[${name}] Generating:`, source.id);
return generator(source);
});
return list.map((source) => {
console.log(`[${name}] Generating:`, source.id);
return generator(source);
});
};
const generator = function generator(sourceJson: sourceData) {
const pluginId = sourceJson.id;
const sourceName = sourceJson.sourceName;
const site = sourceJson.sourceSite;
const reverseChapters = sourceJson.reverseChapters;
const iconFileName = sourceName.split(".")[0].toLowerCase() + ".png";
const pluginScript = `
import { CheerioAPI, load } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
const generator = function generator(source: WPmangaStreamMetadata) {
const WPmangaStreamTemplate = readFileSync(path.join(__dirname, "template.ts"),{
encoding: "utf-8",
});
class LightNovelFRPlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
constructor() {
this.id = "${pluginId}";
this.name = "${sourceName}[wpmangastream]";
this.icon = "multisrc/wpmangastream/icons/${pluginId}.png";
this.site = "${site}";
this.version = "1.0.0";
this.userAgent = "''";
this.cookieString = "''";
}
const pluginScript = `
${WPmangaStreamTemplate}
const plugin = new WPmangaStreamPlugin(${JSON.stringify(source)});
export default plugin;
`.trim();
async popularNovels(page: number): Promise<Plugin.NovelItem[]> {
let url = this.site + 'series/?page=' + page + '&status=&order=popular';
const body = await(await fetchApi(url, {})).text();
const loadedCheerio = load(body);
let novels: Plugin.NovelItem[] = [];
loadedCheerio('article.maindet').each(function () {
const novelName = loadedCheerio(this).find('h2').text();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
const novelUrl = loadedCheerio(this).find('h2 a').attr('href');
if (!novelUrl) return;
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(await fetchApi(url, {})).text();
let loadedCheerio = load(body);
const novel: Plugin.SourceNovel = { url };
// novel.url = url;
novel.name = loadedCheerio('h1.entry-title').text();
novel.cover =
loadedCheerio('img.wp-post-image').attr('data-src') ||
loadedCheerio('img.wp-post-image').attr('src');
novel.status = loadedCheerio('div.sertostat > span').attr('class');
loadedCheerio('div.serl > span').each(function () {
const detailName = loadedCheerio(this).text().trim();
const detail = loadedCheerio(this).next().text().trim();
switch (detailName) {
case 'الكاتب':
case 'Author':
case 'Auteur':
novel.author = detail;
break;
}
});
novel.genres = loadedCheerio('.sertogenre')
.children('a')
.map((i, el) => loadedCheerio(el).text())
.toArray()
.join(',');
let summary = loadedCheerio('.sersys > p').siblings().remove("div").end();
novel.summary = ""
for (let i = 0; i < summary.length; i++) {
const p = summary[i];
novel.summary += loadedCheerio(p).text().trim() + "\\n\\n";
}
let novelChapters:Plugin.ChapterItem[] = [];
loadedCheerio('.eplister')
.find('li')
.each(function () {
const chapterName =
loadedCheerio(this).find('.epl-num').text() +
' - ' +
loadedCheerio(this).find('.epl-title').text();
const releaseDate = loadedCheerio(this).find('.epl-date').text().trim();
const chapterUrl = loadedCheerio(this).find('a').attr('href');
if (!chapterUrl) return;
const chapter = {
name: chapterName,
url: chapterUrl,
releaseDate,
};
novelChapters.push(chapter);
});
novel.chapters = novelChapters;
${reverseChapters ? "if (novel.chapters) novel.chapters.reverse()" : ""}
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const url = chapterUrl;
const body = await(await fetchApi(url, {})).text();
const loadedCheerio = load(body);
let chapterText = loadedCheerio('.epcontent').html() || '';
return chapterText;
};
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const url = this.site + "?s=" + searchTerm;
const body = await(await fetchApi(url, {})).text();
const loadedCheerio = load(body);
let novels: Plugin.NovelItem[] = [];
loadedCheerio('article.maindet').each(function () {
const novelName = loadedCheerio(this).find('h2').text();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
const novelUrl = loadedCheerio(this).find('h2 a').attr('href');
if (!novelUrl) return;
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
async fetchImage(url: string): Promise<string | undefined>{
return await fetchFile(url);
}
}
export default new LightNovelFRPlugin();`;
return {
lang: sourceJson.lang,
filename: sourceName,
pluginScript,
};
return {
lang: source.options?.lang || "English",
filename: source.sourceName,
pluginScript,
};
};
+17 -13
View File
@@ -1,16 +1,20 @@
[
{
"id": "lightnovelfr",
"sourceSite": "https://lightnovelfr.com/",
"sourceName": "Ligh Novel FR",
"lang": "French",
"reverseChapters": true
},
{
"id": "kol-novel",
"sourceSite": "https://kolnovel.com/",
"sourceName": "Kol Novel",
"lang": "arabic",
"reverseChapters": true
{
"id": "lightnovelfr",
"sourceSite": "https://lightnovelfr.com/",
"sourceName": "Ligh Novel FR",
"options": {
"lang": "French",
"reverseChapters": true
}
},
{
"id": "kol-novel",
"sourceSite": "https://kolnovel.com/",
"sourceName": "Kol Novel",
"options": {
"lang": "arabic",
"reverseChapters": true
}
}
]
+149
View File
@@ -0,0 +1,149 @@
import { CheerioAPI, load } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
interface WPmangaStreamOptions {
reverseChapters?: boolean;
lang?: string;
}
export interface WPmangaStreamMetadata {
id: string;
sourceSite: string;
sourceName: string;
options?: WPmangaStreamOptions;
}
class WPmangaStreamPlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
options?: WPmangaStreamOptions;
constructor(metadata: WPmangaStreamMetadata) {
this.id = metadata.id;
this.name = metadata.sourceName + "[wpmangastream]";
this.icon = `multisrc/wpmangastream/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.options = metadata.options;
}
async popularNovels(page: number): Promise<Plugin.NovelItem[]> {
const url = this.site + "series/?page=" + page + "&status=&order=popular";
const body = await fetchApi(url).then((res) => res.text());
const loadedCheerio = load(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio("article.maindet").each(function () {
const name = loadedCheerio(this).find("h2").text();
const image = loadedCheerio(this).find("img");
const url = loadedCheerio(this).find("h2 a").attr("href");
if (!url) return;
novels.push({
name,
cover: image.attr("data-src") || image.attr("src"),
url,
});
});
return novels;
}
async parseNovelAndChapters(url: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(url).then((res) => res.text());
const loadedCheerio = load(body);
const novel: Plugin.SourceNovel = { url };
// novel.url = url;
novel.name = loadedCheerio("h1.entry-title").text();
novel.cover =
loadedCheerio("img.wp-post-image").attr("data-src") ||
loadedCheerio("img.wp-post-image").attr("src");
novel.status = loadedCheerio("div.sertostat > span").attr("class");
loadedCheerio("div.serl > span").each(function () {
const detailName = loadedCheerio(this).text().trim();
const detail = loadedCheerio(this).next().text().trim();
switch (detailName) {
case "الكاتب":
case "Author":
case "Auteur":
novel.author = detail;
break;
}
});
novel.genres = loadedCheerio(".sertogenre")
.children("a")
.map((i, el) => loadedCheerio(el).text())
.toArray()
.join(",");
let summary = loadedCheerio(".sersys > p").siblings().remove("div").end();
novel.summary = "";
for (let i = 0; i < summary.length; i++) {
const p = summary[i];
novel.summary += loadedCheerio(p).text().trim() + "\\n\\n";
}
const chapters: Plugin.ChapterItem[] = loadedCheerio(".eplister li")
.map((index, element) => ({
name:
loadedCheerio(element).find(".epl-num").text() +
loadedCheerio(element).find(".epl-title").text(),
releaseTime: loadedCheerio(element).find(".epl-date").text().trim(),
url: loadedCheerio(element).find("a").attr("href") || "",
}))
.get()
.filter((chapter) => chapter.name && chapter.url);
if (this.options?.reverseChapters && chapters.length) chapters.reverse();
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const body = await fetchApi(chapterUrl).then((res) => res.text());
const loadedCheerio = load(body);
const chapterText = loadedCheerio(".epcontent").html() || "";
return chapterText;
}
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const url = this.site + "?s=" + searchTerm;
const body = await fetchApi(url).then((res) => res.text());
const loadedCheerio = load(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio("article.maindet").each(function () {
const name = loadedCheerio(this).find("h2").text();
const image = loadedCheerio(this).find("img");
const url = loadedCheerio(this).find("h2 a").attr("href");
if (!url) return;
novels.push({
name,
cover: image.attr("data-src") || image.attr("src"),
url,
});
});
return novels;
}
fetchImage = fetchFile;
}