diff --git a/README.md b/README.md index 994c9fb..9059883 100644 --- a/README.md +++ b/README.md @@ -4,31 +4,32 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader) ## Sources -| Source | Status | -| ---------------------------- | :----------------: | -| BoxNovel | :heavy_check_mark: | -| ReadLightNovel | :heavy_check_mark: | -| FastNovel | :x: | -| ReadNovelFull | :heavy_check_mark: | -| MTLNovel | :heavy_check_mark: | -| NovelHall | :heavy_check_mark: | -| WuxiaWorld | :heavy_check_mark: | -| NovelFull | :heavy_check_mark: | -| NovelTrench | :heavy_check_mark: | -| VipNovel | :heavy_check_mark: | -| KissLightNovels | :heavy_check_mark: | -| https://wuxiaworldsite.co/ | :heavy_check_mark: | -| FreeWebNovel | :heavy_check_mark: | -| JPMTL | :heavy_check_mark: | -| LightNovelPub | :heavy_check_mark: | -| https://www.wuxiaworld.co/ | :heavy_check_mark: | -| TapRead | :heavy_check_mark: | -| https://www.novelupdates.cc/ | :heavy_check_mark: | -| https://m.readlightnovel.cc/ | :heavy_check_mark: | -| http://wuxiaworld.cloud/ | :heavy_check_mark: | -| https://foxaholic.com/ | :heavy_check_mark: | -| https://tunovelaligera.com/ | :heavy_check_mark: | -| https://www.skynovels.net/ | :heavy_check_mark: | +| Source | Status | +| ----------------------------- | :----------------: | +| BoxNovel | :heavy_check_mark: | +| ReadLightNovel | :heavy_check_mark: | +| FastNovel | :x: | +| ReadNovelFull | :heavy_check_mark: | +| MTLNovel | :heavy_check_mark: | +| NovelHall | :heavy_check_mark: | +| WuxiaWorld | :heavy_check_mark: | +| NovelFull | :heavy_check_mark: | +| NovelTrench | :heavy_check_mark: | +| VipNovel | :heavy_check_mark: | +| KissLightNovels | :heavy_check_mark: | +| https://wuxiaworldsite.co/ | :heavy_check_mark: | +| FreeWebNovel | :heavy_check_mark: | +| JPMTL | :heavy_check_mark: | +| LightNovelPub | :heavy_check_mark: | +| https://www.wuxiaworld.co/ | :heavy_check_mark: | +| TapRead | :heavy_check_mark: | +| https://www.novelupdates.cc/ | :heavy_check_mark: | +| https://m.readlightnovel.cc/ | :heavy_check_mark: | +| http://wuxiaworld.cloud/ | :heavy_check_mark: | +| https://foxaholic.com/ | :heavy_check_mark: | +| https://tunovelaligera.com/ | :heavy_check_mark: | +| https://www.skynovels.net/ | :heavy_check_mark: | +| https://einherjarproject.net/ | :heavy_check_mark: | ## Setup locally diff --git a/index.js b/index.js index cd833c3..6d428ae 100644 --- a/index.js +++ b/index.js @@ -45,6 +45,7 @@ app.use("/api/22/", require("./src/en/foxaholic/Foxaholic")); // Spanish app.use("/api/23/", require("./src/es/tunovelaligera/Tunovelaligera")); app.use("/api/24/", require("./src/es/skynovels/Skynovels")); +app.use("/api/25/", require("./src/es/einherjarproject/EinherjarProject")); const PORT = process.env.PORT || 5000; diff --git a/sources.js b/sources.js index 395d62a..4cfad2e 100644 --- a/sources.js +++ b/sources.js @@ -215,6 +215,15 @@ extensions = [ sourceLanguage: "Spanish", status: 1, }, + { + sourceId: 25, + sourceUrl: "https://einherjarproject.net/", + sourceName: "EinherjarProject", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/es/einherjarproject/icon.png?raw=true", + sourceLanguage: "Spanish", + status: 1, + }, ]; module.exports = extensions; diff --git a/src/es/einherjarproject/EinherjarProject.js b/src/es/einherjarproject/EinherjarProject.js new file mode 100644 index 0000000..f273888 --- /dev/null +++ b/src/es/einherjarproject/EinherjarProject.js @@ -0,0 +1,17 @@ +const express = require("express"); +const einherjarProjectScraper = require("./EinherjarProjectScraper"); + +const router = express.Router(); + +router.get("/novels/", einherjarProjectScraper.novelsScraper); + +router.get("/novel/:novelUrl", einherjarProjectScraper.novelScraper); + +router.get( + "/novel/:novelUrl/:chapterUrl", + einherjarProjectScraper.chapterScraper +); + +router.get("/search/", einherjarProjectScraper.searchScraper); + +module.exports = router; diff --git a/src/es/einherjarproject/EinherjarProjectScraper.js b/src/es/einherjarproject/EinherjarProjectScraper.js new file mode 100644 index 0000000..ed8e800 --- /dev/null +++ b/src/es/einherjarproject/EinherjarProjectScraper.js @@ -0,0 +1,200 @@ +const cheerio = require("cheerio"); +const fetch = require("node-fetch"); +const { htmlToText } = require("html-to-text"); +const { parseHtml } = require("../../helper"); + +const baseUrl = "https://einherjarproject.net/"; + +const novelsScraper = async (req, res) => { + let url = baseUrl + "proyectos-activos/"; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".wp-block-media-text").each(function (result) { + const novelName = $(this).find("a").text(); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this) + .find(".wp-block-media-text__content") + .find("a") + .attr("href"); + novelUrl = novelUrl.replace(baseUrl, ""); + + const novel = { + extensionId: 25, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels); +}; + +const novelScraper = async (req, res) => { + const novelUrl = req.params.novelUrl; + const url = baseUrl + novelUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novel = {}; + + novel.extensionId = 25; + + novel.sourceName = "Einherjar Project"; + + novel.sourceUrl = url; + + novel.novelUrl = novelUrl + "/"; + + novel.novelName = $("h1").text(); + + novel.novelCover = $("img").attr("src"); + + $(".wp-block-columns") + .find("li") + .each(function (result) { + if ($(this).text().includes("Autor:")) { + novel["Author(s)"] = $(this) + .text() + .replace("Autor:", "") + .slice(0, -1); + } + if ($(this).text().includes("Ilustrador: ")) { + novel["Artist(s)"] = $(this) + .text() + .replace("Ilustrador: ", "") + .slice(0, -1); + } + if ($(this).text().includes("Estado: ")) { + novel.Status = $(this) + .text() + .replace("Estado: ", "") + .slice(0, -1); + } + }); + + let novelSummary = $(".post-content > .has-text-align-center").html(); + + novel.novelSummary = htmlToText(novelSummary); + + let novelChapters = []; + + $(".wp-block-media-text") + .find("p") + .each(function (result) { + if ($(this).find("a").text()) { + const chapterName = $(this).text(); + const releaseDate = null; + const chapterUrl = $(this) + .find("a") + .attr("href") + .replace(baseUrl, ""); + + 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 chapterUrl = req.params.chapterUrl; + + const url = baseUrl + chapterUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let chapterName = $("h1.post-title").text(); + + let chapterText = $(".post-content").html(); + chapterText = htmlToText(chapterText, { preserveNewlines: true }); + + let nextChapter = null; + let prevChapter = null; + + novelUrl = novelUrl + "/"; + chapterUrl = chapterUrl + "/"; + + const chapter = { + extensionId: 25, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + const url = baseUrl + "?s=" + searchTerm; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".post-container") + .find("div.type-page") + .each(function (result) { + const novelName = $(this) + .find(".post-header") + .text() + .replace(/\n/g, ""); + if ( + !novelName.includes("EPUBs") && + !novelName.includes("Proyectos Activos") && + !novelName.includes("Chapter") + ) { + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this) + .find("a") + .attr("href") + .replace(baseUrl, ""); + + const novel = { + extensionId: 25, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + } + }); + + res.json(novels); +}; + +module.exports = einharjarProjectScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/es/einherjarproject/icon.png b/src/es/einherjarproject/icon.png new file mode 100644 index 0000000..b9ef6dc Binary files /dev/null and b/src/es/einherjarproject/icon.png differ