add WuxiaWorld (closes #2)

This commit is contained in:
Rajarshee Chatterjee
2021-05-01 11:45:37 +05:30
parent eb352ae7ac
commit e632be85b1
6 changed files with 605 additions and 12 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

+199
View File
@@ -0,0 +1,199 @@
const express = require("express");
const cheerio = require("cheerio");
const request = require("request");
const puppeteer = require("puppeteer");
const baseUrl = "https://www.wuxiaworld.com/";
const router = express.Router();
router.get("/novels/", async (req, res) => {
let url = `https://www.wuxiaworld.com/novels`;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const body = await page.content();
let novels = [];
const $ = cheerio.load(body);
$(".novel-item").each(function (result) {
let novelName = $(this).find("div.novel-title").text();
let novelCover = $(this).find("img").attr("src");
let novelUrl = $(this).find("a").attr("href");
novelUrl = novelUrl.replace("/novel/", "").concat("/");
novel = {
extensionId: 7,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
});
res.json(novels);
});
// Novel
router.get("/novel/:novelUrl", async (req, res) => {
let novelUrl = req.params.novelUrl;
let url = `${baseUrl}novel/${novelUrl}/`;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const body = await page.content();
const $ = cheerio.load(body);
let novel = {};
novel.extensionId = 7;
novel.sourceName = "WuxiaWorld";
novel.sourceUrl = url;
novel.novelUrl = `${novelUrl}/`;
novel.novelName = $("h2").text();
novel.novelCover = $("img.img-thumbnail").attr("src");
novel.novelSummary = $(".fr-view > p").text();
novel["Author(s)"] = $("div > dt")
.filter(function () {
return $(this).text().trim() === "Author:";
})
.next()
.text();
let genres = [];
$(".genres")
.find("div")
.each(function (res) {
genres.push($(this).find("a").text());
});
novel["Genre(s)"] = genres.join(",");
novel["Artist(s)"] = null;
novel.Status = null;
let novelChapters = [];
$(".chapter-item").each(function (result) {
let chapterName = $(this).text();
chapterName = chapterName.replace(/[\t\n]/g, "");
let releaseDate = null;
let chapterUrl = $(this).find("a").attr("href");
chapterUrl = chapterUrl.replace(`/novel/${novelUrl}/`, "");
novelChapters.push({
chapterName,
releaseDate,
chapterUrl,
});
});
novel.novelChapters = novelChapters;
res.json(novel);
});
router.get("/novel/:novelUrl/:chapterUrl", async (req, res) => {
let url = `${baseUrl}novel/${req.params.novelUrl}/${req.params.chapterUrl}`;
const novelUrl = `${req.params.novelUrl}/`;
const chapterUrl = `${req.params.chapterUrl}/`;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const body = await page.content();
const $ = cheerio.load(body);
let chapterName = $("#sidebar-toggler-container").next().text();
chapterName = chapterName.replace(/[\t\n]/g, "");
let chapterText = $("#chapter-content").text();
let nextChapter = null;
if ($("li.next > a").attr("href") !== "#") {
nextChapter = $("li.next > a")
.attr("href")
.replace(`/novel/${novelUrl}`, "");
}
let prevChapter = null;
if ($("li.prev > a").attr("href") !== "#") {
prevChapter = $("li.prev > a")
.attr("href")
.replace(`/novel/${novelUrl}`, "");
}
chapter = {
extensionId: 7,
novelUrl,
chapterUrl,
chapterName,
chapterText,
nextChapter,
prevChapter,
};
res.json(chapter);
});
router.get("/search/", (req, res) => {
let searchTerm = req.query.s;
searchTerm = encodeURI(searchTerm);
const searchUrl = `https://www.wuxiaworld.com/api/novels/search?query=}`;
const url = `${searchUrl}${searchTerm}`;
request(url, (err, response, body) => {
if (err) throw err;
$ = cheerio.load(body);
let novels = [];
let data = JSON.parse(body);
data = data.items;
data.map((novel) => {
let novelName = novel.name;
let novelCover = novel.coverUrl;
let novelUrl = novel.slug;
novelUrl = novelUrl + "/";
novels.push({
extensionId: 7,
novelUrl,
novelName,
novelCover,
});
});
res.json(novels);
});
});
module.exports = router;
+9
View File
@@ -53,6 +53,15 @@ extensions = [
sourceLanguage: "English",
status: 1,
},
{
sourceId: 7,
sourceUrl: "https://www.wuxiaworld.com/",
sourceName: "WuxiaWorld",
sourceCover:
"https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/wuxiaworld/icon.png?raw=true",
sourceLanguage: "English",
status: 1,
},
];
module.exports = extensions;