* add prettier

* lint-staged

* prettier

* upgrade husky
This commit is contained in:
nyagami
2024-03-23 22:00:29 +07:00
committed by GitHub
parent c22979b10f
commit 5f9a067ab9
113 changed files with 79244 additions and 50841 deletions
+44 -44
View File
@@ -1,62 +1,62 @@
import path from "path";
import fs from "fs";
import path from 'path';
import fs from 'fs';
type GeneratedScript = {
lang: string;
filename: string;
pluginScript: string;
lang: string;
filename: string;
pluginScript: string;
};
export type ScrpitGeneratorFunction = (name: string) => GeneratedScript[];
const isScriptGenerator = (s: unknown): s is ScrpitGeneratorFunction => {
return !!s && typeof s === "function";
return !!s && typeof s === 'function';
};
const generate = async (name: string): Promise<boolean> => {
try {
const generateAll: ScrpitGeneratorFunction | unknown =
require(`./${name}/generator`).generateAll;
if (!isScriptGenerator(generateAll)) return false;
const sources = generateAll(name);
for (let source of sources) {
const { lang, filename, pluginScript } = source;
if (!lang || !filename || !pluginScript) {
console.warn(
name,
": lang, filename, pluginScript are required!"
);
continue;
}
const pluginsDir = path.join(
path.dirname(path.dirname(__dirname)),
"plugins"
);
const filePath = path.join(
pluginsDir,
lang.toLowerCase(),
filename.replace(/[\s-\.]+/g, "") + `[${name}].ts`
);
fs.writeFileSync(filePath, pluginScript, { encoding: "utf-8" });
}
return true;
} catch (e) {
console.log(`${name} is broken! ${e}`);
return false;
try {
const generateAll: ScrpitGeneratorFunction | unknown = require(
`./${name}/generator`,
).generateAll;
if (!isScriptGenerator(generateAll)) return false;
const sources = generateAll(name);
for (let source of sources) {
const { lang, filename, pluginScript } = source;
if (!lang || !filename || !pluginScript) {
console.warn(name, ': lang, filename, pluginScript are required!');
continue;
}
const pluginsDir = path.join(
path.dirname(path.dirname(__dirname)),
'plugins',
);
const filePath = path.join(
pluginsDir,
lang.toLowerCase(),
filename.replace(/[\s-\.]+/g, '') + `[${name}].ts`,
);
fs.writeFileSync(filePath, pluginScript, { encoding: 'utf-8' });
}
return true;
} catch (e) {
console.log(`${name} is broken! ${e}`);
return false;
}
};
const run = async () => {
const sources = fs
.readdirSync(__dirname)
.filter((name) =>
fs.lstatSync(path.join(__dirname, name)).isDirectory() && !name.endsWith('.broken')
);
const sources = fs
.readdirSync(__dirname)
.filter(
name =>
fs.lstatSync(path.join(__dirname, name)).isDirectory() &&
!name.endsWith('.broken'),
);
for (let name of sources) {
const success = await generate(name);
if (success) console.log(`[${name}] OK`);
}
for (let name of sources) {
const success = await generate(name);
if (success) console.log(`[${name}] OK`);
}
};
run();
+24 -24
View File
@@ -1,43 +1,43 @@
import * as fs from "fs";
import * as cheerio from "cheerio";
import * as path from "path";
import list from "./sources.json";
import { HotNovelPubMetadata } from "./template";
import * as fs from 'fs';
import * as cheerio from 'cheerio';
import * as path from 'path';
import list from './sources.json';
import { HotNovelPubMetadata } from './template';
async function getFilters(sources: HotNovelPubMetadata) {
const filters: any = {
sort: {
type: "Picker",
label: "Order",
value: "hot",
type: 'Picker',
label: 'Order',
value: 'hot',
options: [],
},
category: {
type: "Picker",
label: "category",
value: "",
options: [{ label: "NONE", value: "" }],
type: 'Picker',
label: 'category',
value: '',
options: [{ label: 'NONE', value: '' }],
},
};
const body = await fetch(sources.sourceSite).then((res) => res.text());
const body = await fetch(sources.sourceSite).then(res => res.text());
const $: cheerio.CheerioAPI = cheerio.load(body);
$(".new-update").remove();
$('.new-update').remove();
$("section > div").each((i, el) => {
const id = $(el).find('a[class="see-all"]').attr("href");
$('section > div').each((i, el) => {
const id = $(el).find('a[class="see-all"]').attr('href');
if (id) {
filters.sort.options.push({
label: $(el).find('[class="section-title"]').text().trim(),
value: id.split("/").pop(),
value: id.split('/').pop(),
});
}
});
filters.category.label = $(".category-title").text().trim();
const apiSite = sources.sourceSite.replace("://", "://api.");
const jsonRaw = await fetch(apiSite + "/categories", {
filters.category.label = $('.category-title').text().trim();
const apiSite = sources.sourceSite.replace('://', '://api.');
const jsonRaw = await fetch(apiSite + '/categories', {
headers: {
lang: sources.options?.lang || "en",
lang: sources.options?.lang || 'en',
},
});
const json = (await jsonRaw.json()) as response;
@@ -45,7 +45,7 @@ async function getFilters(sources: HotNovelPubMetadata) {
if (json.data?.length) {
json.data
.sort((a, b) => a.name.localeCompare(b.name))
.forEach((category) =>
.forEach(category =>
filters.category.options.push({
label: category.name,
value: category.slug,
@@ -69,13 +69,13 @@ interface DataEntity {
async function start() {
const result = [];
for (const sources of list) {
console.log("updating the filters in", sources.sourceName);
console.log('updating the filters in', sources.sourceName);
const NewFilters = await getFilters(sources as any);
sources.filters = NewFilters;
result.push(sources);
}
fs.writeFileSync(
path.join(__dirname, "sources.json"),
path.join(__dirname, 'sources.json'),
JSON.stringify(result, null, 2),
);
}
+16 -15
View File
@@ -1,21 +1,21 @@
import { FilterTypes, Filters } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import { HotNovelPubMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
import { FilterTypes, Filters } from '../../../libs/filterInputs';
import { ScrpitGeneratorFunction } from '../generate';
import list from './sources.json';
import { HotNovelPubMetadata } from './template';
import { readFileSync } from 'fs';
import path from 'path';
const lang: { [key: string]: string } = {
en: "english",
ru: "russian",
es: "spanish",
pt: "portuguese",
th: "turkish",
en: 'english',
ru: 'russian',
es: 'spanish',
pt: 'portuguese',
th: 'turkish',
};
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list
.map<HotNovelPubMetadata>((p) => {
.map<HotNovelPubMetadata>(p => {
const filters: Filters = {};
for (const k in p.filters) {
const f = p.filters[k as keyof typeof p.filters];
@@ -36,8 +36,9 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
const generator = function generator(metadata: HotNovelPubMetadata) {
const HotNovelPubTemplate = readFileSync(
path.join(__dirname, "template.ts"), {
encoding: "utf-8",
path.join(__dirname, 'template.ts'),
{
encoding: 'utf-8',
},
);
@@ -51,7 +52,7 @@ export default plugin;
`.trim();
return {
lang: lang[metadata?.options?.lang || "en"] || "english",
lang: lang[metadata?.options?.lang || 'en'] || 'english',
filename: metadata.sourceName,
pluginScript,
};
+34 -32
View File
@@ -1,9 +1,9 @@
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 dayjs from "dayjs";
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 dayjs from 'dayjs';
export interface HotNovelPubMetadata {
id: string;
@@ -32,23 +32,23 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/hotnovelpub/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.apiSite = metadata.sourceSite.replace("://", "://api.");
this.version = "1.0.0";
this.apiSite = metadata.sourceSite.replace('://', '://api.');
this.version = '1.0.0';
this.filters = metadata.filters;
this.lang = metadata.options?.lang || "en";
this.lang = metadata.options?.lang || 'en';
}
async popularNovels(
pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = this.apiSite + "/books/";
url += showLatestNovels ? "new" : filters?.sort?.value || "hot";
let url = this.apiSite + '/books/';
url += showLatestNovels ? 'new' : filters?.sort?.value || 'hot';
if (filters?.category?.value) {
url = this.apiSite + "/category/" + filters.category.value;
url = this.apiSite + '/category/' + filters.category.value;
}
url += "/?page=" + (pageNo - 1) + "&limit=20";
url += '/?page=' + (pageNo - 1) + '&limit=20';
const result = await fetchApi(url, {
headers: {
@@ -59,11 +59,11 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
const novels: Plugin.NovelItem[] = [];
if (json.status && json.data.books.data?.length) {
json.data.books.data.forEach((novel) =>
json.data.books.data.forEach(novel =>
novels.push({
name: novel.name,
cover: this.site + novel.image,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
}
@@ -71,7 +71,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const result = await fetchApi(this.apiSite + "/book" + novelPath, {
const result = await fetchApi(this.apiSite + '/book' + novelPath, {
headers: {
lang: this.lang,
},
@@ -85,13 +85,13 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
summary: json.data.book.authorize.description,
author: json.data.book.authorize.name,
status:
json.data.book.status === "updating"
json.data.book.status === 'updating'
? NovelStatus.Ongoing
: NovelStatus.Completed,
};
if (json.data.tags.tags_name?.length) {
novel.genres = json.data.tags.tags_name.join(",");
novel.genres = json.data.tags.tags_name.join(',');
}
if (json.data.chapters?.length) {
@@ -99,7 +99,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
json.data.chapters.forEach((chapter, chapterIndex) =>
chapters.push({
name: chapter.title,
path: "/" + chapter.slug,
path: '/' + chapter.slug,
releaseTime: undefined,
chapterNumber: (chapter.index || chapterIndex) + 1,
}),
@@ -111,50 +111,52 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
let chapterText = loadedCheerio("#content-item").html() || "";
let chapterText = loadedCheerio('#content-item').html() || '';
if (chapterText) {
const result = await fetchApi(
this.site + "/server/getContent?slug=" + chapterPath,
this.site + '/server/getContent?slug=' + chapterPath,
);
const json = (await result.json()) as ChapterType;
if (json.data) {
chapterText += json.data
.map((item) => "<p>" + item + "</p>")
.join("")
.replace(/\n/g, "</p><p>")
.replace(/\s/g, " ");
.map(item => '<p>' + item + '</p>')
.join('')
.replace(/\n/g, '</p><p>')
.replace(/\s/g, ' ');
}
}
return chapterText.replace(/\.copy right hot novel pub/g, "");
return chapterText.replace(/\.copy right hot novel pub/g, '');
}
async searchNovels(
searchTerm: string,
pageNo: number,
): Promise<Plugin.NovelItem[]> {
const result = await fetchApi(this.apiSite + "/search", {
const result = await fetchApi(this.apiSite + '/search', {
headers: {
"Content-Type": "application/json;charset=utf-8",
'Content-Type': 'application/json;charset=utf-8',
Referer: this.site,
Origin: this.site,
lang: this.lang,
},
method: "POST",
method: 'POST',
body: JSON.stringify({ key_search: searchTerm }),
});
const json = (await result.json()) as responseSearch;
const novels: Plugin.NovelItem[] = [];
if (json.status && json.data.books?.length) {
json.data.books.forEach((novel) =>
json.data.books.forEach(novel =>
novels.push({
name: novel.name,
cover: undefined,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
}
+10 -10
View File
@@ -1,10 +1,10 @@
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";
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) => {
@@ -15,8 +15,8 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
};
const generator = function generator(metadata: IfreedomMetadata) {
const IfreedomTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
const IfreedomTemplate = readFileSync(path.join(__dirname, 'template.ts'), {
encoding: 'utf-8',
});
const pluginScript = `
@@ -29,7 +29,7 @@ export default plugin;
`.trim();
return {
lang: "russian",
lang: 'russian',
filename: metadata.sourceName,
pluginScript,
};
+71 -60
View File
@@ -1,9 +1,9 @@
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 dayjs from "dayjs";
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 dayjs from 'dayjs';
export interface IfreedomMetadata {
id: string;
@@ -25,7 +25,7 @@ class IfreedomPlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/ifreedom/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.version = '1.0.0';
this.filters = metadata.filters;
}
@@ -36,87 +36,95 @@ class IfreedomPlugin implements Plugin.PluginBase {
showLatestNovels,
}: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> {
let url = this.site + "/vse-knigi/?sort=" +
(showLatestNovels ? "По дате обновления" : filters?.sort?.value || "По рейтингу");
let url =
this.site +
'/vse-knigi/?sort=' +
(showLatestNovels
? 'По дате обновления'
: filters?.sort?.value || 'По рейтингу');
Object.entries(filters || {}).forEach(([type, { value }]) => {
if (value instanceof Array && value.length) {
url += "&" + type + "[]=" + value.join("&" + type + "[]=");
url += '&' + type + '[]=' + value.join('&' + type + '[]=');
}
});
url += "&bpage=" + page;
url += '&bpage=' + page;
const body = await fetchApi(url).then((res) => res.text());
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",
'div.one-book-home > div.img-home a',
)
.map((index, element) => ({
name: loadedCheerio(element).attr("title") || "",
cover: loadedCheerio(element).find("img").attr("src"),
name: loadedCheerio(element).attr('title') || '',
cover: loadedCheerio(element).find('img').attr('src'),
path:
loadedCheerio(element).attr("href")?.replace?.(this.site, "") || "",
loadedCheerio(element).attr('href')?.replace?.(this.site, '') || '',
}))
.get()
.filter((novel) => novel.name && novel.path);
.filter(novel => novel.name && novel.path);
return novels;
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(this.site + novelPath).then((res) => res.text());
const body = await fetchApi(this.site + novelPath).then(res => res.text());
const loadedCheerio = parseHTML(body);
const novel: Plugin.SourceNovel = {
path: novelPath,
name: loadedCheerio(".entry-title").text(),
cover: loadedCheerio(".img-ranobe > img").attr("src"),
summary: loadedCheerio('meta[name="description"]').attr("content"),
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 "Автор":
loadedCheerio('div.data-ranobe').each(function () {
switch (loadedCheerio(this).find('b').text()) {
case 'Автор':
novel.author = loadedCheerio(this)
.find("div.data-value")
.find('div.data-value')
.text()
.trim();
break;
case "Жанры":
novel.genres = loadedCheerio("div.data-value > a")
case 'Жанры':
novel.genres = loadedCheerio('div.data-value > a')
.map((index, element) => loadedCheerio(element).text()?.trim())
.get()
.join(",");
.join(',');
break;
case "Статус книги":
novel.status = loadedCheerio("div.data-value")
case 'Статус книги':
novel.status = loadedCheerio('div.data-value')
.text()
.includes("активен")
.includes('активен')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
if (novel.author == "Не указан") delete novel.author;
if (novel.author == 'Не указан') delete novel.author;
const chapters: Plugin.ChapterItem[] = [];
const totalChapters = loadedCheerio("div.li-ranobe").length;
const totalChapters = loadedCheerio('div.li-ranobe').length;
loadedCheerio("div.li-ranobe").each((chapterIndex, element) => {
const name = loadedCheerio(element).find("a").text();
const url = loadedCheerio(element).find("a").attr("href");
if (!loadedCheerio(element).find("label.buy-ranobe").length && name && url) {
loadedCheerio('div.li-ranobe').each((chapterIndex, element) => {
const name = loadedCheerio(element).find('a').text();
const url = loadedCheerio(element).find('a').attr('href');
if (
!loadedCheerio(element).find('label.buy-ranobe').length &&
name &&
url
) {
const releaseDate = loadedCheerio(element)
.find("div.li-col2-ranobe")
.find('div.li-col2-ranobe')
.text()
.trim();
chapters.push({
name,
path: url.replace(this.site, ""),
path: url.replace(this.site, ''),
releaseTime: this.parseDate(releaseDate),
chapterNumber: totalChapters - chapterIndex,
});
@@ -128,21 +136,23 @@ class IfreedomPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
loadedCheerio(".entry-content img").each((index, element) => {
const srcset = loadedCheerio(element).attr("srcset")?.split?.(" ");
loadedCheerio('.entry-content img').each((index, element) => {
const srcset = loadedCheerio(element).attr('srcset')?.split?.(' ');
if (srcset?.length) {
loadedCheerio(element).removeAttr("srcset");
const bestlink: string[] = srcset.filter((url) => url.startsWith("http"));
loadedCheerio(element).removeAttr('srcset');
const bestlink: string[] = srcset.filter(url => url.startsWith('http'));
if (bestlink[bestlink.length - 1]) {
loadedCheerio(element).attr("src", bestlink[bestlink.length - 1]);
loadedCheerio(element).attr('src', bestlink[bestlink.length - 1]);
}
}
});
const chapterText = loadedCheerio(".entry-content").html() || "";
const chapterText = loadedCheerio('.entry-content').html() || '';
return chapterText;
}
@@ -151,25 +161,26 @@ class IfreedomPlugin implements Plugin.PluginBase {
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());
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",
'div.one-book-home > div.img-home a',
)
.map((index, element) => ({
name: loadedCheerio(element).attr("title") || "",
cover: loadedCheerio(element).find("img").attr("src"),
path: loadedCheerio(element).attr("href")?.replace?.(this.site, "") || "",
name: loadedCheerio(element).attr('title') || '',
cover: loadedCheerio(element).find('img').attr('src'),
path:
loadedCheerio(element).attr('href')?.replace?.(this.site, '') || '',
}))
.get()
.filter((novel) => novel.name && novel.path);
.filter(novel => novel.name && novel.path);
return novels;
}
parseDate = (dateString: string | undefined = "") => {
parseDate = (dateString: string | undefined = '') => {
const months: { [key: string]: number } = {
января: 1,
февраля: 2,
@@ -185,16 +196,16 @@ class IfreedomPlugin implements Plugin.PluginBase {
декабря: 12,
};
if (dateString.includes(".")) {
const [day, month, year] = dateString.split(".");
if (dateString.includes('.')) {
const [day, month, year] = dateString.split('.');
if (day && month && year) {
return dayjs(year + "-" + month + "-" + day).format("LL");
return dayjs(year + '-' + month + '-' + day).format('LL');
}
} else if (dateString.includes(" ")) {
const [day, month] = dateString.split(" ");
} else if (dateString.includes(' ')) {
const [day, month] = dateString.split(' ');
if (day && months[month]) {
const year = new Date().getFullYear();
return dayjs(year + "-" + months[month] + "-" + day).format("LL");
return dayjs(year + '-' + months[month] + '-' + day).format('LL');
}
}
return dateString || null;
+15 -10
View File
@@ -1,8 +1,8 @@
import { ScrpitGeneratorFunction } from "../generate";
import { LightNovelWPMetadata } from "./template";
import list from "./sources.json";
import { readFileSync } from "fs";
import path from "path";
import { ScrpitGeneratorFunction } from '../generate';
import { LightNovelWPMetadata } from './template';
import list from './sources.json';
import { readFileSync } from 'fs';
import path from 'path';
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list.map((source: LightNovelWPMetadata) => {
@@ -11,15 +11,20 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
filters = require(`./filters/${source.id}`);
source.filters = filters.filters;
} catch (e) {}
console.log(`[${name}] Generating: ${source.id}${" ".repeat(20 - source.id.length)} ${source.filters ? "🔎with filters🔍" : "🚫no filters🚫"}`);
console.log(
`[${name}] Generating: ${source.id}${' '.repeat(20 - source.id.length)} ${source.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
);
return generator(source);
});
};
const generator = function generator(source: LightNovelWPMetadata) {
const LightNovelWPTemplate = readFileSync(path.join(__dirname, "template.ts"),{
encoding: "utf-8",
});
const LightNovelWPTemplate = readFileSync(
path.join(__dirname, 'template.ts'),
{
encoding: 'utf-8',
},
);
const pluginScript = `
${LightNovelWPTemplate}
@@ -28,7 +33,7 @@ export default plugin;
`.trim();
return {
lang: source.options?.lang || "English",
lang: source.options?.lang || 'English',
filename: source.sourceName,
pluginScript,
};
+110 -86
View File
@@ -3,99 +3,123 @@ import * as cheerio from 'cheerio';
import * as path from 'path';
function getFilters(name: string, html: string) {
const $:cheerio.CheerioAPI = cheerio.load(html);
const filters: any = {filters: {
"genre[]": {
type: "Checkbox",
label: "Genre",
value: [],
options: []
},
"type[]": {
type: "Checkbox",
label: "Type",
value: [],
options: []
},
"status": {
type: "Picker",
label: "Status",
value: "",
options: []
},
"order": {
type: "Picker",
label: "Order",
value: "",
options: []
},
}};
const $: cheerio.CheerioAPI = cheerio.load(html);
const filters: any = {
filters: {
'genre[]': {
type: 'Checkbox',
label: 'Genre',
value: [],
options: [],
},
'type[]': {
type: 'Checkbox',
label: 'Type',
value: [],
options: [],
},
'status': {
type: 'Picker',
label: 'Status',
value: '',
options: [],
},
'order': {
type: 'Picker',
label: 'Order',
value: '',
options: [],
},
},
};
const filtersContainer = $('div.quickfilter').find("ul");
filtersContainer.each((i, el) => {
const filterName = Object.keys(filters.filters)[i];
filters.filters[filterName].label = $(el).prev().contents().first().text().trim();
$(el).find("li").each((j, li) => {
filters.filters[filterName].options.push({
label: $(li).text().trim(),
value: decodeURI($(li).find("input").attr("value") || "")
});
});
});
fs.writeFileSync(
path.join(__dirname, 'filters', name + ".json"),
JSON.stringify(filters, null, 2)
);
const filtersContainer = $('div.quickfilter').find('ul');
filtersContainer.each((i, el) => {
const filterName = Object.keys(filters.filters)[i];
filters.filters[filterName].label = $(el)
.prev()
.contents()
.first()
.text()
.trim();
$(el)
.find('li')
.each((j, li) => {
filters.filters[filterName].options.push({
label: $(li).text().trim(),
value: decodeURI($(li).find('input').attr('value') || ''),
});
});
});
fs.writeFileSync(
path.join(__dirname, 'filters', name + '.json'),
JSON.stringify(filters, null, 2),
);
}
async function getFiltersFromURL(name: string, url: string) {
const response = await fetch(url + "/series/");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}, while fetching ${response.url}`);
}
const html = await response.text();
try {
getFilters(name, html);
} catch (e) {
console.error("Error while getting filters from", url);
}
const response = await fetch(url + '/series/');
if (!response.ok) {
throw new Error(
`HTTP error! status: ${response.status}, while fetching ${response.url}`,
);
}
const html = await response.text();
try {
getFilters(name, html);
} catch (e) {
console.error('Error while getting filters from', url);
}
}
async function askGetFilter() {
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
async function askGetFilter(){
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const EREASE_PREV_LINE = '\x1b[1A\r\x1b[2K';
await readline.question('Enter the id of the site (same one as in sources.json): ', async (name: string) => {
await readline.question(EREASE_PREV_LINE + 'Do you want to get the filters from a URL or the html text? (if url dosen\'t work try html) (url/html): ', async (method: string) => {
if (method.toLowerCase() === "url") {
await readline.question(EREASE_PREV_LINE + 'Enter the URL (same one as in sources.json): ', async (url: string) => {
try {
await getFiltersFromURL(name, url);
} catch (e: any) {
console.error("Error while getting filters from", url);
console.log(e.message || e);
}
readline.close();
});
} else {
process.stdout.write(EREASE_PREV_LINE + `Enter the html text from the page at {sourceSite}/series (at the end press ENTER then press CTRL+C)
(to make it faster you can run \`$(\"div.quickfilter\").parent().html()\` in the console to get only the important html part): `)
let html = "";
readline.on('SIGINT', () => {
console.log("Creating filters file");
getFilters(name, html);
readline.close();
});
readline.on('line', (line: string) => {
html += line + "\n";
});
}
});
});
const EREASE_PREV_LINE = '\x1b[1A\r\x1b[2K';
await readline.question(
'Enter the id of the site (same one as in sources.json): ',
async (name: string) => {
await readline.question(
EREASE_PREV_LINE +
"Do you want to get the filters from a URL or the html text? (if url dosen't work try html) (url/html): ",
async (method: string) => {
if (method.toLowerCase() === 'url') {
await readline.question(
EREASE_PREV_LINE +
'Enter the URL (same one as in sources.json): ',
async (url: string) => {
try {
await getFiltersFromURL(name, url);
} catch (e: any) {
console.error('Error while getting filters from', url);
console.log(e.message || e);
}
readline.close();
},
);
} else {
process.stdout.write(
EREASE_PREV_LINE +
`Enter the html text from the page at {sourceSite}/series (at the end press ENTER then press CTRL+C)
(to make it faster you can run \`$(\"div.quickfilter\").parent().html()\` in the console to get only the important html part): `,
);
let html = '';
readline.on('SIGINT', () => {
console.log('Creating filters file');
getFilters(name, html);
readline.close();
});
readline.on('line', (line: string) => {
html += line + '\n';
});
}
},
);
},
);
}
askGetFilter();
+134 -95
View File
@@ -1,9 +1,9 @@
import { CheerioAPI, load } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { defaultCover } from "@libs/defaultCover";
import { Filters } from "@libs/filterInputs";
import { CheerioAPI, load } from 'cheerio';
import { fetchApi, fetchFile } from '@libs/fetch';
import { Plugin } from '@typings/plugin';
import { NovelStatus } from '@libs/novelStatus';
import { defaultCover } from '@libs/defaultCover';
import { Filters } from '@libs/filterInputs';
interface LightNovelWPOptions {
reverseChapters?: boolean;
@@ -40,50 +40,64 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
}
getHostname(url: string): string {
return url.split("/")[2];
return url.split('/')[2];
}
async getCheerio(url: string, search: boolean): Promise<CheerioAPI> {
const r = await fetchApi(url);
if (!r.ok && search != true) throw new Error("Could not reach site (" + r.status + ") try to open in webview.");
if (!r.ok && search != true)
throw new Error(
'Could not reach site (' + r.status + ') try to open in webview.',
);
const $ = load(await r.text());
const title = $("title").text().trim();
if (this.getHostname(url) != this.getHostname(r.url) ||
title == "Bot Verification" || title == "You are being redirected..." || title == "Un instant..." || title == "Just a moment..." || title == "Redirecting...")
throw new Error("Captcha error, please open in webview");
const title = $('title').text().trim();
if (
this.getHostname(url) != this.getHostname(r.url) ||
title == 'Bot Verification' ||
title == 'You are being redirected...' ||
title == 'Un instant...' ||
title == 'Just a moment...' ||
title == 'Redirecting...'
)
throw new Error('Captcha error, please open in webview');
return ($);
return $;
}
parseNovels($: CheerioAPI): Plugin.NovelItem[] {
const novels: Plugin.NovelItem[] = [];
$("div.listupd > article").each((i, elem) => {
const novelName = $(elem).find("h2").text();
const image = $(elem).find("img");
const novelUrl = $(elem).find("a").attr("href");
$('div.listupd > article').each((i, elem) => {
const novelName = $(elem).find('h2').text();
const image = $(elem).find('img');
const novelUrl = $(elem).find('a').attr('href');
if (novelUrl) {
novels.push({
name: novelName,
cover: image.attr("data-src") || image.attr("src") || defaultCover,
path: novelUrl.replace(this.site, ""),
cover: image.attr('data-src') || image.attr('src') || defaultCover,
path: novelUrl.replace(this.site, ''),
});
}
});
return novels;
}
async popularNovels(pageNo: number, { filters, showLatestNovels }: Plugin.PopularNovelsOptions <typeof this.filters>): Promise<Plugin.NovelItem[]> {
let url = this.site + "/series/?page=" + pageNo;
async popularNovels(
pageNo: number,
{
filters,
showLatestNovels,
}: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> {
let url = this.site + '/series/?page=' + pageNo;
if (!filters) filters = {};
if (showLatestNovels) url += "&order=latest";
if (showLatestNovels) url += '&order=latest';
for (const key in filters) {
if (typeof filters[key].value === "object")
if (typeof filters[key].value === 'object')
for (const value of filters[key].value as string[])
url += `&${key}=${value}`;
else if (filters[key].value)
url += `&${key}=${filters[key].value}`;
else if (filters[key].value) url += `&${key}=${filters[key].value}`;
}
const $ = await this.getCheerio(url, false);
return this.parseNovels($);
@@ -92,19 +106,22 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const $ = await this.getCheerio(this.site + novelPath, false);
const novel: Plugin.SourceNovel = { path: novelPath.replace(this.site, ""), name: "Untitled" };
const novel: Plugin.SourceNovel = {
path: novelPath.replace(this.site, ''),
name: 'Untitled',
};
novel.name = $("h1.entry-title").text().trim();
const image = $("img.wp-post-image");
novel.cover = image.attr("data-src") || image.attr("src") || defaultCover;
switch ($("div.sertostat > span").attr("class")?.toLowerCase() || "") {
case "completed":
novel.name = $('h1.entry-title').text().trim();
const image = $('img.wp-post-image');
novel.cover = image.attr('data-src') || image.attr('src') || defaultCover;
switch ($('div.sertostat > span').attr('class')?.toLowerCase() || '') {
case 'completed':
novel.status = NovelStatus.Completed;
break;
case "ongoing":
case 'ongoing':
novel.status = NovelStatus.Ongoing;
break;
case "hiatus":
case 'hiatus':
novel.status = NovelStatus.OnHiatus;
break;
default:
@@ -112,49 +129,55 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
break;
}
let details = $("div.serl");
if (!details.length) details = $("div.spe > span");
let details = $('div.serl');
if (!details.length) details = $('div.spe > span');
details.each(function () {
const detailName = $(this).contents().first().text().replace(":", "").trim().toLowerCase();
const detailName = $(this)
.contents()
.first()
.text()
.replace(':', '')
.trim()
.toLowerCase();
const detail = $(this).contents().last().text().trim().toLowerCase();
switch (detailName) {
case "الكاتب":
case "author":
case "auteur":
case "autor":
case "yazar":
case 'الكاتب':
case 'author':
case 'auteur':
case 'autor':
case 'yazar':
novel.author = detail;
break;
case "الحالة":
case "status":
case "statut":
case "estado":
case "durum":
case 'الحالة':
case 'status':
case 'statut':
case 'estado':
case 'durum':
switch (detail) {
case "مكتملة":
case "completed":
case "complété":
case "completo":
case "completado":
case "tamamlandı":
case 'مكتملة':
case 'completed':
case 'complété':
case 'completo':
case 'completado':
case 'tamamlandı':
novel.status = NovelStatus.Completed;
break;
case "مستمرة":
case "ongoing":
case "en cours":
case "em andamento":
case "en progreso":
case "devam ediyor":
case 'مستمرة':
case 'ongoing':
case 'en cours':
case 'em andamento':
case 'en progreso':
case 'devam ediyor':
novel.status = NovelStatus.Ongoing;
break;
case "متوقفة":
case "hiatus":
case "en pause":
case "hiato":
case "pausa":
case "pausado":
case "duraklatıldı":
case 'متوقفة':
case 'hiatus':
case 'en pause':
case 'hiato':
case 'pausa':
case 'pausado':
case 'duraklatıldı':
novel.status = NovelStatus.OnHiatus;
break;
default:
@@ -162,40 +185,48 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
break;
}
break;
case "الفنان":
case "artist":
case "artiste":
case "artista":
case "çizer":
case 'الفنان':
case 'artist':
case 'artiste':
case 'artista':
case 'çizer':
novel.artist = detail;
break;
}
});
let genres = $(".sertogenre")
if (!genres.length) genres = $(".genxed")
let genres = $('.sertogenre');
if (!genres.length) genres = $('.genxed');
novel.genres = genres
.children("a")
.children('a')
.map((i, el) => $(el).text())
.toArray()
.join(",");
.join(',');
let summary = $(".sersys > p").map((i, el) => $(el).text().trim()).toArray();
if (!summary.length) summary = $(".entry-content > p").map((i, el) => $(el).text().trim()).toArray();
novel.summary = summary.join("\n");
let summary = $('.sersys > p')
.map((i, el) => $(el).text().trim())
.toArray();
if (!summary.length)
summary = $('.entry-content > p')
.map((i, el) => $(el).text().trim())
.toArray();
novel.summary = summary.join('\n');
const chapters: Plugin.ChapterItem[] = [];
$(".eplister li").each((i, elem) => {
const chapterName = $(elem).find(".epl-num").text() + " " + $(elem).find(".epl-title").text();
const chapterUrl = $(elem).find("a").attr("href") || "";
const releaseTime = $(elem).find(".epl-date").text().trim();
$('.eplister li').each((i, elem) => {
const chapterName =
$(elem).find('.epl-num').text() +
' ' +
$(elem).find('.epl-title').text();
const chapterUrl = $(elem).find('a').attr('href') || '';
const releaseTime = $(elem).find('.epl-date').text().trim();
let isFreeChapter: boolean;
switch ($(elem).find(".epl-price").text().trim().toLowerCase()) {
case "free":
case "gratuit":
case "مجاني":
case "livre":
case "":
switch ($(elem).find('.epl-price').text().trim().toLowerCase()) {
case 'free':
case 'gratuit':
case 'مجاني':
case 'livre':
case '':
isFreeChapter = true;
break;
default:
@@ -205,7 +236,7 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
if (isFreeChapter)
chapters.push({
name: chapterName,
path: chapterUrl.replace(this.site, ""),
path: chapterUrl.replace(this.site, ''),
releaseTime: releaseTime,
});
});
@@ -218,16 +249,24 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
async parseChapter(chapterPath: string): Promise<string> {
const $ = await this.getCheerio(this.site + chapterPath, false);
if (this.id == "kolnovel") {
let ignore = $("article > style").text().trim().split(",");
ignore.push(...(ignore.pop()?.match(/^\.\w+/) || []));
ignore.map((tag) => $(`p${tag}`).remove());
if (this.id == 'kolnovel') {
let ignore = $('article > style').text().trim().split(',');
ignore.push(...(ignore.pop()?.match(/^\.\w+/) || []));
ignore.map(tag => $(`p${tag}`).remove());
}
return $(".epcontent p").map((i, el) => $(el)).toArray().join("\n") || "";
return (
$('.epcontent p')
.map((i, el) => $(el))
.toArray()
.join('\n') || ''
);
}
async searchNovels(searchTerm: string, page: number): Promise<Plugin.NovelItem[]> {
const url = this.site + "page/" + page + "/?s=" + searchTerm;
async searchNovels(
searchTerm: string,
page: number,
): Promise<Plugin.NovelItem[]> {
const url = this.site + 'page/' + page + '/?s=' + searchTerm;
const $ = await this.getCheerio(url, true);
return this.parseNovels($);
}
+26 -25
View File
@@ -1,36 +1,37 @@
import { FilterTypes, Filters } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import { MadaraMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
import { FilterTypes, Filters } from '../../../libs/filterInputs';
import { ScrpitGeneratorFunction } from '../generate';
import list from './sources.json';
import { MadaraMetadata } from './template';
import { readFileSync } from 'fs';
import path from 'path';
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list.map((metadata: MadaraMetadata) => {
let filters: any = {};
try {
filters = require(`./filters/${metadata.id}`);
metadata.filters = filters.filters;
}
catch (e) {}
console.log(`[${name}] Generating: ${metadata.id}${" ".repeat(20 - metadata.id.length)} ${metadata.filters ? "🔎with filters🔍" : "🚫no filters🚫"}`);
return generator(metadata);
});
return list.map((metadata: MadaraMetadata) => {
let filters: any = {};
try {
filters = require(`./filters/${metadata.id}`);
metadata.filters = filters.filters;
} catch (e) {}
console.log(
`[${name}] Generating: ${metadata.id}${' '.repeat(20 - metadata.id.length)} ${metadata.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
);
return generator(metadata);
});
};
const generator = function generator(metadata: MadaraMetadata) {
const madaraTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const madaraTemplate = readFileSync(path.join(__dirname, 'template.ts'), {
encoding: 'utf-8',
});
const pluginScript = `
const pluginScript = `
${madaraTemplate}
const plugin = new MadaraPlugin(${JSON.stringify(metadata)});
export default plugin;
`.trim();
return {
lang: metadata.options?.lang || "English",
filename: metadata.sourceName,
pluginScript,
};
return {
lang: metadata.options?.lang || 'English',
filename: metadata.sourceName,
pluginScript,
};
};
+185 -154
View File
@@ -3,177 +3,208 @@ import * as cheerio from 'cheerio';
import * as path from 'path';
function getFilters(name: string, html: string) {
const $:cheerio.CheerioAPI = cheerio.load(html);
const filters: any = {filters: {
"genre[]": {
type: "Checkbox",
label: "Genre",
value: [],
options: []
},
"op": {
type: "Switch",
label: "Having ALL selected genres",
value: false
},
"author": {
type: "Text",
label: "Author",
value: ""
},
"artist": {
type: "Text",
label: "Artist",
value: ""
},
"release": {
type: "Text",
label: "Year of Released",
value: ""
},
"adult": {
type: "Picker",
label: "Adult content",
value: "",
options: [],
},
"status[]": {
type: "Checkbox",
label: "Status",
value: [],
options: []
},
"m_orderby": {
type: "Picker",
label: "Order by",
value: "",
options: []
},
}};
const $: cheerio.CheerioAPI = cheerio.load(html);
const filters: any = {
filters: {
'genre[]': {
type: 'Checkbox',
label: 'Genre',
value: [],
options: [],
},
'op': {
type: 'Switch',
label: 'Having ALL selected genres',
value: false,
},
'author': {
type: 'Text',
label: 'Author',
value: '',
},
'artist': {
type: 'Text',
label: 'Artist',
value: '',
},
'release': {
type: 'Text',
label: 'Year of Released',
value: '',
},
'adult': {
type: 'Picker',
label: 'Adult content',
value: '',
options: [],
},
'status[]': {
type: 'Checkbox',
label: 'Status',
value: [],
options: [],
},
'm_orderby': {
type: 'Picker',
label: 'Order by',
value: '',
options: [],
},
},
};
const divs = $("form.search-advanced-form > div");
const divs = $('form.search-advanced-form > div');
// ==================== Genre ====================
const genreDiv = divs.eq(0);
genreDiv.find("label").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr("for") || "")
};
filters.filters["genre[]"].options.push(option);
});
// ==================== Genre ====================
const genreDiv = divs.eq(0);
genreDiv.find('label').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr('for') || ''),
};
filters.filters['genre[]'].options.push(option);
});
// ===================== Op ======================
const statusDiv = divs.eq(1);
filters.filters["op"].label = statusDiv.find("option").eq(1)
.text().replace("AND", "").replace("(", "").replace(")", "").trim();
// ===================== Op ======================
const statusDiv = divs.eq(1);
filters.filters['op'].label = statusDiv
.find('option')
.eq(1)
.text()
.replace('AND', '')
.replace('(', '')
.replace(')', '')
.trim();
// ==================== Author ====================
const authorDiv = divs.eq(2);
filters.filters["author"].label = authorDiv.find("span").text().trim();
// ==================== Author ====================
const authorDiv = divs.eq(2);
filters.filters['author'].label = authorDiv.find('span').text().trim();
// ==================== Artist ====================
const artistDiv = divs.eq(3);
filters.filters["artist"].label = artistDiv.find("span").text().trim();
// ==================== Artist ====================
const artistDiv = divs.eq(3);
filters.filters['artist'].label = artistDiv.find('span').text().trim();
// ==================== Release ====================
const releaseDiv = divs.eq(4);
filters.filters["release"].label = releaseDiv.find("span").text().trim();
// ==================== Release ====================
const releaseDiv = divs.eq(4);
filters.filters['release'].label = releaseDiv.find('span').text().trim();
// ==================== Adult ====================
const adultDiv = divs.eq(5);
filters.filters["adult"].label = adultDiv.find("span").text().trim();
adultDiv.find("option").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr("value") || "")
};
filters.filters["adult"].options.push(option);
});
// ==================== Adult ====================
const adultDiv = divs.eq(5);
filters.filters['adult'].label = adultDiv.find('span').text().trim();
adultDiv.find('option').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr('value') || ''),
};
filters.filters['adult'].options.push(option);
});
// ==================== Status ====================
const statusDiv2 = divs.eq(6);
filters.filters["status[]"].label = statusDiv2.find("span").text().trim();
statusDiv2.find("label").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: $(el).attr("for")
};
filters.filters["status[]"].options.push(option);
});
// ==================== Status ====================
const statusDiv2 = divs.eq(6);
filters.filters['status[]'].label = statusDiv2.find('span').text().trim();
statusDiv2.find('label').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: $(el).attr('for'),
};
filters.filters['status[]'].options.push(option);
});
// ==================== Order by ====================
const orderByDiv = $("div.c-nav-tabs").eq(0);
filters.filters["m_orderby"].label = orderByDiv.find("span").text().trim();
orderByDiv.find("a").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI(($(el).attr("href")?.split("=").length == 3 ? $(el).attr("href")?.split("=")[2] : "") || "")
};
filters.filters["m_orderby"].options.push(option);
});
// ==================== Order by ====================
const orderByDiv = $('div.c-nav-tabs').eq(0);
filters.filters['m_orderby'].label = orderByDiv.find('span').text().trim();
orderByDiv.find('a').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI(
($(el).attr('href')?.split('=').length == 3
? $(el).attr('href')?.split('=')[2]
: '') || '',
),
};
filters.filters['m_orderby'].options.push(option);
});
if (filters.filters["m_orderby"].options.length == 0 ||
filters.filters["status[]"].options.length == 0 ||
filters.filters["adult"].options.length == 0 ||
filters.filters["genre[]"].options.length == 0) {
console.error(`🚨Error in filters for ${name} please fix manually (${path.join(__dirname, 'filters', name + ".json")})🚨`);
}
if (
filters.filters['m_orderby'].options.length == 0 ||
filters.filters['status[]'].options.length == 0 ||
filters.filters['adult'].options.length == 0 ||
filters.filters['genre[]'].options.length == 0
) {
console.error(
`🚨Error in filters for ${name} please fix manually (${path.join(__dirname, 'filters', name + '.json')})🚨`,
);
}
fs.writeFileSync(
path.join(__dirname, 'filters', name + ".json"),
JSON.stringify(filters, null, 2)
);
console.log(`✅Filters created successfully for ${name}✅`);
fs.writeFileSync(
path.join(__dirname, 'filters', name + '.json'),
JSON.stringify(filters, null, 2),
);
console.log(`✅Filters created successfully for ${name}✅`);
}
async function getFiltersFromURL(name: string, url: string) {
const response = await fetch(url + "/?s=&post_type=wp-manga");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}, while fetching ${response.url}`);
}
const html = await response.text();
try {
getFilters(name, html);
} catch (e) {
console.error("Error while getting filters from", url);
}
const response = await fetch(url + '/?s=&post_type=wp-manga');
if (!response.ok) {
throw new Error(
`HTTP error! status: ${response.status}, while fetching ${response.url}`,
);
}
const html = await response.text();
try {
getFilters(name, html);
} catch (e) {
console.error('Error while getting filters from', url);
}
}
async function askGetFilter() {
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
async function askGetFilter(){
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const EREASE_PREV_LINE = '\x1b[1A\r\x1b[2K';
await readline.question('Enter the id of the site (same one as in sources.json): ', async (name: string) => {
await readline.question(EREASE_PREV_LINE + 'Do you want to get the filters from a URL or the html text? (if url dosen\'t work try html) (url/html): ', async (method: string) => {
if (method.toLowerCase() === "url") {
await readline.question(EREASE_PREV_LINE + 'Enter the URL (same one as in sources.json): ', async (url: string) => {
try {
await getFiltersFromURL(name, url);
} catch (e: any) {
console.error("Error while getting filters from", url);
console.log(e.message || e);
}
readline.close();
});
} else {
process.stdout.write(EREASE_PREV_LINE + `Enter the html text from the page at {sourceSite}/?s=&post_type=wp-manga (at the end press ENTER then press CTRL+C): `)
let html = "";
readline.on('SIGINT', () => {
console.log("Stopeed reading input, creating filters file");
getFilters(name, html);
readline.close();
});
readline.on('line', (line: string) => {
html += line + "\n";
});
}
});
});
const EREASE_PREV_LINE = '\x1b[1A\r\x1b[2K';
await readline.question(
'Enter the id of the site (same one as in sources.json): ',
async (name: string) => {
await readline.question(
EREASE_PREV_LINE +
"Do you want to get the filters from a URL or the html text? (if url dosen't work try html) (url/html): ",
async (method: string) => {
if (method.toLowerCase() === 'url') {
await readline.question(
EREASE_PREV_LINE +
'Enter the URL (same one as in sources.json): ',
async (url: string) => {
try {
await getFiltersFromURL(name, url);
} catch (e: any) {
console.error('Error while getting filters from', url);
console.log(e.message || e);
}
readline.close();
},
);
} else {
process.stdout.write(
EREASE_PREV_LINE +
`Enter the html text from the page at {sourceSite}/?s=&post_type=wp-manga (at the end press ENTER then press CTRL+C): `,
);
let html = '';
readline.on('SIGINT', () => {
console.log('Stopeed reading input, creating filters file');
getFilters(name, html);
readline.close();
});
readline.on('line', (line: string) => {
html += line + '\n';
});
}
},
);
},
);
}
askGetFilter();
+161 -129
View File
@@ -1,13 +1,13 @@
import { fetchApi, fetchFile } from "@libs/fetch";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { CheerioAPI, load as parseHTML } from "cheerio";
import { defaultCover } from "@libs/defaultCover";
import { NovelStatus } from "@libs/novelStatus";
import dayjs from "dayjs";
import { fetchApi, fetchFile } from '@libs/fetch';
import { Filters, FilterTypes } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
import { CheerioAPI, load as parseHTML } from 'cheerio';
import { defaultCover } from '@libs/defaultCover';
import { NovelStatus } from '@libs/novelStatus';
import dayjs from 'dayjs';
const includesAny = (str: string, keywords: string[]) =>
new RegExp(keywords.join("|")).test(str);
new RegExp(keywords.join('|')).test(str);
interface MadaraOptions {
useNewChapterEndpoint?: boolean;
@@ -45,157 +45,178 @@ class MadaraPlugin implements Plugin.PluginBase {
}
getHostname(url: string): string {
return url.split("/")[2];
return url.split('/')[2];
}
async getCheerio(url: string): Promise<CheerioAPI> {
const r = await fetchApi(url);
if (!r.ok) throw new Error("Could not reach site (" + r.status + ") try to open in webview.");
if (!r.ok)
throw new Error(
'Could not reach site (' + r.status + ') try to open in webview.',
);
const $ = parseHTML(await r.text());
const title = $("title").text().trim();
if (this.getHostname(url) != this.getHostname(r.url) ||
title == "Bot Verification" || title == "You are being redirected..." || title == "Un instant..." || title == "Just a moment..." || title == "Redirecting...")
throw new Error("Captcha error, please open in webview");
return ($);
const title = $('title').text().trim();
if (
this.getHostname(url) != this.getHostname(r.url) ||
title == 'Bot Verification' ||
title == 'You are being redirected...' ||
title == 'Un instant...' ||
title == 'Just a moment...' ||
title == 'Redirecting...'
)
throw new Error('Captcha error, please open in webview');
return $;
}
parseNovels(loadedCheerio: CheerioAPI): Plugin.NovelItem[] {
const novels: Plugin.NovelItem[] = [];
loadedCheerio(".manga-title-badges").remove();
loadedCheerio(".page-item-detail, .c-tabs-item__content").each((index, element) => {
const novelName = loadedCheerio(element).find(".post-title").text().trim();
const novelUrl = loadedCheerio(element).find(".post-title").find("a").attr("href") || "";
if (!novelName || !novelUrl) return;
const image = loadedCheerio(element).find("img");
const novelCover = image.attr("data-src") || image.attr("src");
const novel: Plugin.NovelItem = {
name: novelName,
cover: novelCover,
path: novelUrl.replace(this.site, ""),
};
novels.push(novel);
});
loadedCheerio('.manga-title-badges').remove();
loadedCheerio('.page-item-detail, .c-tabs-item__content').each(
(index, element) => {
const novelName = loadedCheerio(element)
.find('.post-title')
.text()
.trim();
const novelUrl =
loadedCheerio(element).find('.post-title').find('a').attr('href') ||
'';
if (!novelName || !novelUrl) return;
const image = loadedCheerio(element).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
const novel: Plugin.NovelItem = {
name: novelName,
cover: novelCover,
path: novelUrl.replace(this.site, ''),
};
novels.push(novel);
},
);
return novels;
}
async popularNovels(pageNo: number,{ filters, showLatestNovels }: Plugin.PopularNovelsOptions<typeof this.filters>): Promise<Plugin.NovelItem[]> {
let url = this.site + "/page/" + pageNo + "/?s=&post_type=wp-manga";
async popularNovels(
pageNo: number,
{
filters,
showLatestNovels,
}: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> {
let url = this.site + '/page/' + pageNo + '/?s=&post_type=wp-manga';
if (!filters) filters = {};
if (showLatestNovels) url += "&m_orderby=latest";
if (showLatestNovels) url += '&m_orderby=latest';
for (const key in filters) {
if (typeof filters[key].value === "object")
if (typeof filters[key].value === 'object')
for (const value of filters[key].value as string[])
url += `&${key}=${value}`;
else if (filters[key].value)
url += `&${key}=${filters[key].value}`;
else if (filters[key].value) url += `&${key}=${filters[key].value}`;
}
const loadedCheerio = await this.getCheerio(url);
return this.parseNovels(loadedCheerio);
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(this.site + novelPath).then((res) => res.text());
const body = await fetchApi(this.site + novelPath).then(res => res.text());
let loadedCheerio = parseHTML(body);
loadedCheerio(".manga-title-badges, #manga-title span").remove();
loadedCheerio('.manga-title-badges, #manga-title span').remove();
const novel: Plugin.SourceNovel = {
path: novelPath,
name:
loadedCheerio(".post-title h1").text().trim() ||
loadedCheerio("#manga-title h1").text(),
loadedCheerio('.post-title h1').text().trim() ||
loadedCheerio('#manga-title h1').text(),
};
novel.cover =
loadedCheerio(".summary_image > a > img").attr("data-lazy-src") ||
loadedCheerio(".summary_image > a > img").attr("data-src") ||
loadedCheerio(".summary_image > a > img").attr("src") ||
loadedCheerio(".summary_image > a > img").attr("src") ||
loadedCheerio('.summary_image > a > img').attr('data-lazy-src') ||
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCover;
loadedCheerio(".post-content_item, .post-content").each(function () {
const detailName = loadedCheerio(this).find("h5").text().trim();
const detail = loadedCheerio(this).find(".summary-content").text().trim();
loadedCheerio('.post-content_item, .post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();
switch (detailName) {
case "Genre(s)":
case "Género(s)":
case "التصنيفات":
case 'Genre(s)':
case 'Género(s)':
case 'التصنيفات':
novel.genres = detail;
break;
case "Author(s)":
case "Autor(es)":
case "المؤلف":
case "المؤلف (ين)":
case 'Author(s)':
case 'Autor(es)':
case 'المؤلف':
case 'المؤلف (ين)':
novel.author = detail;
break;
case "Status":
case "Estado":
case 'Status':
case 'Estado':
novel.status =
detail.includes("OnGoing") || detail.includes("مستمرة")
detail.includes('OnGoing') || detail.includes('مستمرة')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
loadedCheerio("div.summary__content .code-block,script").remove();
loadedCheerio('div.summary__content .code-block,script').remove();
novel.summary =
loadedCheerio("div.summary__content").text().trim() ||
loadedCheerio("#tab-manga-about").text().trim() ||
loadedCheerio('div.summary__content').text().trim() ||
loadedCheerio('#tab-manga-about').text().trim() ||
loadedCheerio('.post-content_item h5:contains("Summary")')
.next()
.text()
.trim();
const chapters: Plugin.ChapterItem[] = [];
let html = "";
let html = '';
if (this.options?.useNewChapterEndpoint) {
html = await fetchApi(this.site + novelPath + "ajax/chapters/", {
method: "POST",
}).then((res) => res.text());
html = await fetchApi(this.site + novelPath + 'ajax/chapters/', {
method: 'POST',
}).then(res => res.text());
} else {
const novelId =
loadedCheerio(".rating-post-id").attr("value") ||
loadedCheerio("#manga-chapters-holder").attr("data-id") ||
"";
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id') ||
'';
const formData = new FormData();
formData.append("action", "manga_get_chapters");
formData.append("manga", novelId);
formData.append('action', 'manga_get_chapters');
formData.append('manga', novelId);
html = await fetchApi(this.site + "wp-admin/admin-ajax.php", {
method: "POST",
html = await fetchApi(this.site + 'wp-admin/admin-ajax.php', {
method: 'POST',
body: formData,
}).then((res) => res.text());
}).then(res => res.text());
}
if (html !== "0") {
if (html !== '0') {
loadedCheerio = parseHTML(html);
}
const totalChapters = loadedCheerio(".wp-manga-chapter").length;
loadedCheerio(".wp-manga-chapter").each((chapterIndex, element) => {
const chapterName = loadedCheerio(element).find("a").text().trim();
const totalChapters = loadedCheerio('.wp-manga-chapter').length;
loadedCheerio('.wp-manga-chapter').each((chapterIndex, element) => {
const chapterName = loadedCheerio(element).find('a').text().trim();
let releaseDate = loadedCheerio(element)
.find("span.chapter-release-date")
.find('span.chapter-release-date')
.text()
.trim();
if (releaseDate) {
releaseDate = this.parseData(releaseDate);
} else {
releaseDate = dayjs().format("LL");
releaseDate = dayjs().format('LL');
}
let chapterUrl = loadedCheerio(element).find("a").attr("href") || "";
let chapterUrl = loadedCheerio(element).find('a').attr('href') || '';
chapters.push({
name: chapterName,
path: chapterUrl.replace(this.site, ""),
path: chapterUrl.replace(this.site, ''),
releaseTime: releaseDate || null,
chapterNumber: totalChapters - chapterIndex,
});
@@ -206,21 +227,32 @@ class MadaraPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
const chapterText =
loadedCheerio(".text-left").html() ||
loadedCheerio(".text-right").html() ||
loadedCheerio(".entry-content").html() ||
loadedCheerio(".c-blog-post > div > div:nth-child(2)").html() ||
"";
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
loadedCheerio('.entry-content').html() ||
loadedCheerio('.c-blog-post > div > div:nth-child(2)').html() ||
'';
return chapterText;
}
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
const url = this.site + "page/" + pageNo + "/?s=" + searchTerm + "&post_type=wp-manga";
async searchNovels(
searchTerm: string,
pageNo?: number | undefined,
): Promise<Plugin.NovelItem[]> {
const url =
this.site +
'page/' +
pageNo +
'/?s=' +
searchTerm +
'&post_type=wp-manga';
const loadedCheerio = await this.getCheerio(url);
return this.parseNovels(loadedCheerio);
}
@@ -229,66 +261,66 @@ class MadaraPlugin implements Plugin.PluginBase {
parseData = (date: string) => {
const dayJSDate = dayjs(); // today
const timeAgo = date.match(/\d+/)?.[0] || "";
const timeAgo = date.match(/\d+/)?.[0] || '';
const timeAgoInt = parseInt(timeAgo, 10);
if (!timeAgo) return date; // there is no number!
if (includesAny(date, ["detik", "segundo", "second", "วินาที"])) {
dayJSDate.subtract(timeAgoInt, "second"); // go back N seconds
if (includesAny(date, ['detik', 'segundo', 'second', 'วินาที'])) {
dayJSDate.subtract(timeAgoInt, 'second'); // go back N seconds
} else if (
includesAny(date, [
"menit",
"dakika",
"min",
"minute",
"minuto",
"นาที",
"دقائق",
'menit',
'dakika',
'min',
'minute',
'minuto',
'นาที',
'دقائق',
])
) {
dayJSDate.subtract(timeAgoInt, "minute"); // go back N minute
dayJSDate.subtract(timeAgoInt, 'minute'); // go back N minute
} else if (
includesAny(date, [
"jam",
"saat",
"heure",
"hora",
"hour",
"ชั่วโมง",
"giờ",
"ore",
"ساعة",
"小时",
'jam',
'saat',
'heure',
'hora',
'hour',
'ชั่วโมง',
'giờ',
'ore',
'ساعة',
'小时',
])
) {
dayJSDate.subtract(timeAgoInt, "hours"); // go back N hours
dayJSDate.subtract(timeAgoInt, 'hours'); // go back N hours
} else if (
includesAny(date, [
"hari",
"gün",
"jour",
"día",
"dia",
"day",
"วัน",
"ngày",
"giorni",
"أيام",
"天",
'hari',
'gün',
'jour',
'día',
'dia',
'day',
'วัน',
'ngày',
'giorni',
'أيام',
'天',
])
) {
dayJSDate.subtract(timeAgoInt, "days"); // go back N days
} else if (includesAny(date, ["week", "semana"])) {
dayJSDate.subtract(timeAgoInt, "week"); // go back N a week
} else if (includesAny(date, ["month", "mes"])) {
dayJSDate.subtract(timeAgoInt, "month"); // go back N months
} else if (includesAny(date, ["year", "año"])) {
dayJSDate.subtract(timeAgoInt, "year"); // go back N years
dayJSDate.subtract(timeAgoInt, 'days'); // go back N days
} else if (includesAny(date, ['week', 'semana'])) {
dayJSDate.subtract(timeAgoInt, 'week'); // go back N a week
} else if (includesAny(date, ['month', 'mes'])) {
dayJSDate.subtract(timeAgoInt, 'month'); // go back N months
} else if (includesAny(date, ['year', 'año'])) {
dayJSDate.subtract(timeAgoInt, 'year'); // go back N years
} else {
return date;
}
return dayJSDate.format("LL");
return dayJSDate.format('LL');
};
}
+18 -15
View File
@@ -1,16 +1,18 @@
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";
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 (name) {
return list
.map<ReadwnMetadata>((p) => {
.map<ReadwnMetadata>(p => {
p.filters.tags.options.unshift(...defaultSettings.filters.tags.options);
p.filters.genres.options.unshift(...defaultSettings.filters.genres.options);
p.filters.genres.options.unshift(
...defaultSettings.filters.genres.options,
);
p.filters = Object.assign(defaultSettings.filters, p.filters);
const d = false;
@@ -33,8 +35,8 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
};
const generator = function generator(metadata: ReadwnMetadata) {
const readwnTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
const readwnTemplate = readFileSync(path.join(__dirname, 'template.ts'), {
encoding: 'utf-8',
});
//metadata.filters = {
@@ -45,14 +47,15 @@ const generator = function generator(metadata: ReadwnMetadata) {
const pluginScript = `
${readwnTemplate}
const plugin = new ReadwnPlugin(${
JSON.stringify(metadata).replace(/"type":"([^"]+)"/g, '"type":FilterTypes.$1')
});
const plugin = new ReadwnPlugin(${JSON.stringify(metadata).replace(
/"type":"([^"]+)"/g,
'"type":FilterTypes.$1',
)});
export default plugin;
`.trim();
return {
lang: "english",
lang: 'english',
filename: metadata.sourceName,
pluginScript,
};
+74 -68
View File
@@ -1,10 +1,10 @@
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 dayjs from "dayjs";
import qs from "qs";
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 dayjs from 'dayjs';
import qs from 'qs';
export interface ReadwnMetadata {
id: string;
@@ -26,7 +26,7 @@ class ReadwnPlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/readwn/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.version = '1.0.0';
this.filters = metadata.filters;
}
@@ -34,115 +34,115 @@ class ReadwnPlugin implements Plugin.PluginBase {
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";
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";
url = this.site + '/tags/' + filters.tags.value + '-0.html';
}
const body = await fetchApi(url).then((res) => res.text());
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = loadedCheerio("li.novel-item")
const novels: Plugin.NovelItem[] = loadedCheerio('li.novel-item')
.map((index, element) => ({
name: loadedCheerio(element).find("h4").text() || "",
name: loadedCheerio(element).find('h4').text() || '',
cover:
this.site +
loadedCheerio(element).find(".novel-cover > img").attr("data-src"),
path: loadedCheerio(element).find("a").attr("href") || "",
loadedCheerio(element).find('.novel-cover > img').attr('data-src'),
path: loadedCheerio(element).find('a').attr('href') || '',
}))
.get()
.filter((novel) => novel.name && novel.path);
.filter(novel => novel.name && novel.path);
return novels;
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(this.site + novelPath).then((res) => res.text());
const body = await fetchApi(this.site + novelPath).then(res => res.text());
const loadedCheerio = parseHTML(body);
const novel: Plugin.SourceNovel = {
path: novelPath,
name: loadedCheerio("h1.novel-title").text() || "",
name: loadedCheerio('h1.novel-title').text() || '',
};
novel.author = loadedCheerio("span[itemprop=author]").text();
novel.author = loadedCheerio('span[itemprop=author]').text();
novel.cover =
this.site + loadedCheerio("figure.cover > img").attr("data-src");
this.site + loadedCheerio('figure.cover > img').attr('data-src');
novel.summary = loadedCheerio(".summary")
novel.summary = loadedCheerio('.summary')
.text()
.replace("Summary", "")
.replace('Summary', '')
.trim();
novel.genres = loadedCheerio("div.categories > ul > li")
novel.genres = loadedCheerio('div.categories > ul > li')
.map((index, element) => loadedCheerio(element).text()?.trim())
.get()
.join(",");
.join(',');
loadedCheerio("div.header-stats > span").each(function () {
if (loadedCheerio(this).find("small").text() === "Status") {
loadedCheerio('div.header-stats > span').each(function () {
if (loadedCheerio(this).find('small').text() === 'Status') {
novel.status =
loadedCheerio(this).find("strong").text() === "Ongoing"
loadedCheerio(this).find('strong').text() === 'Ongoing'
? NovelStatus.Ongoing
: NovelStatus.Completed;
}
});
const latestChapterNo = parseInt(
loadedCheerio(".header-stats")
.find("span > strong")
loadedCheerio('.header-stats')
.find('span > strong')
.first()
.text()
.trim(),
);
const chapters: Plugin.ChapterItem[] = loadedCheerio(".chapter-list li")
const chapters: Plugin.ChapterItem[] = loadedCheerio('.chapter-list li')
.map((chapterIndex, element) => {
const name = loadedCheerio(element)
.find("a .chapter-title")
.find('a .chapter-title')
.text()
.trim();
const path = loadedCheerio(element).find("a").attr("href")?.trim();
const path = loadedCheerio(element).find('a').attr('href')?.trim();
if (!name || !path) return null;
let releaseTime = loadedCheerio(element)
.find("a .chapter-update")
.find('a .chapter-update')
.text()
.trim();
if (releaseTime?.includes?.("ago")) {
const timeAgo = releaseTime.match(/\d+/)?.[0] || "0";
if (releaseTime?.includes?.('ago')) {
const timeAgo = releaseTime.match(/\d+/)?.[0] || '0';
const timeAgoInt = parseInt(timeAgo, 10);
if (timeAgoInt) {
const dayJSDate = dayjs(); // today
if (
releaseTime.includes("hours ago") ||
releaseTime.includes("hour ago")
releaseTime.includes('hours ago') ||
releaseTime.includes('hour ago')
) {
dayJSDate.subtract(timeAgoInt, "hours"); // go back N hours
dayJSDate.subtract(timeAgoInt, 'hours'); // go back N hours
}
if (
releaseTime.includes("days ago") ||
releaseTime.includes("day ago")
releaseTime.includes('days ago') ||
releaseTime.includes('day ago')
) {
dayJSDate.subtract(timeAgoInt, "days"); // go back N days
dayJSDate.subtract(timeAgoInt, 'days'); // go back N days
}
if (
releaseTime.includes("months ago") ||
releaseTime.includes("month ago")
releaseTime.includes('months ago') ||
releaseTime.includes('month ago')
) {
dayJSDate.subtract(timeAgoInt, "months"); // go back N months
dayJSDate.subtract(timeAgoInt, 'months'); // go back N months
}
releaseTime = dayJSDate.format("LL");
releaseTime = dayJSDate.format('LL');
}
}
@@ -154,18 +154,22 @@ class ReadwnPlugin implements Plugin.PluginBase {
};
})
.get()
.filter((chapter) => chapter);
.filter(chapter => chapter);
if (latestChapterNo > chapters.length) {
const lastChapterNo = parseInt(
chapters[chapters.length - 1].path.match(/_(\d+)\.html/)?.[1] || "",
chapters[chapters.length - 1].path.match(/_(\d+)\.html/)?.[1] || '',
10,
);
for (let i = (lastChapterNo || chapters.length) + 1; i <= latestChapterNo; i++) {
for (
let i = (lastChapterNo || chapters.length) + 1;
i <= latestChapterNo;
i++
) {
chapters.push({
name: "Chapter " + i,
path: novelPath.replace(".html", "_" + i + ".html"),
name: 'Chapter ' + i,
path: novelPath.replace('.html', '_' + i + '.html'),
releaseTime: null,
chapterNumber: i,
});
@@ -177,38 +181,40 @@ class ReadwnPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
const chapterText = loadedCheerio(".chapter-content").html() || "";
const chapterText = loadedCheerio('.chapter-content').html() || '';
return chapterText;
}
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const result = await fetchApi(this.site + "/e/search/index.php", {
const result = await fetchApi(this.site + '/e/search/index.php', {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Referer: this.site + "/search.html",
'Content-Type': 'application/x-www-form-urlencoded',
Referer: this.site + '/search.html',
Origin: this.site,
},
method: "POST",
method: 'POST',
body: qs.stringify({
show: "title",
show: 'title',
tempid: 1,
tbname: "news",
tbname: 'news',
keyboard: searchTerm,
}),
}).then((res) => res.text());
}).then(res => res.text());
const loadedCheerio = parseHTML(result);
const novels: Plugin.NovelItem[] = loadedCheerio("li.novel-item")
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"),
path: loadedCheerio(element).find("a").attr("href") || "",
name: loadedCheerio(element).find('h4').text() || '',
cover: this.site + loadedCheerio(element).find('img').attr('data-src'),
path: loadedCheerio(element).find('a').attr('href') || '',
}))
.get()
.filter((novel) => novel.name && novel.path);
.filter(novel => novel.name && novel.path);
return novels;
}
+13 -13
View File
@@ -1,14 +1,14 @@
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";
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 (name) {
return list
.map<RulateMetadata>((p) => {
.map<RulateMetadata>(p => {
if (p.filters) {
p.filters.cat.options.unshift(...defaultSettings.filters.cat.options);
}
@@ -34,21 +34,21 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
};
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)
.replace(/"type":"([^"]+)"/g, '"type":FilterTypes.$1')
.replace(/\.XCheckbox/g, ".ExcludableCheckboxGroup") //remember to redo
.replace(/\.Checkbox/g, ".CheckboxGroup")});
.replace(/\.XCheckbox/g, '.ExcludableCheckboxGroup') //remember to redo
.replace(/\.Checkbox/g, '.CheckboxGroup')});
export default plugin;
`.trim();
return {
lang: "russian",
lang: 'russian',
filename: metadata.sourceName,
pluginScript,
};
+78 -74
View File
@@ -1,9 +1,9 @@
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 dayjs from "dayjs";
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 dayjs from 'dayjs';
export interface RulateMetadata {
id: string;
@@ -25,7 +25,7 @@ class RulatePlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/rulate/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.version = '1.0.0';
this.filters = metadata.filters;
}
@@ -34,35 +34,37 @@ class RulatePlugin implements Plugin.PluginBase {
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
let url = this.site + "/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");
let url = this.site + '/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');
Object.entries(filters || {}).forEach(([type, { value }]) => {
if (value instanceof Array && value.length) {
url += "&" + value
.map((val) => (type == "extra" ? val + "=1" : type + "[]=" + val))
.join("&");
url +=
'&' +
value
.map(val => (type == 'extra' ? val + '=1' : type + '[]=' + val))
.join('&');
}
});
url += "&Book_page=" + pageNo;
url += '&Book_page=' + pageNo;
const body = await fetchApi(url).then((res) => res.text());
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((index, element) => {
loadedCheerio(element).find("p > a").text();
const name = loadedCheerio(element).find("p > a").text();
const cover = loadedCheerio(element).find("img").attr("src");
const path = loadedCheerio(element).find("p > a").attr("href");
loadedCheerio(element).find('p > a').text();
const name = loadedCheerio(element).find('p > a').text();
const cover = loadedCheerio(element).find('img').attr('src');
const path = loadedCheerio(element).find('p > a').attr('href');
if (!name || !path) return;
novels.push({ name, cover: this.site + cover, path });
@@ -73,13 +75,13 @@ class RulatePlugin implements Plugin.PluginBase {
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
let result = await fetchApi(this.site + novelPath);
if (result.url.includes("mature?path=")) {
if (result.url.includes('mature?path=')) {
const formData = new FormData();
formData.append("path", novelPath);
formData.append("ok", "Да");
formData.append('path', novelPath);
formData.append('ok', 'Да');
await fetchApi(result.url, {
method: "POST",
method: 'POST',
body: formData,
});
@@ -96,41 +98,41 @@ class RulatePlugin implements Plugin.PluginBase {
.text()
.trim(),
};
if (novel.name?.includes?.("[")) {
novel.name = novel.name.split("[")[0].trim();
if (novel.name?.includes?.('[')) {
novel.name = novel.name.split('[')[0].trim();
}
novel.cover =
this.site + loadedCheerio('div[class="images"] > div img').attr("src");
novel.summary = loadedCheerio("#Info > div:nth-child(3), .book-description")
this.site + 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)",
'.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(
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();
switch (loadedCheerio(this).find('strong').text()) {
case 'Автор:':
novel.author = loadedCheerio(this).find('em > a').text().trim();
break;
case "Выпуск:":
case 'Выпуск:':
novel.status =
loadedCheerio(this).find("em").text().trim() === "продолжается"
loadedCheerio(this).find('em').text().trim() === 'продолжается'
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
case "Тэги:":
case 'Тэги:':
loadedCheerio(this)
.find("em > a")
.find('em > a')
.each(function () {
genres.push(loadedCheerio(this).text());
});
break;
case "Жанры:":
case 'Жанры:':
loadedCheerio(this)
.find("em > a")
.find('em > a')
.each(function () {
genres.push(loadedCheerio(this).text());
});
@@ -140,23 +142,23 @@ class RulatePlugin implements Plugin.PluginBase {
);
if (genres.length) {
novel.genres = genres.reverse().join(",");
novel.genres = genres.reverse().join(',');
}
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio("table > tbody > tr.chapter_row").each(
loadedCheerio('table > tbody > tr.chapter_row').each(
(chapterIndex, element) => {
const chapterName = loadedCheerio(element)
.find('td[class="t"] > a')
.text()
.trim();
const releaseDate = loadedCheerio(element)
.find("td > span")
.attr("title")
.find('td > span')
.attr('title')
?.trim();
const chapterUrl = loadedCheerio(element)
.find('td[class="t"] > a')
.attr("href");
.attr('href');
if (
!loadedCheerio(element).find('td > span[class="disabled"]').length &&
@@ -179,12 +181,12 @@ class RulatePlugin implements Plugin.PluginBase {
async parseChapter(chapterPath: string): Promise<string> {
let result = await fetchApi(this.site + chapterPath);
if (result.url.includes("mature?path=")) {
if (result.url.includes('mature?path=')) {
const formData = new FormData();
formData.append("ok", "Да");
formData.append('ok', 'Да');
await fetchApi(result.url, {
method: "POST",
method: 'POST',
body: formData,
});
@@ -193,26 +195,26 @@ class RulatePlugin implements Plugin.PluginBase {
const body = await result.text();
const loadedCheerio = parseHTML(body);
loadedCheerio(".content-text img").each((index, element) => {
if (!loadedCheerio(element).attr("src")?.startsWith("http")) {
const src = loadedCheerio(element).attr("src");
loadedCheerio(element).attr("src", this.site + src);
loadedCheerio('.content-text img').each((index, element) => {
if (!loadedCheerio(element).attr('src')?.startsWith('http')) {
const src = loadedCheerio(element).attr('src');
loadedCheerio(element).attr('src', this.site + src);
}
});
const chapterText = loadedCheerio(".content-text").html();
return chapterText || "";
const chapterText = loadedCheerio('.content-text').html();
return chapterText || '';
}
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const result = await fetchApi(
this.site + "/search/autocomplete?query=" + searchTerm,
this.site + '/search/autocomplete?query=' + searchTerm,
);
const json = (await result.json()) as response[];
json.forEach((novel) => {
const name = novel.title_one + " / " + novel.title_two;
json.forEach(novel => {
const name = novel.title_one + ' / ' + novel.title_two;
if (!novel.url) return;
novels.push({
@@ -225,24 +227,26 @@ class RulatePlugin implements Plugin.PluginBase {
return novels;
}
parseDate = (dateString: string | undefined = "") => {
parseDate = (dateString: string | undefined = '') => {
const months: { [key: string]: number } = {
"янв.": 1,
"февр.": 2,
"мар.": 3,
"апр.": 4,
'янв.': 1,
'февр.': 2,
'мар.': 3,
'апр.': 4,
мая: 5,
"июн.": 6,
"июл.": 7,
"авг.": 8,
"сент.": 9,
"окт.": 10,
"нояб.": 11,
"дек.": 12,
'июн.': 6,
'июл.': 7,
'авг.': 8,
'сент.': 9,
'окт.': 10,
'нояб.': 11,
'дек.': 12,
};
const [day, month, year, , time] = dateString.split(" ");
const [day, month, year, , time] = dateString.split(' ');
if (day && months[month] && year && time) {
return dayjs(year + "-" + months[month] + "-" + day + " " + time).format("LLL");
return dayjs(year + '-' + months[month] + '-' + day + ' ' + time).format(
'LLL',
);
}
return dateString || null;
};