committed by
GitHub
parent
4e48014594
commit
bcce52e5df
@@ -20,6 +20,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader)
|
||||
| WuxiaWorldSite | :heavy_check_mark: |
|
||||
| FreeWebNovel | :heavy_check_mark: |
|
||||
| JPMTL | :heavy_check_mark: |
|
||||
| LightNovelPub | :heavy_check_mark: |
|
||||
|
||||
## Setup locally
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ app.use("/api/11/", require("./src/en/kisslightnovels/KissLightNovels"));
|
||||
app.use("/api/12/", require("./src/en/wuxiaworldsite/WuxiaWorldSite"));
|
||||
app.use("/api/13/", require("./src/en/freewebnovel/FreeWebNovel"));
|
||||
app.use("/api/14/", require("./src/en/jpmtl/JPMTL"));
|
||||
app.use("/api/15/", require("./src/en/lightnovelpub/LightNovelPub"));
|
||||
|
||||
const PORT = process.env.PORT || 5000;
|
||||
|
||||
|
||||
@@ -125,6 +125,15 @@ extensions = [
|
||||
sourceLanguage: "English",
|
||||
status: 1,
|
||||
},
|
||||
{
|
||||
sourceId: 15,
|
||||
sourceUrl: "https://www.lightnovelpub.com/",
|
||||
sourceName: "LightNovelPub",
|
||||
sourceCover:
|
||||
"https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/lightnovelpub/icon.png?raw=true",
|
||||
sourceLanguage: "English",
|
||||
status: 1,
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = extensions;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const express = require("express");
|
||||
const lightNovelPubScraper = require("./LightNovelPubScraper");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/novels/", lightNovelPubScraper.novelsScraper);
|
||||
|
||||
router.get("/novel/:novelUrl", lightNovelPubScraper.novelScraper);
|
||||
|
||||
router.get("/novel/:novelUrl/:chapterUrl", lightNovelPubScraper.chapterScraper);
|
||||
|
||||
router.get("/search/", lightNovelPubScraper.searchScraper);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,203 @@
|
||||
const cheerio = require("cheerio");
|
||||
const fetch = require("node-fetch");
|
||||
const { htmlToText } = require("html-to-text");
|
||||
|
||||
const baseUrl = "https://www.lightnovelpub.com/";
|
||||
|
||||
const novelsScraper = async (req, res) => {
|
||||
let url = baseUrl + "browse/all/popular/all/1";
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
let novels = [];
|
||||
|
||||
$(".novel-item.ads").remove();
|
||||
|
||||
$(".novel-item").each(function (result) {
|
||||
const novelName = $(this)
|
||||
.find(".novel-title")
|
||||
.text()
|
||||
.replace(/[\t\n]/g, "");
|
||||
|
||||
const novelCover = $(this).find("img").attr("data-src");
|
||||
|
||||
let novelUrl = $(this)
|
||||
.find(".novel-title > a")
|
||||
.attr("href")
|
||||
.replace(`/novel/`, "");
|
||||
novelUrl += "/";
|
||||
|
||||
const novel = {
|
||||
extensionId: 15,
|
||||
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 = 15;
|
||||
|
||||
novel.sourceName = "LightNovelPub";
|
||||
|
||||
novel.sourceUrl = url;
|
||||
|
||||
novel.novelUrl = `${novelUrl}/`;
|
||||
|
||||
novel.novelName = $("h1.novel-title")
|
||||
.text()
|
||||
.replace(/[\t\n]/g, "")
|
||||
.trim();
|
||||
|
||||
novel.novelCover = $("img").attr("src");
|
||||
|
||||
novel["Genre(s)"] = "";
|
||||
|
||||
$("div.categories > ul > li").each(function (result) {
|
||||
novel["Genre(s)"] +=
|
||||
$(this)
|
||||
.text()
|
||||
.replace(/[\t\n]/g, "") + ",";
|
||||
});
|
||||
|
||||
$("div.header-stats > span").each(function (result) {
|
||||
if ($(this).find("small").text() === "Status") {
|
||||
novel.Status = $(this).find("strong").text();
|
||||
}
|
||||
});
|
||||
|
||||
novel["Genre(s)"] = novel["Genre(s)"].slice(0, -1);
|
||||
|
||||
novel["Author(s)"] = $(".author > a > span").text();
|
||||
|
||||
novelSummary = $(".summary > .content").html();
|
||||
novel.novelSummary = htmlToText(novelSummary);
|
||||
|
||||
let novelChapters = [];
|
||||
|
||||
let firstChapterNo, totalChapters;
|
||||
|
||||
totalChapters = $(".header-stats > span").first().text().match(/\d+/)[0];
|
||||
firstChapterNo = $(".chapter-no").first().text().match(/\d+/)[0];
|
||||
|
||||
for (let i = firstChapterNo; i <= totalChapters; i++) {
|
||||
const chapterName = "Chapter " + i;
|
||||
|
||||
const releaseDate = null;
|
||||
|
||||
const chapterUrl = "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}novel/${novelUrl}/${chapterUrl}`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
const chapterName = $("h2").text();
|
||||
let chapterText = $("#chapter-container").html();
|
||||
chapterText = htmlToText(chapterText);
|
||||
|
||||
let nextChapter = null;
|
||||
|
||||
if (!$("a.nextchap.isDisabled").length) {
|
||||
nextChapter = $("a.nextchap")
|
||||
.attr("href")
|
||||
.replace("/novel/" + novelUrl + "/", "");
|
||||
}
|
||||
|
||||
let prevChapter = null;
|
||||
|
||||
if (!$("a.prevchap.isDisabled").length) {
|
||||
prevChapter = $("a.prevchap")
|
||||
.attr("href")
|
||||
.replace("/novel/" + novelUrl + "/", "");
|
||||
}
|
||||
|
||||
novelUrl = novelUrl + "/";
|
||||
chapterUrl = chapterUrl + "/";
|
||||
|
||||
const chapter = {
|
||||
extensionId: 15,
|
||||
novelUrl,
|
||||
chapterUrl,
|
||||
chapterName,
|
||||
chapterText,
|
||||
nextChapter,
|
||||
prevChapter,
|
||||
};
|
||||
|
||||
res.json(chapter);
|
||||
};
|
||||
|
||||
const searchScraper = async (req, res) => {
|
||||
const searchTerm = req.query.s;
|
||||
|
||||
const url = `${baseUrl}lnwsearchlive?inputContent=${searchTerm}`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.json();
|
||||
const data = body.resultview;
|
||||
|
||||
$ = cheerio.load(data);
|
||||
|
||||
let novels = [];
|
||||
|
||||
$(".novel-item").each(function (result) {
|
||||
const novelName = $(this).find("h4.novel-title").text();
|
||||
const novelCover = $(this).find("img").attr("src");
|
||||
|
||||
let novelUrl = $(this).find("a").attr("href").replace(`/novel/`, "");
|
||||
novelUrl += "/";
|
||||
|
||||
const novel = {
|
||||
extensionId: 15,
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
res.json(novels);
|
||||
};
|
||||
|
||||
module.exports = lightNovelPubScraper = {
|
||||
novelsScraper,
|
||||
novelScraper,
|
||||
chapterScraper,
|
||||
searchScraper,
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
Reference in New Issue
Block a user