diff --git a/README.md b/README.md index b6bf366..6a81991 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader) | https://yuukitls.com/ | :heavy_check_mark: | | https://hasutl.wordpress.com/ | :heavy_check_mark: | | https://oasistranslations.wordpress.com/ | :heavy_check_mark: | +| http://www.novelawuxia.com/ | :heavy_check_mark: | ## Setup locally diff --git a/index.js b/index.js index 96f433c..07a9815 100644 --- a/index.js +++ b/index.js @@ -51,6 +51,7 @@ app.use("/api/26/", require("./src/es/novelasligera/NovelasLigera")); app.use("/api/28/", require("./src/es/yuukitls/YuukiTls")); app.use("/api/29/", require("./src/es/hasutl/Hasutl")); app.use("/api/30/", require("./src/es/oasistranslations/OasisTranslations")); +app.use("/api/31/", require("./src/es/novelawuxia/NovelaWuxia")); const PORT = process.env.PORT || 5000; diff --git a/sources.js b/sources.js index e5339c5..62a2cc1 100644 --- a/sources.js +++ b/sources.js @@ -278,6 +278,15 @@ extensions = [ sourceLanguage: "Spanish", status: 1, }, + { + sourceId: 31, + sourceUrl: "http://www.novelawuxia.com/", + sourceName: "Novela Wuxia", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/es/novelawuxia/icon.png?raw=true", + sourceLanguage: "Spanish", + status: 1, + }, ]; module.exports = extensions; diff --git a/src/es/novelawuxia/NovelaWuxia.js b/src/es/novelawuxia/NovelaWuxia.js new file mode 100644 index 0000000..511b9b1 --- /dev/null +++ b/src/es/novelawuxia/NovelaWuxia.js @@ -0,0 +1,17 @@ +const express = require("express"); +const NovelaWuxiaScraper = require("./NovelaWuxiaScraper"); + +const router = express.Router(); + +router.get("/novels/", NovelaWuxiaScraper.novelsScraper); + +router.get("/novel/:novelUrl", NovelaWuxiaScraper.novelScraper); + +router.get( + "/novel/:novelUrl/:year/:month/:chapterUrl", + NovelaWuxiaScraper.chapterScraper +); + +router.get("/search/", NovelaWuxiaScraper.searchScraper); + +module.exports = router; diff --git a/src/es/novelawuxia/NovelaWuxiaScraper.js b/src/es/novelawuxia/NovelaWuxiaScraper.js new file mode 100644 index 0000000..d1cfc9a --- /dev/null +++ b/src/es/novelawuxia/NovelaWuxiaScraper.js @@ -0,0 +1,211 @@ +const cheerio = require("cheerio"); +const fetch = require("node-fetch"); +const { htmlToText } = require("html-to-text"); +const { parseHtml } = require("../../helper"); + +const baseUrl = "http://www.novelawuxia.com/"; + +function getNovelName(y) { + return y.replace(/-/g, " ").replace(/(?:^|\s)\S/g, (a) => a.toUpperCase()); +} + +const novelsScraper = async (req, res) => { + let url = baseUrl + "p/todas-las-novelas.html"; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".post-body.entry-content") + .find("a") + .each(function (result) { + let novelName = $(this) + .attr("href") + .split("/") + .pop() + .replace(".html", ""); + novelName = getNovelName(novelName); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).attr("href"); + novelUrl = novelUrl.replace(`${baseUrl}p/`, "") + "/"; + + const novel = { + extensionId: 31, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels); +}; + +const novelScraper = async (req, res) => { + const novelUrl = req.params.novelUrl; + const url = `${baseUrl}p/${novelUrl}`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novel = {}; + + novel.extensionId = 31; + + novel.sourceName = "Novela Wuxia"; + + novel.sourceUrl = url; + + novel.novelUrl = `${novelUrl}/`; + + novel.novelName = $("h1.post-title").text().trim(); + + novel.novelCover = $(`img[title="${novel.novelName}"]`).attr("src"); + + $(".col-6.col-sm-6 > b").each(function (result) { + const detailName = $(this).text(); + const detail = $(this)[0].nextSibling.nodeValue.trim(); + + if (detailName.includes("Autor")) { + novel["Author(s)"] = detail.replace("Autor:", ""); + } + if (detailName.includes("Ilustrador")) { + novel["Artist(s)"] = detail.replace("Ilustrador: ", ""); + } + if (detailName.includes("Estatus")) { + novel.Status = detail.replace("Estatus: ", ""); + } + if (detailName.includes("Géneros:")) { + novel["Genres(s)"] = detail + .replace("Géneros: ", "") + .replace(/,\s/g, ","); + } + }); + + $('div[style="text-align: center;"]').each(function (result) { + const detailName = $(this).text(); + + if (detailName.includes("Sinopsis")) { + novel.novelSummary = $(this) + .next() + .text() + .replace("Sinopsis", "") + .trim(); + } + }); + + let novelChapters = []; + + $( + 'div[style="-webkit-text-stroke-width: 0px; color: black; font-family: "times new roman"; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"]' + ) + .find("a") + .each(function (res) { + const chapterName = $(this).text(); + const chapterUrl = $(this).attr("href").replace(baseUrl, ""); + const releaseDate = null; + + const chapter = { chapterName, releaseDate, chapterUrl }; + + novelChapters.push(chapter); + }); + + novel.novelChapters = novelChapters; + + res.json(novel); +}; + +const chapterScraper = async (req, res) => { + let novelUrl = req.params.novelUrl; + let year = req.params.year; + let month = req.params.month; + let chapterUrl = req.params.chapterUrl; + + const url = `${baseUrl}${year}/${month}/${chapterUrl}`; + + console.log(url); + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let chapterName = $("h1.post-title").text().trim(); + + let chapterText = $(".post-body.entry-content").html(); + chapterText = parseHtml(chapterText); + + let nextChapter = null; + let prevChapter = null; + + novelUrl = novelUrl + "/"; + chapterUrl = chapterUrl + "/"; + + const chapter = { + extensionId: 31, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + const url = `${baseUrl}search?q=${searchTerm}`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".date-outer").each(function (result) { + let novelName = $(this) + .find("a") + .attr("href") + .split("/") + .pop() + .replace(/-capitulo(.*?).html/, ""); + + const novelUrl = novelName + ".html/"; + + novelName = getNovelName(novelName); + + const exists = novels.some((novel) => novel.novelName === novelName); + + if (!exists) { + const novelCover = null; + const novel = { + extensionId: 31, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + } + }); + + res.json(novels); +}; + +module.exports = vipNovelScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/es/novelawuxia/icon.png b/src/es/novelawuxia/icon.png new file mode 100644 index 0000000..623c577 Binary files /dev/null and b/src/es/novelawuxia/icon.png differ