Add Royal Road
This commit is contained in:
@@ -29,6 +29,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader)
|
||||
| https://foxaholic.com/ | :heavy_check_mark: |
|
||||
| https://comrademao.com/ | :heavy_check_mark: |
|
||||
| https://www.novelpassion.com/ | :heavy_check_mark: |
|
||||
| https://www.royalroad.com/ | :heavy_check_mark: |
|
||||
| https://tunovelaligera.com/ | :heavy_check_mark: |
|
||||
| https://www.skynovels.net/ | :heavy_check_mark: |
|
||||
| https://einherjarproject.net/ | :heavy_check_mark: |
|
||||
|
||||
@@ -42,6 +42,8 @@ app.use("/api/20/", require("./src/en/wuxiaworldcloud/WuxiaWorldCloud"));
|
||||
app.use("/api/21/", require("./src/en/woopread/WoopRead"));
|
||||
app.use("/api/22/", require("./src/en/foxaholic/Foxaholic"));
|
||||
app.use("/api/27/", require("./src/en/comrademao/ComradeMao"));
|
||||
app.use("/api/33/", require("./src/en/novelpassion/NovelPassion"));
|
||||
app.use("/api/34/", require("./src/en/royalroad/RoyalRoad"));
|
||||
|
||||
// Spanish
|
||||
app.use("/api/23/", require("./src/es/tunovelaligera/Tunovelaligera"));
|
||||
@@ -52,7 +54,6 @@ app.use("/api/28/", require("./src/es/yuukitls/YuukiTls"));
|
||||
app.use("/api/29/", require("./src/es/hasutl/Hasutl"));
|
||||
app.use("/api/30/", require("./src/es/oasistranslations/OasisTranslations"));
|
||||
app.use("/api/31/", require("./src/es/novelawuxia/NovelaWuxia"));
|
||||
app.use("/api/33/", require("./src/en/novelpassion/NovelPassion"));
|
||||
|
||||
const PORT = process.env.PORT || 5000;
|
||||
|
||||
|
||||
+10
-1
@@ -211,7 +211,7 @@ extensions = [
|
||||
status: 1,
|
||||
},
|
||||
{
|
||||
sourceId: 27,
|
||||
sourceId: 33,
|
||||
sourceUrl: "https://www.novelpassion.com/",
|
||||
sourceName: "NovelPassion",
|
||||
sourceCover:
|
||||
@@ -219,6 +219,15 @@ extensions = [
|
||||
sourceLanguage: "English",
|
||||
status: 1,
|
||||
},
|
||||
{
|
||||
sourceId: 34,
|
||||
sourceUrl: "https://www.royalroad.com/",
|
||||
sourceName: "Royal Road",
|
||||
sourceCover:
|
||||
"https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/royalroad/icon.png?raw=true",
|
||||
sourceLanguage: "English",
|
||||
status: 1,
|
||||
},
|
||||
|
||||
/**
|
||||
* Spanish
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const express = require("express");
|
||||
const RoyalRoadScraper = require("./RoyalRoadScraper");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/novels/", RoyalRoadScraper.novelsScraper);
|
||||
|
||||
router.get("/novel/:novelId/:novelUrl", RoyalRoadScraper.novelScraper);
|
||||
|
||||
router.get(
|
||||
"/novel/:novelId/:novelUrl/:chapterId/:chapterUrl",
|
||||
RoyalRoadScraper.chapterScraper
|
||||
);
|
||||
|
||||
router.get("/search/", RoyalRoadScraper.searchScraper);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,185 @@
|
||||
const cheerio = require("cheerio");
|
||||
const fetch = require("node-fetch");
|
||||
const { htmlToText } = require("html-to-text");
|
||||
const { parseHtml } = require("../../helper");
|
||||
|
||||
const baseUrl = "https://www.royalroad.com/";
|
||||
|
||||
const novelsScraper = async (req, res) => {
|
||||
let url = baseUrl + "fictions/best-rated?page=1";
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
let novels = [];
|
||||
|
||||
$("div.fiction-list-item.row").each(function (result) {
|
||||
const novelName = $(this).find("h2.fiction-title").text().trim();
|
||||
const novelCover = $(this).find("img").attr("src");
|
||||
|
||||
let novelUrl = $(this)
|
||||
.find("h2.fiction-title > a")
|
||||
.attr("href")
|
||||
.replace("/fiction/", "");
|
||||
|
||||
const novel = {
|
||||
extensionId: 34,
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
res.json(novels);
|
||||
};
|
||||
|
||||
const novelScraper = async (req, res) => {
|
||||
const novelId = req.params.novelId;
|
||||
const novelUrl = req.params.novelUrl;
|
||||
const url = baseUrl + "fiction/" + +novelId + "/" + novelUrl;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
let novel = {};
|
||||
|
||||
novel.extensionId = 34;
|
||||
|
||||
novel.sourceName = "Royal Road";
|
||||
|
||||
novel.sourceUrl = url;
|
||||
|
||||
novel.novelUrl = novelUrl;
|
||||
|
||||
novelName = $("h1").text();
|
||||
novel.novelName = novelName;
|
||||
|
||||
novel.novelCover = $("#thumbnail > img").attr("src");
|
||||
|
||||
novel.novelSummary = $("div.description").text().trim();
|
||||
|
||||
novel["Genre(s)"] = $("span.tags").text().trim().replace(/\n\s+/g, ",");
|
||||
novel.Status = $(
|
||||
"div.fiction-info > div.portlet > .col-md-8 > .margin-bottom-10 > span"
|
||||
)
|
||||
.first()
|
||||
.next()
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
let novelChapters = [];
|
||||
|
||||
$("table#chapters > tbody")
|
||||
.find("tr")
|
||||
.each(function (result) {
|
||||
const chapterName = $(this).find("td").first().text().trim();
|
||||
const releaseDate = $(this).find("td").first().next().text().trim();
|
||||
|
||||
const chapterUrl = $(this)
|
||||
.find("td")
|
||||
.first()
|
||||
.find("a")
|
||||
.attr("href")
|
||||
.replace(
|
||||
"/fiction/" + +novelId + "/" + novelUrl + "/chapter/",
|
||||
""
|
||||
);
|
||||
|
||||
novelChapters.push({
|
||||
chapterName,
|
||||
releaseDate,
|
||||
chapterUrl,
|
||||
});
|
||||
});
|
||||
|
||||
novel.novelChapters = novelChapters;
|
||||
|
||||
res.json(novel);
|
||||
};
|
||||
|
||||
const chapterScraper = async (req, res) => {
|
||||
let novelUrl = req.params.novelUrl;
|
||||
let chapterUrl = req.params.chapterUrl;
|
||||
|
||||
const url = `${baseUrl}fiction/${req.params.novelId}/${novelUrl}/chapter/${req.params.chapterId}/${req.params.chapterUrl}`;
|
||||
|
||||
console.log(url);
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
let chapterName = $("div.chapter-content").find("strong").text();
|
||||
|
||||
let chapterText = $("div.chapter-content").html();
|
||||
chapterText = parseHtml(chapterText);
|
||||
|
||||
let nextChapter = null;
|
||||
let prevChapter = null;
|
||||
|
||||
const chapter = {
|
||||
extensionId: 34,
|
||||
novelUrl,
|
||||
chapterUrl,
|
||||
chapterName,
|
||||
chapterText,
|
||||
nextChapter,
|
||||
prevChapter,
|
||||
};
|
||||
|
||||
res.json(chapter);
|
||||
};
|
||||
|
||||
const searchScraper = async (req, res) => {
|
||||
const searchTerm = req.query.s;
|
||||
|
||||
const url = baseUrl + "fictions/search?title=" + searchTerm;
|
||||
|
||||
console.log(url);
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
let novels = [];
|
||||
|
||||
$("div.fiction-list-item.row").each(function (result) {
|
||||
const novelName = $(this).find("h2.fiction-title").text().trim();
|
||||
let novelCover = $(this).find("img").attr("src");
|
||||
|
||||
if (novelCover.includes("Content")) {
|
||||
novelCover = baseUrl + novelCover;
|
||||
}
|
||||
|
||||
let novelUrl = $(this)
|
||||
.find("h2.fiction-title > a")
|
||||
.attr("href")
|
||||
.replace("/fiction/", "");
|
||||
|
||||
const novel = {
|
||||
extensionId: 34,
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
res.json(novels);
|
||||
};
|
||||
|
||||
module.exports = RoyalRoadScraper = {
|
||||
novelsScraper,
|
||||
novelScraper,
|
||||
chapterScraper,
|
||||
searchScraper,
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 152 KiB |
Reference in New Issue
Block a user