diff --git a/index.js b/index.js index dae5fc9..44f144f 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,7 @@ app.use("/api/8/", require("./src/en/novelfull/NovelFull")); app.use("/api/9/", require("./src/en/noveltrench/NovelTrench")); app.use("/api/10/", require("./src/en/vipnovel/VipNovel")); app.use("/api/11/", require("./src/en/kisslightnovels/KissLightNovels")); +app.use("/api/12/", require("./src/en/wuxiaworldsite/WuxiaWorldSite")); const PORT = process.env.PORT || 5000; diff --git a/sources.js b/sources.js index 17f0abe..899bce6 100644 --- a/sources.js +++ b/sources.js @@ -98,6 +98,15 @@ extensions = [ sourceLanguage: "English", status: 1, }, + { + sourceId: 12, + sourceUrl: "https://wuxiaworldsite.co/", + sourceName: "WuxiaWorldSite", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/wuxiaworldsite/icon.png?raw=true", + sourceLanguage: "English", + status: 1, + }, ]; module.exports = extensions; diff --git a/src/en/wuxiaworldsite/WuxiaWorldSite.js b/src/en/wuxiaworldsite/WuxiaWorldSite.js new file mode 100644 index 0000000..0cf16e8 --- /dev/null +++ b/src/en/wuxiaworldsite/WuxiaWorldSite.js @@ -0,0 +1,14 @@ +const express = require("express"); +const WuxiaWorldScraper = require("./WuxiaWorldSiteScraper"); + +const router = express.Router(); + +router.get("/novels/", WuxiaWorldSiteScraper.novelsScraper); + +router.get("/novel/:novelUrl", WuxiaWorldSiteScraper.novelScraper); + +router.get("/novel/:novelUrl/:chapterUrl", WuxiaWorldSiteScraper.chapterScraper); + +router.get("/search/", WuxiaWorldSiteScraper.searchScraper); + +module.exports = router; diff --git a/src/en/wuxiaworldsite/WuxiaWorldSiteScraper.js b/src/en/wuxiaworldsite/WuxiaWorldSiteScraper.js new file mode 100644 index 0000000..ede8cf9 --- /dev/null +++ b/src/en/wuxiaworldsite/WuxiaWorldSiteScraper.js @@ -0,0 +1,202 @@ +const cheerio = require("cheerio"); +const fetch = require("node-fetch"); + +const baseUrl = "https://wuxiaworldsite.co/"; +const searchUrl = "https://wuxiaworldsite.co/search/"; + +const novelsScraper = async (req, res) => { + const url = `${baseUrl}/power-ranking`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".a_item").each( (i, el) => { + const novelName = $(el).find("a").attr("title"); + const novelCover = baseUrl + $(el).find("a > img").attr("src"); + const novelUrl = $(el).find(".name_views > a").attr("href"); + + const novel = { + extensionId: 12, + 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); + + $(".category_list").remove(); + + let novel = {}; + + novel.extensionId = 12; + + novel.sourceName = "WuxiaWorldSite"; + + novel.sourceUrl = url; + + novel.novelUrl = novelUrl + "/"; + + novel.novelName = $(".content-reading > h1").text(); + + novel.novelCover = baseUrl + $(".img-read> img").attr("src"); + + novel.novelSummary = $(".story-introduction-content").text(); + + novel["Author(s)"] = $(".content-reading > p").text(); + + novel["Artist(s)"] = null; + + novel["Genre(s)"] = ""; + + $(".a_tag_item").each((i, el) => { + novel["Genre(s)"] += $(el).text() + ","; + }); + + novel["Genre(s)"] = novel["Genre(s)"].split(","); + novel["Genre(s)"].pop(); + + novel.Status = novel["Genre(s)"].pop(); + + novel["Genre(s)"] = novel["Genre(s)"].join(","); + + const novelID = $(".show-more-list").attr("data-id"); + + const getChapters = async (novelID) => { + const chapterListUrl = baseUrl + "/get-full-list.ajax?id=" + novelID; + + const data = await fetch(chapterListUrl); + const chapters = await data.text(); + + $ = cheerio.load(chapters); + + let novelChapters = []; + + $(".new-update-content").each((i, el) => { + let chapterName = $(el).text().split(/\t+/); + const releaseDate = chapterName.pop(); + chapterName = chapterName[0]; + let chapterUrl = $(el).attr("href"); + chapterUrl = chapterUrl.split("/").pop(); + + const novel = { + chapterName, + releaseDate, + chapterUrl, + }; + novelChapters.push(novel); + }); + return novelChapters; + }; + + novel.novelChapters = await getChapters(novelID); + + res.json(novel); +}; + +const chapterScraper = async (req, res) => { + let novelUrl = req.params.novelUrl; + let chapterUrl = req.params.chapterUrl; + + const url = `${baseUrl}/${novelUrl}/${chapterUrl}`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let chapterText = $("#content").html() || ""; + let chapterName = ""; + if (chapterText) { + chapterText = chapterText.split("
"); + chapterName = chapterText.shift(); + } else { + $("p").each((i, el) => { + if ($(el).css("display") !== "none") { + chapterText += $(el).text() + "\n"; + } + }); + chapterText = chapterText.split("\n"); + chapterName = chapterText.shift(); + } + + chapterText = chapterText.join("\n"); + + const prevChapter = $(".pre").attr("href") + ? $(".pre").attr("href").split("/").pop() + : null; + + const nextChapter = $(".next_sesction > a").attr("href") + ? $(".next_sesction > a").attr("href").split("/").pop() + : null; + + + novelUrl += "/"; + chapterUrl += "/"; + + const chapter = { + extensionId: 12, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + const url = `${searchUrl}${searchTerm}`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".a_item").each( (i, el) => { + const novelName = $(el).find(".name_views > a").attr("title"); + const novelCover = baseUrl + $(el).find("a > img").attr("src"); + const novelUrl = $(el).find(".name_views > a").attr("href"); + + const novel = { + extensionId: 12, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels) +}; + + +module.exports = WuxiaWorldSiteScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/en/wuxiaworldsite/icon.png b/src/en/wuxiaworldsite/icon.png new file mode 100644 index 0000000..f94b242 Binary files /dev/null and b/src/en/wuxiaworldsite/icon.png differ