add KissLightNovels (#12)

This commit is contained in:
Rajarshee Chatterjee
2021-05-10 21:42:03 +05:30
committed by GitHub
parent a5e9373c4a
commit d5fb9419ce
5 changed files with 222 additions and 1 deletions
+1
View File
@@ -28,6 +28,7 @@ app.use("/api/7/", require("./src/en/wuxiaworld/WuxiaWorld"));
app.use("/api/8/", require("./src/en/novelfull/NovelFull")); app.use("/api/8/", require("./src/en/novelfull/NovelFull"));
app.use("/api/9/", require("./src/en/noveltrench/NovelTrench")); app.use("/api/9/", require("./src/en/noveltrench/NovelTrench"));
app.use("/api/10/", require("./src/en/vipnovel/VipNovel")); app.use("/api/10/", require("./src/en/vipnovel/VipNovel"));
app.use("/api/11/", require("./src/en/kisslightnovels/KissLightNovels"));
const PORT = process.env.PORT || 5000; const PORT = process.env.PORT || 5000;
+9 -1
View File
@@ -80,7 +80,6 @@ extensions = [
sourceLanguage: "English", sourceLanguage: "English",
status: 1, status: 1,
}, },
{ {
sourceId: 10, sourceId: 10,
sourceUrl: "https://vipnovel.com/", sourceUrl: "https://vipnovel.com/",
@@ -90,6 +89,15 @@ extensions = [
sourceLanguage: "English", sourceLanguage: "English",
status: 1, status: 1,
}, },
{
sourceId: 11,
sourceUrl: "https://kisslightnovels.info/",
sourceName: "KissLightNovel",
sourceCover:
"https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/kisslightnovels/icon.png?raw=true",
sourceLanguage: "English",
status: 1,
},
]; ];
module.exports = extensions; module.exports = extensions;
+17
View File
@@ -0,0 +1,17 @@
const express = require("express");
const kissLightNovelsScraper = require("./KissLightNovelsScraper");
const router = express.Router();
router.get("/novels/", kissLightNovelsScraper.novelsScraper);
router.get("/novel/:novelUrl", kissLightNovelsScraper.novelScraper);
router.get(
"/novel/:novelUrl/:chapterUrl",
kissLightNovelsScraper.chapterScraper
);
router.get("/search/", kissLightNovelsScraper.searchScraper);
module.exports = router;
@@ -0,0 +1,195 @@
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const { htmlToText } = require("html-to-text");
const baseUrl = "https://kisslightnovels.info/";
const novelsScraper = async (req, res) => {
const result = await fetch(baseUrl);
const body = await result.text();
$ = cheerio.load(body);
let novels = [];
$(".page-item-detail").each(function (result) {
const novelName = $(this).find("h5 > a").text();
const novelCover = $(this).find("img").attr("src");
let novelUrl = $(this).find("h5 > a").attr("href");
novelUrl = novelUrl.replace(`${baseUrl}novel/`, "");
const novel = {
extensionId: 11,
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 = 11;
novel.sourceName = "KissLightNovels";
novel.sourceUrl = url;
novel.novelUrl = `${novelUrl}/`;
novel.novelName = $(".post-title > h1")
.text()
.replace(/[\t\n]/g, "")
.trim();
novel.novelCover = $(".summary_image > a > img").attr("data-src");
$(".post-content_item").each(function (result) {
detailName = $(this)
.find(".summary-heading > h5")
.text()
.replace(/[\t\n]/g, "")
.trim();
detail = $(this)
.find(".summary-content")
.text()
.replace(/[\t\n]/g, "")
.trim();
novel[detailName] = detail;
});
$(".description-summary > div.summary__content").find("em").remove();
novel.novelSummary = $(".description-summary > div.summary__content")
.text()
.replace(/[\t\n]/g, "");
let novelChapters = [];
$(".wp-manga-chapter").each(function (result) {
chapterName = $(this)
.find("a")
.text()
.replace(/[\t\n]/g, "")
.trim();
releaseDate = $(this)
.find("span")
.text()
.replace(/[\t\n]/g, "")
.trim();
chapterUrl = $(this).find("a").attr("href").replace(url, "");
novelChapters.push({ chapterName, releaseDate, chapterUrl });
});
novel.novelChapters = novelChapters.reverse();
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);
$("#snippet-box").remove();
const chapterName = $("div.text-left > h4").text();
let chapterText = $(".reading-content").html();
chapterText = htmlToText(chapterText);
let nextChapter = null;
if ($(".nav-next").length) {
nextChapter = $(".nav-next")
.find("a")
.attr("href")
.replace(baseUrl + "novel/" + novelUrl + "/", "");
}
let prevChapter = null;
if ($(".nav-previous").length) {
prevChapter = $(".nav-previous")
.find("a")
.attr("href")
.replace(baseUrl + "novel/" + novelUrl + "/", "");
}
novelUrl = novelUrl + "/";
chapterUrl = chapterUrl + "/";
const chapter = {
extensionId: 11,
novelUrl,
chapterUrl,
chapterName,
chapterText,
nextChapter,
prevChapter,
};
res.json(chapter);
};
const searchScraper = async (req, res) => {
const searchTerm = req.query.s;
const url = `${baseUrl}?s=${searchTerm}&post_type=wp-manga&m_orderby=rating`;
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novels = [];
$(".c-tabs-item__content").each(function (result) {
const novelName = $(this).find("h4 > a").text();
const novelCover = $(this).find("img").attr("src");
let novelUrl = $(this).find("h4 > a").attr("href");
novelUrl = novelUrl.replace(`${baseUrl}novel/`, "");
const novel = {
extensionId: 11,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
});
res.json(novels);
};
module.exports = kissLightNovelScraper = {
novelsScraper,
novelScraper,
chapterScraper,
searchScraper,
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB