diff --git a/server.js b/server.js index 5699abd..319385f 100644 --- a/server.js +++ b/server.js @@ -22,6 +22,7 @@ app.use("/api/1/", require("./src/en/boxnovel/boxnovel")); app.use("/api/2/", require("./src/en/readlightnovel/readlightnovel")); app.use("/api/3/", require("./src/en/fastnovel/fastnovel")); app.use("/api/4/", require("./src/en/readnovelfull/readnovelfull")); +app.use("/api/5/", require("./src/en/mtlnovel/mtlnovel")); const PORT = process.env.PORT || 5000; diff --git a/src/en/mtlnovel/icon.png b/src/en/mtlnovel/icon.png new file mode 100644 index 0000000..8fb2406 Binary files /dev/null and b/src/en/mtlnovel/icon.png differ diff --git a/src/en/mtlnovel/mtlnovel.js b/src/en/mtlnovel/mtlnovel.js new file mode 100644 index 0000000..eb3ec78 --- /dev/null +++ b/src/en/mtlnovel/mtlnovel.js @@ -0,0 +1,202 @@ +const express = require("express"); +const cheerio = require("cheerio"); +const request = require("request"); + +const router = express.Router(); + +const baseUrl = "https://mtlnovel.com"; + +// Top novels + +router.get("/novels/", (req, res) => { + const url = `${baseUrl}/alltime-rank/`; + + request(url, (err, response, body) => { + if (err) throw err; + + let novels = []; + + $ = cheerio.load(body); + + $("div.box.wide").each(function (result) { + let novelUrl = $(this).find("a.list-title").attr("href"); + novelUrl = novelUrl.replace("https://www.mtlnovel.com/", ""); + + let novelName = $(this).find("a.list-title").text().slice(4); + let novelCover = $(this).find("amp-img").attr("src"); + + novel = { + extensionId: 5, + novelUrl, + novelName, + novelCover, + }; + + novels.push(novel); + }); + + res.json(novels); + }); +}); + +router.get("/novel/:novelUrl", (req, res) => { + let novelUrl = req.params.novelUrl; + const url = `${baseUrl}/${novelUrl}`; + console.log(url); + + request(url, (err, response, body) => { + $ = cheerio.load(body); + + let novel = {}; + + novel.extensionId = 5; + + novel.sourceName = "MTLNovel"; + + novel.sourceUrl = url; + + novel.novelUrl = `${novelUrl}/`; + + novel.novelName = $("h1.entry-title").text(); + + novel.novelCover = $("amp-img").attr("src"); + + novel.novelSummary = $("div.desc > h2").next().text(); + + novel["Author(s)"] = $("tr > td") + .filter(function () { + return $(this).prev().text().trim() === "Author"; + }) + .next() + .text() + .replace("Auhtor:", ""); + + novel.Status = $("tr > td") + .filter(function () { + return $(this).prev().text().trim() === "Status"; + }) + .next() + .text() + .replace("Status:", ""); + + novel["Genre(s)"] = $("td") + .filter(function () { + return $(this).prev().text().trim() === "Genre"; + }) + .next() + .text() + .replace("Genre:", ""); + + novel["Artist(s)"] = null; + + function callback(res) { + console.log(res); + novel.novelChapters = res; + } + + request(`${url}/chapter-list/`, (err, response, body) => { + $ = cheerio.load(body); + console.log(`${url}/chapter-list/`); + // console.log($("div.ch-list").find("a.ch-link").next().html()); + let novelChapters = []; + + $("div.ch-list") + .find("a.ch-link") + .each(function (result) { + let chapterName = $(this).text().replace("~ ", ""); + + let releaseDate = null; + + let chapterUrl = $(this).attr("href"); + chapterUrl = chapterUrl.replace( + `https://www.mtlnovel.com/${novelUrl}/`, + "" + ); + + novelChapters.push({ + chapterUrl, + chapterName, + releaseDate, + }); + }); + + callback(novelChapters); + + return res.json(novel); + }); + }); +}); + +router.get("/novel/:novelUrl/:chapterUrl", (req, res) => { + let novelUrl = req.params.novelUrl; + const url = `https://www.mtlnovel.com/${novelUrl}/${req.params.chapterUrl}/`; + console.log(url); + request(url, (err, response, body) => { + if (err) throw err; + + $ = cheerio.load(body); + + let chapterName = $("h1.main-title").text(); + + let chapterText = $("div.par").text(); + + let nextChapter = null; + if ($("a.next").attr("href")) { + nextChapter = $("a.next").attr("href").replace(`/${novelUrl}/`, ""); + } + + let prevChapter = null; + if ($("a.prev").attr("href")) { + prevChapter = $("a.prev").attr("href").replace(`/${novelUrl}/`, ""); + } + + chapter = { + extensionId: 5, + novelUrl: `${req.params.novelUrl}`, + chapterUrl: `${req.params.chapterUrl}`, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); + }); +}); + +router.get("/search/", (req, res) => { + searchTerm = req.query.s; + + const searchUrl = "https://www.mtlnovel.com"; + + request.post( + { url: searchUrl, form: { s: searchTerm } }, + (err, response, body) => { + if (err) throw err; + + $ = cheerio.load(body); + console.log(body); + let novels = []; + + $("div.box").each(function (result) { + let novelName = $(this).find("a.list-title").text(); + let novelCover = $(this).find("amp-img").attr("src"); + let novelUrl = $(this).find("a").attr("href"); + novelUrl = novelUrl.replace("https://www.mtlnovel.com/", ""); + + novel = { + extensionId: 5, + novelUrl, + novelName, + novelCover, + }; + + novels.push(novel); + }); + + res.json(novels); + } + ); +}); + +module.exports = router; diff --git a/src/en/readnovelfull/readnovelfull.js b/src/en/readnovelfull/readnovelfull.js index bec4fdb..c287af4 100644 --- a/src/en/readnovelfull/readnovelfull.js +++ b/src/en/readnovelfull/readnovelfull.js @@ -155,7 +155,6 @@ router.get("/novel/:novelUrl/:chapterUrl", (req, res) => { router.get("/search/", (req, res) => { let searchTerm = req.query.s; - console.log(searchTerm); searchUrl = `https://readnovelfull.com/search?keyword=`; url = `${searchUrl}${searchTerm}`; diff --git a/src/extensions.js b/src/extensions.js index 88ab766..16b1907 100644 --- a/src/extensions.js +++ b/src/extensions.js @@ -34,6 +34,15 @@ extensions = [ sourceLanguage: "English", status: 1, }, + { + sourceId: 5, + sourceUrl: "https://www.mtlnovel.com/", + sourceName: "MTLNovel", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/mtlnovel/icon.png?raw=true", + sourceLanguage: "English", + status: 1, + }, ]; module.exports = extensions;