diff --git a/README.md b/README.md index 9b1fd43..41c813c 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader) | https://m.readlightnovel.cc/ | :heavy_check_mark: | | http://wuxiaworld.cloud/ | :heavy_check_mark: | | https://foxaholic.com/ | :heavy_check_mark: | +| https://comrademao.com/ | :heavy_check_mark: | | https://tunovelaligera.com/ | :heavy_check_mark: | | https://www.skynovels.net/ | :heavy_check_mark: | | https://einherjarproject.net/ | :heavy_check_mark: | diff --git a/index.js b/index.js index 2b65e78..719f1ee 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,7 @@ app.use("/api/19/", require("./src/en/readlightnovelcc/ReadLightNovelCc")); app.use("/api/20/", require("./src/en/wuxiaworldcloud/WuxiaWorldCloud")); app.use("/api/21/", require("./src/en/woopread/WoopRead")); app.use("/api/22/", require("./src/en/foxaholic/Foxaholic")); +app.use("/api/27/", require("./src/en/comrademao/ComradeMao")); // Spanish app.use("/api/23/", require("./src/es/tunovelaligera/Tunovelaligera")); diff --git a/sources.js b/sources.js index 01e14da..85c7ca3 100644 --- a/sources.js +++ b/sources.js @@ -1,4 +1,8 @@ extensions = [ + /** + * English + */ + { sourceId: 1, sourceUrl: "https://boxnovel.com/", @@ -197,6 +201,20 @@ extensions = [ sourceLanguage: "English", status: 1, }, + { + sourceId: 27, + sourceUrl: "https://comrademao.com/", + sourceName: "ComradeMao", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/comrademao/icon.png?raw=true", + sourceLanguage: "English", + status: 1, + }, + + /** + * Spanish + */ + { sourceId: 23, sourceUrl: "https://tunovelaligera.com/", diff --git a/src/en/comrademao/ComradeMao.js b/src/en/comrademao/ComradeMao.js new file mode 100644 index 0000000..253a256 --- /dev/null +++ b/src/en/comrademao/ComradeMao.js @@ -0,0 +1,14 @@ +const express = require("express"); +const ComradeMaoScraper = require("./ComradeMaoScraper"); + +const router = express.Router(); + +router.get("/novels/", ComradeMaoScraper.novelsScraper); + +router.get("/novel/:novelUrl", ComradeMaoScraper.novelScraper); + +router.get("/novel/:novelUrl/:chapterUrl", ComradeMaoScraper.chapterScraper); + +router.get("/search/", ComradeMaoScraper.searchScraper); + +module.exports = router; diff --git a/src/en/comrademao/ComradeMaoScraper.js b/src/en/comrademao/ComradeMaoScraper.js new file mode 100644 index 0000000..6def0aa --- /dev/null +++ b/src/en/comrademao/ComradeMaoScraper.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://comrademao.com/"; + +const novelsScraper = async (req, res) => { + let url = baseUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $("article.blog-article").each(function (result) { + const novelName = $(this).find("h5 > a").text(); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).find("h5 > a").attr("href"); + novelUrl = novelUrl.replace(baseUrl + "novel/", ""); + + const novel = { + extensionId: 27, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels); +}; + +const novelScraper = async (req, res) => { + const novelUrl = req.params.novelUrl; + const url = baseUrl + "novel/" + novelUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novel = {}; + + novel.extensionId = 27; + + novel.sourceName = "Comrade Mao"; + + novel.sourceUrl = url; + + novel.novelUrl = novelUrl + "/"; + + function getNovelName(y) { + return y + .replace("-", " ") + .replace(/(?:^|\s)\S/g, (a) => a.toUpperCase()); + } + + novelName = getNovelName(novelUrl); + novel.novelName = novelName; + + novel.novelCover = $("#thumbnail > img").attr("src"); + + let novelSummary = $("div#Description").html(); + novel.novelSummary = htmlToText(novelSummary); + + novel["Genre(s)"] = $("div#Genre") + .text() + .replace(/Genre:|\s/g, ""); + + novel.Status = $("div#Status") + .text() + .replace(/Status:|\s/g, ""); + + novel["Author(s)"] = $("div#Publisher") + .text() + .replace(/Publisher:|\s/g, ""); + + // novel['Genre(s)'] = $("div#Genre"). + + let novelChapters = []; + + const latestChapter = $("tbody > tr") + .first() + .next() + .find("td > a") + .text() + .replace(/^\D+/g, ""); + + for (let i = 1; i <= latestChapter; i++) { + const chapterName = "Chapter " + i; + const releaseDate = null; + const chapterUrl = novelUrl + "-chapter-" + i + "/"; + + 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}mtl/${novelUrl}/${chapterUrl}`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let chapterName = $(".entry-title").text(); + + let chapterText = $(".entry-content").html(); + chapterText = parseHtml(chapterText); + + let nextChapter = null; + + if ($(".nav-next").find("a").length) { + nextChapter = $(".nav-next") + .find("a") + .attr("href") + .replace(baseUrl + "mtl/" + novelUrl + "/", ""); + } + + let prevChapter = null; + + if ($(".nav-previous").find("a").length) { + prevChapter = $(".nav-previous") + .find("a") + .attr("href") + .replace(baseUrl + "mtl/" + novelUrl + "/", ""); + } + + novelUrl = novelUrl + "/"; + chapterUrl = chapterUrl + "/"; + + const chapter = { + extensionId: 27, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + const url = baseUrl + "?s=" + searchTerm + "&post_type=novel"; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $("article.blog-article").each(function (result) { + const novelName = $(this).find("h5 > a").text(); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).find("h5 > a").attr("href"); + novelUrl = novelUrl.replace(baseUrl + "novel/", ""); + + const novel = { + extensionId: 27, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels); +}; + +module.exports = vipNovelScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/en/comrademao/icon.png b/src/en/comrademao/icon.png new file mode 100644 index 0000000..f02d1b9 Binary files /dev/null and b/src/en/comrademao/icon.png differ