refactor: Classes for Plugins (#631)
* set target to ES5 * refactor types * use .gitkeep * use dot to make dist/js dirs on top * add hako * add Hako * add madara * fix: url path js -> .js * fix: branch * freestyle for using UA, cookie * add parseNovels for Hako * update readme * fix: conflict types * add Kolnovel, remove node-fetch * add bestlightnovel * add plugins * WQMangaStreamScraper * PandaMTL * NobleMTL * LightNovelBrasil * WPMangaStream * add filters for popularNovels * fix undefined json * Linovelib (#26) * linovelib CN * icon for linovelib * fix undefined chapter * add check * fix: add artist * TuNovelaLigera ES + Madara Fix (#28) * app repo test * POST is now working * update madara template + run generator * template fix didnt get pushed commited idk why * template update POST * generated * fix: useNewChapterEndpoint update (#29) * useNewChapterEndpoint update * Update Selectors --------- Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
This commit is contained in:
@@ -1,56 +1,72 @@
|
||||
import { CheerioAPI, load as parseHTML } from "cheerio";
|
||||
import { fetchApi, fetchFile } from "@libs/fetch";
|
||||
import { load as parseHTML } from "cheerio";
|
||||
import { NovelStatus } from "@libs/novelStatus";
|
||||
import { Filter, FilterInputs } from "@libs/filterInputs";
|
||||
import { Plugin } from "@typings/plugin";
|
||||
import { showToast } from "@libs/showToast";
|
||||
import { defaultCover } from "@libs/defaultCover";
|
||||
import { Chapter, Novel, Plugin } from "@typings/plugin";
|
||||
import { NovelStatus } from "@libs/novelStatus";
|
||||
|
||||
export const id = "TNL.com";
|
||||
export const name = "TuNovelaLigera";
|
||||
export const site = "https://tunovelaligera.com/";
|
||||
export const version = "1.0.0";
|
||||
export const icon = "src/es/tunovelaligera/icon.png";
|
||||
class TuNovelaLigera implements Plugin.PluginBase {
|
||||
id = "tunovelaligera";
|
||||
name = "TuNovelaLigera";
|
||||
icon = "src/es/tunovelaligera/icon.png";
|
||||
site = "https://tunovelaligera.com/";
|
||||
version = "1.0.0";
|
||||
userAgent = "";
|
||||
cookieString = "";
|
||||
|
||||
const baseUrl = site;
|
||||
async popularNovels(pageNo: number, {filters}: Plugin.PopularNovelsOptions): Promise<Plugin.NovelItem[]> {
|
||||
let link = `${this.site}`;
|
||||
|
||||
export const popularNovels: Plugin.popularNovels = async function (page) {
|
||||
let url = baseUrl + "novelas/page/" + page + "/?m_orderby=rating";
|
||||
link += (filters?.genres ? `genero/` + filters.genres : "novelas");
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
link += `/page/${pageNo}`;
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
link += (filters?.order ? filters.order : "?m_orderby=rating")
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
const headers = new Headers();
|
||||
if(this.cookieString){
|
||||
headers.append("cookie", this.cookieString);
|
||||
}
|
||||
const result = await fetchApi(link, {headers})
|
||||
const body = await result.text();
|
||||
|
||||
loadedCheerio(".page-item-detail").each(function () {
|
||||
const novelName = loadedCheerio(this).find(".h5 > a").text();
|
||||
const novelCover = loadedCheerio(this).find("img").attr("src");
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novelUrl = loadedCheerio(this).find(".h5 > a").attr("href");
|
||||
if (!novelUrl) return;
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
loadedCheerio(".page-item-detail").each((i,el) => {
|
||||
const novelName = loadedCheerio(el).find(".h5 > a").text();
|
||||
const novelCover = loadedCheerio(el).find("img").attr("src");
|
||||
const novelUrl = loadedCheerio(el).find(".h5 > a").attr("href");
|
||||
|
||||
return novels;
|
||||
};
|
||||
if (!novelUrl) return;
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
async function (novelUrl) {
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const url = novelUrl;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const headers = new Headers();
|
||||
if(this.cookieString){
|
||||
headers.append("cookie", this.cookieString);
|
||||
}
|
||||
const result = await fetchApi(url, {headers});
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
let novel: Novel.instance = {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
url,
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
loadedCheerio(".manga-title-badges").remove();
|
||||
@@ -62,6 +78,7 @@ export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
novel.cover =
|
||||
novelCover.attr("data-src") ||
|
||||
novelCover.attr("src") ||
|
||||
novelCover.attr('data-cfsrc') ||
|
||||
defaultCover;
|
||||
|
||||
loadedCheerio(".post-content_item").each(function () {
|
||||
@@ -93,69 +110,264 @@ export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
|
||||
|
||||
novel.summary = loadedCheerio("div.summary__content > p").text().trim();
|
||||
|
||||
let novelChapters: Chapter.Item[] = [];
|
||||
let chapter: Plugin.ChapterItem[] = [];
|
||||
|
||||
loadedCheerio(".lcp_catlist li").each(function () {
|
||||
const chapterName = loadedCheerio(this)
|
||||
.find("a")
|
||||
.text()
|
||||
.replace(/[\t\n]/g, "")
|
||||
.trim();
|
||||
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
let lastPage = 1;
|
||||
lastPage = +loadedCheerio('.lcp_paginator li:last').prev().text();
|
||||
|
||||
const releaseDate = loadedCheerio(this).find("span").text().trim();
|
||||
const getChapters = async () => {
|
||||
const n = url.split('/');
|
||||
const novelName = n[4];
|
||||
showToast('Cargando desde Archivo...');
|
||||
|
||||
let chapterUrl = loadedCheerio(this).find("a").attr("href");
|
||||
if (!chapterUrl) return;
|
||||
novelChapters.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
const formData = new FormData()
|
||||
formData.append("action", "madara_load_more");
|
||||
formData.append("page", "0");
|
||||
formData.append("template", "html/loop/content");
|
||||
formData.append("vars[category_name]", novelName);
|
||||
formData.append("vars[posts_per_page]", "10000");
|
||||
|
||||
const result = await fetchApi(
|
||||
`${this.site}wp-admin/admin-ajax.php`,
|
||||
{
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers
|
||||
},
|
||||
);
|
||||
const text = await result.text();
|
||||
|
||||
loadedCheerio = parseHTML(text);
|
||||
|
||||
loadedCheerio('.heading').each((i, el) => {
|
||||
const chapterName = loadedCheerio(el)
|
||||
.text()
|
||||
.replace(/[\t\n]/g, '')
|
||||
.trim();
|
||||
const releaseDate = null;
|
||||
const chapterUrl = loadedCheerio(el).find('a').attr('href') || "";
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
url: chapterUrl,
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
});
|
||||
});
|
||||
return chapter.reverse();
|
||||
};
|
||||
|
||||
const getPageChapters = async () => {
|
||||
for (let i = 1; i <= lastPage; i++) {
|
||||
const chaptersUrl = `${novelUrl}?lcp_page0=${i}`;
|
||||
showToast(`Cargando desde la página ${i}/${lastPage}...`);
|
||||
const result = await fetchApi(chaptersUrl, {headers});
|
||||
const chaptersHTML = await result.text();
|
||||
|
||||
novel.chapters = novelChapters.reverse();
|
||||
let chapterCheerio = parseHTML(chaptersHTML);
|
||||
|
||||
chapterCheerio('.lcp_catlist li').each((i, el) => {
|
||||
const chapterName = chapterCheerio(el)
|
||||
.find('a')
|
||||
.text()
|
||||
.replace(/[\t\n]/g, '')
|
||||
.trim();
|
||||
|
||||
const releaseDate = chapterCheerio(el)
|
||||
.find('span')
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
const chapterUrl =
|
||||
chapterCheerio(el).find('a').attr('href') || "";
|
||||
|
||||
chapter.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
url: chapterUrl,
|
||||
});
|
||||
});
|
||||
await delay(1000);
|
||||
}
|
||||
return chapter.reverse();
|
||||
}
|
||||
|
||||
novel.chapters = await getChapters();
|
||||
|
||||
if (!novel.chapters.length) {
|
||||
showToast('¡Archivo no encontrado!');
|
||||
await delay(1000);
|
||||
novel.chapters = await getPageChapters();
|
||||
}
|
||||
|
||||
return novel;
|
||||
}
|
||||
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const headers = new Headers();
|
||||
if(this.cookieString){
|
||||
headers.append("cookie", this.cookieString);
|
||||
}
|
||||
const result = await fetchApi(chapterUrl);
|
||||
const body = await result.text();
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
loadedCheerio("#hola_siguiente").next().find('div').remove();
|
||||
const chapterText = loadedCheerio("#hola_siguiente").next().html() || "";
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
|
||||
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
|
||||
const url = chapterUrl;
|
||||
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}?s=${searchTerm}&post_type=wp-manga`;
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let chapterText = loadedCheerio("#hola_siguiente").next().text();
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
return chapterText;
|
||||
};
|
||||
loadedCheerio(".c-tabs-item__content").each((i, el) => {
|
||||
const novelName = loadedCheerio(el).find(".h4 > a").text();
|
||||
const novelCover = loadedCheerio(el).find("img").attr("src");
|
||||
const novelUrl = loadedCheerio(el).find(".h4 > a").attr("href");
|
||||
if (!novelUrl) return;
|
||||
novels.push({
|
||||
name: novelName,
|
||||
url: novelUrl,
|
||||
cover: novelCover,
|
||||
});
|
||||
});
|
||||
|
||||
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
|
||||
const url = `${baseUrl}?s=${searchTerm}&post_type=wp-manga`;
|
||||
return novels;
|
||||
};
|
||||
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
return await fetchFile(url);
|
||||
}
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
filters = [
|
||||
{
|
||||
key: "order",
|
||||
label: "Ordenado por",
|
||||
values: [
|
||||
{ label: "Lo mas reciente", value: "?m_orderby=latest" },
|
||||
|
||||
let novels: Novel.Item[] = [];
|
||||
{ label: "A-Z", value: "?m_orderby=alphabet" },
|
||||
|
||||
{ label: "Clasificación", value: "?m_orderby=rating" },
|
||||
|
||||
{ label: "Trending", value: "?m_orderby=trending" },
|
||||
|
||||
{ label: "Mas visto", value: "?m_orderby=views" },
|
||||
|
||||
{ label: "Nuevo", value: "?m_orderby=new-manga" },
|
||||
],
|
||||
inputType: FilterInputs.Picker,
|
||||
},
|
||||
{
|
||||
key: "genres",
|
||||
label: "Generos",
|
||||
values: [
|
||||
{ label: "Acción", value: "accion" },
|
||||
|
||||
loadedCheerio(".c-tabs-item__content").each(function () {
|
||||
const novelName = loadedCheerio(this).find(".h4 > a").text();
|
||||
const novelCover = loadedCheerio(this).find("img").attr("src");
|
||||
{ label: "Adulto", value: "adulto" },
|
||||
|
||||
{ label: "Artes Marciales", value: "artes-marciales" },
|
||||
|
||||
{ label: "Aventura", value: "aventura" },
|
||||
|
||||
{ label: "Ciencia Ficción", value: "ciencia-ficcion" },
|
||||
|
||||
{ label: "Comedia", value: "comedia" },
|
||||
|
||||
{ label: "Deportes", value: "deportes" },
|
||||
|
||||
{ label: "Drama", value: "drama" },
|
||||
|
||||
{ label: "Eastern Fantasy", value: "eastern-fantasy" },
|
||||
|
||||
{ label: "Ecchi", value: "ecchi" },
|
||||
|
||||
{ label: "FanFiction", value: "fan-fiction" },
|
||||
|
||||
{ label: "Fantasía", value: "fantasia" },
|
||||
|
||||
{ label: "Fantasía oriental", value: "fantasia-oriental" },
|
||||
|
||||
{ label: "Ficción Romántica", value: "ficcion-romantica" },
|
||||
|
||||
{ label: "Gender Bender", value: "gender-bender" },
|
||||
|
||||
{ label: "Harem", value: "harem" },
|
||||
|
||||
{ label: "Histórico", value: "historico" },
|
||||
|
||||
{ label: "Horror", value: "horror" },
|
||||
|
||||
{ label: "Josei", value: "josei" },
|
||||
|
||||
{ label: "Maduro", value: "maduro" },
|
||||
|
||||
{ label: "Mecha", value: "mecha" },
|
||||
|
||||
{ label: "Misterio", value: "misterio" },
|
||||
|
||||
{ label: "Novela China", value: "novela-china" },
|
||||
|
||||
{ label: "Novela FanFiction", value: "novela-fanfiction" },
|
||||
|
||||
{ label: "Novela Japonesa", value: "novela-japonesa" },
|
||||
|
||||
{ label: "Novela Koreana", value: "novela-koreana" },
|
||||
|
||||
{ label: "Novela ligera", value: "novela-ligera" },
|
||||
|
||||
{ label: "Novela original", value: "novela-original" },
|
||||
|
||||
{ label: "Novela Web", value: "web-novel" },
|
||||
|
||||
{ label: "Psicológico", value: "psicologico" },
|
||||
|
||||
{ label: "Realismo Mágico", value: "realismo-magico" },
|
||||
|
||||
{ label: "Recuento de vida", value: "recuento-de-vida" },
|
||||
|
||||
{ label: "Romance", value: "romance" },
|
||||
|
||||
{ label: "Romance contemporáneo", value: "romance-contemporaneo" },
|
||||
|
||||
{ label: "Romance Moderno", value: "romance-moderno" },
|
||||
|
||||
{ label: "Seinen", value: "seinen" },
|
||||
|
||||
{ label: "Shoujo", value: "shoujo" },
|
||||
|
||||
{ label: "Shounen", value: "shounen" },
|
||||
|
||||
{ label: "Sobrenatural", value: "sobrenatural" },
|
||||
|
||||
{ label: "Tragedia", value: "tragedia" },
|
||||
|
||||
{ label: "Vampiros", value: "vampiros" },
|
||||
|
||||
{ label: "Vida Escolar", value: "vida-escolar" },
|
||||
|
||||
{ label: "Western Fantasy", value: "western-fantasy" },
|
||||
|
||||
{ label: "Wuxia", value: "wuxia" },
|
||||
|
||||
{ label: "Xianxia", value: "xianxia" },
|
||||
|
||||
{ label: "Xuanhuan", value: "xuanhuan" },
|
||||
|
||||
{ label: "Yaoi", value: "yaoi" },
|
||||
],
|
||||
inputType: FilterInputs.Picker,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
let novelUrl = loadedCheerio(this).find(".h4 > a").attr("href");
|
||||
if (!novelUrl) return;
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
url: novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
export const fetchImage: Plugin.fetchImage = fetchFile;
|
||||
export default new TuNovelaLigera();
|
||||
|
||||
Reference in New Issue
Block a user