diff --git a/index.js b/index.js index 80bea96..14ae3ec 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ app.use("/api/35/", require("./src/en/scribblehub/ScribbleHub")); app.use("/api/37/", require("./src/en/lnmtl/LNMTL")); app.use("/api/48/", require("./src/en/wuxiablog/WuxiaBlog")); app.use("/api/49/", require("./src/en/wuxiacity/WuxiaCity")); -app.use("/api/76/", require("./src/en/wnmtl/WNMTL")); +app.use("/api/77/", require("./src/en/wnmtl/WNMTL")); // Spanish app.use("/api/23/", require("./src/es/tunovelaligera/Tunovelaligera")); @@ -66,6 +66,9 @@ app.use("/api/36", require("./src/jp/syosetu/Syosetu")); // Chinese app.use("/api/50/", require("./src/ch/yushubo/Yushubo")); +// French +app.use("/api/76/", require("./src/fr/noveldeglace/NovelDeGlace")); + // MultiSrc app.use("/api/", require("./multisrc/madara/MadaraGenerator")); app.use("/api/", require("./multisrc/wpmangastream/WPMangaStreamGenerator")); diff --git a/src/en/wnmtl/WNMTLScraper.js b/src/en/wnmtl/WNMTLScraper.js index 512f294..741c875 100644 --- a/src/en/wnmtl/WNMTLScraper.js +++ b/src/en/wnmtl/WNMTLScraper.js @@ -3,44 +3,46 @@ const fetch = require("node-fetch"); const { htmlToText } = require("html-to-text"); const { parseHtml } = require("../../helper"); -const baseUrl = "https://noveldeglace.com/"; +const baseUrl = "https://www.wnmtl.org/"; -const sourceName = "Novel De Glace"; -const sourceId = 76; +const sourceName = "WNMTL"; +const sourceId = 77; const novelsScraper = async (req, res) => { - let url = baseUrl + "roman"; + let url = baseUrl + "explore"; console.log(url); - const result = await fetch(url); + const result = await fetch( + "https://www.wnmtl.org/book/2308-warlock-apprentice" + ); const body = await result.text(); - $ = cheerio.load(body); + // $ = cheerio.load(body); - let novels = []; + // let novels = []; - $("article").each(function () { - const novelName = $(this).find("h2").text().trim(); - const novelCover = $(this).find("img").attr("src"); - const novelUrl = $(this).find("h2 > a").attr("href"); + // $(".card").each(function () { + // const novelName = $(this).find(".book-name").text(); + // const novelCover = $(this).find("img").attr("src"); + // const novelUrl = $(this).find("a").attr("href"); - const novel = { - sourceId, - novelName, - novelCover, - novelUrl, - }; + // const novel = { + // sourceId, + // novelName, + // novelCover, + // novelUrl, + // }; - novels.push(novel); - }); + // novels.push(novel); + // }); - res.json(novels); + res.json({ novels: body }); }; const novelScraper = async (req, res) => { const novelUrl = req.params.novelUrl; - const url = baseUrl + "novel/" + novelUrl; + const url = novelUrl; const result = await fetch(url); const body = await result.text(); @@ -49,14 +51,7 @@ const novelScraper = async (req, res) => { let novel = { sourceId, sourceName, url, novelUrl }; - function getNovelName(y) { - return y - .replace("-", " ") - .replace(/(?:^|\s)\S/g, (a) => a.toUpperCase()); - } - - novelName = getNovelName(novelUrl); - novel.novelName = novelName; + novel.novelName = $("#thumbnail > img").text(); novel.novelCover = $("#thumbnail > img").attr("src"); diff --git a/src/fr/noveldeglace/NovelDeGlace.js b/src/fr/noveldeglace/NovelDeGlace.js new file mode 100644 index 0000000..de5a2f3 --- /dev/null +++ b/src/fr/noveldeglace/NovelDeGlace.js @@ -0,0 +1,14 @@ +const express = require("express"); +const NovelDeGlaceScraper = require("./NovelDeGlaceScraper"); + +const router = express.Router(); + +router.get("/novels/", NovelDeGlaceScraper.novelsScraper); + +router.get("/novel/:novelUrl", NovelDeGlaceScraper.novelScraper); + +router.get("/novel/:novelUrl/:chapterUrl", NovelDeGlaceScraper.chapterScraper); + +router.get("/search/", NovelDeGlaceScraper.searchScraper); + +module.exports = router; diff --git a/src/fr/noveldeglace/NovelDeGlaceScraper.js b/src/fr/noveldeglace/NovelDeGlaceScraper.js new file mode 100644 index 0000000..a025eb1 --- /dev/null +++ b/src/fr/noveldeglace/NovelDeGlaceScraper.js @@ -0,0 +1,163 @@ +const cheerio = require("cheerio"); +const fetch = require("node-fetch"); +const { htmlToText } = require("html-to-text"); +const { parseHtml } = require("../../helper"); + +const baseUrl = "https://noveldeglace.com/"; + +const sourceName = "Novel De Glace"; +const sourceId = 76; + +const novelsScraper = async (req, res) => { + let url = baseUrl + "roman"; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $("article").each(function () { + const novelName = $(this).find("h2").text().trim(); + const novelCover = $(this).find("img").attr("src"); + const novelUrl = $(this).find("h2 > a").attr("href").split("/")[4]; + + const novel = { + sourceId, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + res.json(novels); +}; + +const novelScraper = async (req, res) => { + const novelUrl = req.params.novelUrl; + const url = baseUrl + "roman/" + novelUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novel = { sourceId, sourceName, url, novelUrl }; + + novel.novelName = $( + "div.entry-content > div > strong" + )[0].nextSibling.nodeValue.trim(); + + novel.novelCover = $("#thumbnail > img").attr("src"); + + novel.novelSummary = $("div[data-title=Synopsis]").text(); + novel.author = $( + "div.romans > div.project-large > div.su-row > div.su-column.su-column-size-3-4 > div > div:nth-child(3) > strong" + )[0].nextSibling.nodeValue.trim(); + + novel.genre = $(".genre") + .text() + .replace("Genre : ", "") + .replace(/, /g, ","); + + let novelChapters = []; + + $(".chpt").each(function () { + const chapterName = $(this).find("a").text().trim(); + const releaseDate = null; + const chapterUrl = $(this).find("a").attr("href").split("/")[4]; + + const novel = { + sourceId, + chapterName, + releaseDate, + chapterUrl, + }; + + novelChapters.push(novel); + }); + + novel.novelChapters = novelChapters; + + res.json(novel); +}; + +const chapterScraper = async (req, res) => { + let novelUrl = req.params.novelUrl; + let chapterUrl = req.params.chapterUrl; + + const url = `${baseUrl}chapitre/${chapterUrl}`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let chapterName = $("h2.western").text(); + + let chapterText = $(".chapter-content").html(); + chapterText = parseHtml(chapterText); + + let nextChapter = null; + + let prevChapter = null; + + novelUrl = novelUrl + "/"; + chapterUrl = chapterUrl + "/"; + + const chapter = { + sourceId, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + let url = baseUrl + "roman"; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $("article").each(function () { + const novelName = $(this).find("h2").text().trim(); + const novelCover = $(this).find("img").attr("src"); + const novelUrl = $(this).find("h2 > a").attr("href").split("/")[4]; + + const novel = { + sourceId, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + novels = novels.filter((novel) => + novel.novelName.toLowerCase().includes(searchTerm) + ); + + res.json(novels); +}; + +module.exports = NovelDeGlaceScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/fr/noveldeglace/icon.png b/src/fr/noveldeglace/icon.png new file mode 100644 index 0000000..e69241a Binary files /dev/null and b/src/fr/noveldeglace/icon.png differ