diff --git a/README.md b/README.md index 5f31616..ffad144 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader) | https://www.wuxiaworld.co/ | :heavy_check_mark: | | TapRead | :heavy_check_mark: | | https://www.novelupdates.cc/ | :heavy_check_mark: | -| LightNovelPub | :heavy_check_mark: | +| https://m.readlightnovel.cc/ | :heavy_check_mark: | ## Setup locally diff --git a/index.js b/index.js index b1d2386..ef69d66 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ app.use("/api/15/", require("./src/en/lightnovelpub/LightNovelPub")); app.use("/api/16/", require("./src/en/wuxiaworldco/WuxiaWorldCo")); app.use("/api/17/", require("./src/en/tapread/TapRead")); app.use("/api/18/", require("./src/en/novelupdatescc/NovelUpdatesCc")); +app.use("/api/19/", require("./src/en/readlightnovelcc/ReadLightNovelCc")); const PORT = process.env.PORT || 5000; diff --git a/sources.js b/sources.js index 6df61cd..905ca02 100644 --- a/sources.js +++ b/sources.js @@ -161,6 +161,15 @@ extensions = [ sourceLanguage: "English", status: 1, }, + { + sourceId: 18, + sourceUrl: "https://m.readlightnovel.cc/", + sourceName: "ReadLightNovel.cc", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/readlightnovelcc/icon.png?raw=true", + sourceLanguage: "English", + status: 1, + }, ]; module.exports = extensions; diff --git a/src/en/novelupdatescc/NovelUpdatesCcScraper.js b/src/en/novelupdatescc/NovelUpdatesCcScraper.js index 005be0f..1265ea0 100644 --- a/src/en/novelupdatescc/NovelUpdatesCcScraper.js +++ b/src/en/novelupdatescc/NovelUpdatesCcScraper.js @@ -45,7 +45,7 @@ const novelScraper = async (req, res) => { novel.extensionId = 18; - novel.sourceName = "NovelUpdatesCc"; + novel.sourceName = "NovelUpdates.cc"; novel.sourceUrl = url; diff --git a/src/en/readlightnovelcc/ReadLightNovelCc.js b/src/en/readlightnovelcc/ReadLightNovelCc.js new file mode 100644 index 0000000..740ef18 --- /dev/null +++ b/src/en/readlightnovelcc/ReadLightNovelCc.js @@ -0,0 +1,14 @@ +const express = require("express"); +const ReadLightNovelCc = require("./ReadLightNovelCcScraper"); + +const router = express.Router(); + +router.get("/novels/", ReadLightNovelCc.novelsScraper); + +router.get("/novel/:novelUrl", ReadLightNovelCc.novelScraper); + +router.get("/novel/:novelUrl/:chapterUrl", ReadLightNovelCc.chapterScraper); + +router.get("/search/", ReadLightNovelCc.searchScraper); + +module.exports = router; diff --git a/src/en/readlightnovelcc/ReadLightNovelCcScraper.js b/src/en/readlightnovelcc/ReadLightNovelCcScraper.js new file mode 100644 index 0000000..c2d3aa5 --- /dev/null +++ b/src/en/readlightnovelcc/ReadLightNovelCcScraper.js @@ -0,0 +1,167 @@ +const cheerio = require("cheerio"); +const fetch = require("node-fetch"); +const { htmlToText } = require("html-to-text"); +const { parseHtml } = require("../../helper"); + +const baseUrl = "https://m.readlightnovel.cc/"; + +const novelsScraper = async (req, res) => { + const result = await fetch(baseUrl); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".section-item").each(function (result) { + const novelName = $(this).find(".book-name").text(); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).find("a").attr("href").slice(1); + + const novel = { + extensionId: 19, + 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 = 19; + + novel.sourceName = "ReadLightNovel.cc"; + + novel.sourceUrl = url; + + novel.novelUrl = `${novelUrl}/`; + + novel.novelName = $(".book-name").text(); + + novel.novelCover = $("div.book-img > img").attr("src"); + + novel["Genre(s)"] = $("div.book-catalog > span.txt").text(); + + novel.Status = $("div.book-state > span.txt").text(); + + novel["Author(s)"] = $("div.author > span.name").text(); + + novelSummary = $("div.content > p.desc").html(); + novel.novelSummary = htmlToText(novelSummary); + + let novelChapters = []; + + $(".chapter-item").each(function (result) { + const chapterName = $(this).find(".chapter-name").text(); + const releaseDate = null; + const chapterUrl = $(this).attr("href").slice(1); + + novelChapters.push({ + chapterName, + releaseDate, + chapterUrl, + }); + }); + + 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); + + const chapterName = $("h1.chapter-title").text(); + let chapterText = $("div.chapter-entity").html(); + chapterText = parseHtml(chapterText); + + let nextChapter = null; + + if ($("a.next").length) { + nextChapter = $("a.next").attr("href").slice(1); + } + + let prevChapter = null; + + if ($("a.prev").length) { + prevChapter = $("a.prev").attr("href").slice(1); + } + + novelUrl = novelUrl + "/"; + chapterUrl = chapterUrl + "/"; + + const chapter = { + extensionId: 19, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + const url = `${baseUrl}search/${searchTerm}/1`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".list-item").each(function (result) { + $(this).find("font").remove(); + + const novelName = $(this).find(".book-name").text(); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).find("a").attr("href").slice(1); + + const novel = { + extensionId: 19, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels); +}; + +module.exports = wuxiaWorldCoScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/en/readlightnovelcc/icon.png b/src/en/readlightnovelcc/icon.png new file mode 100644 index 0000000..b732fa7 Binary files /dev/null and b/src/en/readlightnovelcc/icon.png differ