Add arabic sources

This commit is contained in:
Rajarshee Chatterjee
2021-07-16 09:23:49 +05:30
parent 517af27937
commit 340d4e5939
6 changed files with 252 additions and 8 deletions
+9 -8
View File
@@ -4,17 +4,17 @@ const sources = require("./sources");
const app = express(); const app = express();
app.use( app.use(
express.json({ express.json({
extended: false, extended: false,
}) })
); );
app.get("/", (req, res) => app.get("/", (req, res) =>
res.json({ res.json({
Author: "@rajarsheechatterjee", Author: "@rajarsheechatterjee",
Version: "1.0.0", Version: "1.0.0",
Github: "https://github.com/rajarsheechatterjee/lnreader-extensions", Github: "https://github.com/rajarsheechatterjee/lnreader-extensions",
}) })
); );
// English // English
@@ -67,6 +67,7 @@ app.use("/api/50/", require("./src/ch/yushubo/Yushubo"));
// MultiSrc // MultiSrc
app.use("/api/", require("./multisrc/madara/MadaraGenerator")); app.use("/api/", require("./multisrc/madara/MadaraGenerator"));
app.use("/api/", require("./multisrc/wpmangastream/WPMangaStreamGenerator"));
const PORT = process.env.PORT || 5000; const PORT = process.env.PORT || 5000;
@@ -0,0 +1,41 @@
const express = require("express");
const WPMangaStreamScraper = require("./WPMangaStreamScraper");
const router = express.Router();
const madaraSources = [
{
extensionId: 53,
scraper: new WPMangaStreamScraper(
53,
"https://kolnovel.com/",
"KolNovel"
),
},
{
extensionId: 54,
scraper: new WPMangaStreamScraper(
54,
"https://rewayat-ar.site/",
"Rewayat-Ar"
),
},
];
madaraSources.map((source) => {
router.get(`/${source.extensionId}/novels/`, source.scraper.novelsScraper);
router.get(
`/${source.extensionId}/novel/:novelUrl`,
source.scraper.novelScraper
);
router.get(
`/${source.extensionId}/novel/:novelUrl/:chapterUrl`,
source.scraper.chapterScraper
);
router.get(`/${source.extensionId}/search/`, source.scraper.searchScraper);
});
module.exports = router;
@@ -0,0 +1,180 @@
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const { parseHtml } = require("../../src/helper");
class MadaraScraper {
constructor(extensionId, baseUrl, sourceName) {
this.extensionId = extensionId;
this.baseUrl = baseUrl;
this.sourceName = sourceName;
this.novelsScraper = this.novelsScraper.bind(this);
this.novelScraper = this.novelScraper.bind(this);
this.chapterScraper = this.chapterScraper.bind(this);
this.searchScraper = this.searchScraper.bind(this);
}
async novelsScraper(req, res) {
let url = this.baseUrl + "series/?m_orderby=popular";
let extensionId = this.extensionId;
const result = await fetch(url);
const body = await result.text();
const $ = cheerio.load(body);
let novels = [];
$("article.bs").each(function (result) {
const novelName = $(this).find(".ntitle").text().trim();
let image = $(this).find("img");
const novelCover = image.attr("src");
let novelUrl = $(this).find("a").attr("href").split("/")[4];
const novel = {
extensionId,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
});
res.json(novels);
}
async novelScraper(req, res) {
const novelUrl = req.params.novelUrl;
const url = `${this.baseUrl}series/${novelUrl}/`;
const result = await fetch(url);
const body = await result.text();
let $ = cheerio.load(body);
let novel = {};
novel.extensionId = this.extensionId;
novel.sourceName = this.sourceName;
novel.sourceUrl = url;
novel.novelUrl = novelUrl;
novel.novelName = $(".entry-title").text();
novel.novelCover = $("img.thumb").attr("src");
$("div.spe > span").each(function (result) {
const detailName = $(this).find("b").text().trim();
const detail = $(this).find("b").next().text().trim();
if ($(this).text().includes("الحالة:")) {
novel.Status = $(this).text().replace("الحالة: ", "");
}
switch (detailName) {
case "المؤلف:":
novel["Author(s)"] = detail;
break;
}
});
novel["Genre(s)"] = $(".genxed").text().replace(/\s/g, ",");
novel.novelSummary = $('div[itemprop="description"]').text().trim();
let novelChapters = [];
$(".eplister")
.find("li")
.each(function (result) {
const chapterName =
$(this).find(".epl-num").text() +
" - " +
$(this).find(".epl-title").text();
const releaseDate = $(this).find(".epl-date").text().trim();
const chapterUrl = $(this).find("a").attr("href").split("/")[3];
novelChapters.push({ chapterName, releaseDate, chapterUrl });
});
novel.novelChapters = novelChapters.reverse();
res.json(novel);
}
async chapterScraper(req, res) {
let novelUrl = req.params.novelUrl;
let chapterUrl = req.params.chapterUrl;
let extensionId = this.extensionId;
const url = `${this.baseUrl}${chapterUrl}`;
const result = await fetch(url);
const body = await result.text();
const $ = cheerio.load(body);
let chapterName = $(".entry-title").text();
let chapterText = $(".entry-content").html();
chapterText = parseHtml(chapterText);
let nextChapter = null;
let prevChapter = null;
const chapter = {
extensionId,
novelUrl,
chapterUrl,
chapterName,
chapterText,
nextChapter,
prevChapter,
};
res.json(chapter);
}
async searchScraper(req, res) {
const searchTerm = req.query.s;
const url = `${this.baseUrl}?s=${searchTerm}`;
const result = await fetch(url);
const body = await result.text();
const $ = cheerio.load(body);
let novels = [];
let extensionId = this.extensionId;
$("article.bs").each(function (result) {
const novelName = $(this).find(".ntitle").text().trim();
let image = $(this).find("img");
const novelCover = image.attr("src");
let novelUrl = $(this).find("a").attr("href").split("/")[4];
const novel = {
extensionId,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
});
res.json(novels);
}
}
module.exports = MadaraScraper;
Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

+22
View File
@@ -444,6 +444,28 @@ extensions = [
sourceLanguage: "Japanese", sourceLanguage: "Japanese",
status: 1, status: 1,
}, },
/**
* Arabic
*/
{
sourceId: 53,
sourceUrl: "https://kolnovel.com/",
sourceName: "KolNovel",
sourceCover:
"https://github.com/LNReader/lnreader-sources/blob/main/multisrc/wpmangastream/icons/kolnovel.png?raw=true",
sourceLanguage: "Arabic",
status: 1,
},
{
sourceId: 54,
sourceUrl: "https://rewayat-ar.site/",
sourceName: "Rewayat-Ar",
sourceCover:
"https://github.com/LNReader/lnreader-sources/blob/main/multisrc/wpmangastream/icons/rewayatar.png?raw=true",
sourceLanguage: "Arabic",
status: 1,
},
]; ];
module.exports = extensions; module.exports = extensions;