Add Oasis Translations (Closes #29)

This commit is contained in:
Rajarshee Chatterjee
2021-06-05 18:22:45 +05:30
parent 62d414baf2
commit 2ecab780b2
6 changed files with 271 additions and 30 deletions
+31 -30
View File
@@ -4,36 +4,37 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader)
## Sources
| Source | Status |
| ----------------------------- | :----------------: |
| BoxNovel | :heavy_check_mark: |
| ReadLightNovel | :heavy_check_mark: |
| FastNovel | :x: |
| ReadNovelFull | :heavy_check_mark: |
| MTLNovel | :heavy_check_mark: |
| NovelHall | :heavy_check_mark: |
| WuxiaWorld | :heavy_check_mark: |
| NovelFull | :heavy_check_mark: |
| NovelTrench | :heavy_check_mark: |
| VipNovel | :heavy_check_mark: |
| KissLightNovels | :heavy_check_mark: |
| https://wuxiaworldsite.co/ | :heavy_check_mark: |
| FreeWebNovel | :heavy_check_mark: |
| JPMTL | :heavy_check_mark: |
| LightNovelPub | :heavy_check_mark: |
| https://www.wuxiaworld.co/ | :heavy_check_mark: |
| TapRead | :heavy_check_mark: |
| https://www.novelupdates.cc/ | :heavy_check_mark: |
| https://m.readlightnovel.cc/ | :heavy_check_mark: |
| http://wuxiaworld.cloud/ | :heavy_check_mark: |
| https://foxaholic.com/ | :heavy_check_mark: |
| https://comrademao.com/ | :heavy_check_mark: |
| https://tunovelaligera.com/ | :heavy_check_mark: |
| https://www.skynovels.net/ | :heavy_check_mark: |
| https://einherjarproject.net/ | :heavy_check_mark: |
| https://novelasligera.com/ | :heavy_check_mark: |
| https://yuukitls.com/ | :heavy_check_mark: |
| https://hasutl.wordpress.com/ | :heavy_check_mark: |
| Source | Status |
| ---------------------------------------- | :----------------: |
| BoxNovel | :heavy_check_mark: |
| ReadLightNovel | :heavy_check_mark: |
| FastNovel | :x: |
| ReadNovelFull | :heavy_check_mark: |
| MTLNovel | :heavy_check_mark: |
| NovelHall | :heavy_check_mark: |
| WuxiaWorld | :heavy_check_mark: |
| NovelFull | :heavy_check_mark: |
| NovelTrench | :heavy_check_mark: |
| VipNovel | :heavy_check_mark: |
| KissLightNovels | :heavy_check_mark: |
| https://wuxiaworldsite.co/ | :heavy_check_mark: |
| FreeWebNovel | :heavy_check_mark: |
| JPMTL | :heavy_check_mark: |
| LightNovelPub | :heavy_check_mark: |
| https://www.wuxiaworld.co/ | :heavy_check_mark: |
| TapRead | :heavy_check_mark: |
| https://www.novelupdates.cc/ | :heavy_check_mark: |
| https://m.readlightnovel.cc/ | :heavy_check_mark: |
| http://wuxiaworld.cloud/ | :heavy_check_mark: |
| https://foxaholic.com/ | :heavy_check_mark: |
| https://comrademao.com/ | :heavy_check_mark: |
| https://tunovelaligera.com/ | :heavy_check_mark: |
| https://www.skynovels.net/ | :heavy_check_mark: |
| https://einherjarproject.net/ | :heavy_check_mark: |
| https://novelasligera.com/ | :heavy_check_mark: |
| https://yuukitls.com/ | :heavy_check_mark: |
| https://hasutl.wordpress.com/ | :heavy_check_mark: |
| https://oasistranslations.wordpress.com/ | :heavy_check_mark: |
## Setup locally
+1
View File
@@ -50,6 +50,7 @@ app.use("/api/25/", require("./src/es/einherjarproject/EinherjarProject"));
app.use("/api/26/", require("./src/es/novelasligera/NovelasLigera"));
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"));
const PORT = process.env.PORT || 5000;
+9
View File
@@ -269,6 +269,15 @@ extensions = [
sourceLanguage: "Spanish",
status: 1,
},
{
sourceId: 30,
sourceUrl: "https://oasistranslations.wordpress.com/",
sourceName: "Oasis Translations",
sourceCover:
"https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/es/oasistranslations/icon.png?raw=true",
sourceLanguage: "Spanish",
status: 1,
},
];
module.exports = extensions;
@@ -0,0 +1,17 @@
const express = require("express");
const OasisTranslationsScraper = require("./OasisTranslationsScraper");
const router = express.Router();
router.get("/novels/", OasisTranslationsScraper.novelsScraper);
router.get("/novel/:novelUrl", OasisTranslationsScraper.novelScraper);
router.get(
"/novel/:novelUrl/:chapterUrl",
OasisTranslationsScraper.chapterScraper
);
router.get("/search/", OasisTranslationsScraper.searchScraper);
module.exports = router;
@@ -0,0 +1,213 @@
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const { htmlToText } = require("html-to-text");
const { parseHtml } = require("../../helper");
const baseUrl = "https://oasistranslations.wordpress.com/";
const novelsScraper = async (req, res) => {
let url = baseUrl;
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novels = [];
$(".menu-item-1819")
.find(".sub-menu > li")
.each(function (result) {
const novelName = $(this).text();
if (!novelName.match(/Activas|Finalizadas|Dropeadas/)) {
const novelCover = $(this).find("img").attr("src");
let novelUrl = $(this).find("a").attr("href");
novelUrl = novelUrl.split("/");
novelUrl = novelUrl[novelUrl.length - 2] + "/";
const novel = {
extensionId: 30,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
}
});
res.json(novels);
};
const novelScraper = async (req, res) => {
const novelUrl = req.params.novelUrl;
const url = baseUrl + novelUrl + "/";
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novel = {};
novel.extensionId = 30;
novel.sourceName = "Oasis Translations";
novel.sourceUrl = url;
novel.novelUrl = novelUrl + "/";
novel.novelName = $("h1.entry-title")
.text()
.replace(/[\t\n]/g, "")
.trim();
novel.novelCover = $('img[loading="lazy"]').attr("src");
let details = $(".entry-content").find("h2").next().html();
details = details.match(/<\/strong>(.|\n)*?<br>/g);
details = details.map((detail) =>
detail.replace(/<strong>|<\/strong>|<br>|:\s/g, "")
);
novel["Genre(s)"] = "";
novel["Author(s)"] = details[2];
novel["Genre(s)"] = details[4].replace(/\s/g, "");
novel["Artist(s)"] = details[3];
let novelSummary = $(".entry-content").find("h2").next().next().html();
novel.novelSummary = htmlToText(novelSummary);
let novelChapters = [];
// if ($(".entry-content").find("li").length) {
$(".entry-content")
.find("a")
.each(function (result) {
let chapterUrl = $(this).attr("href");
if (chapterUrl && chapterUrl.includes(baseUrl)) {
const chapterName = $(this).text();
const releaseDate = null;
chapterUrl = chapterUrl.split("/");
chapterUrl = chapterUrl[chapterUrl.length - 2] + "/";
const chapter = { chapterName, releaseDate, chapterUrl };
novelChapters.push(chapter);
}
});
// } else {
// $(".entry-content")
// .find("p")
// .each(function (result) {
// let chapterUrl = $(this).find("a").attr("href");
// if (chapterUrl && chapterUrl.includes(baseUrl)) {
// const chapterName = $(this).text();
// const releaseDate = null;
// chapterUrl = chapterUrl.split("/");
// chapterUrl = chapterUrl[chapterUrl.length - 2] + "/";
// 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}/${novelUrl}/${chapterUrl}`;
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let chapterName = $("h1.entry-title").text();
$("div#jp-post-flair").remove();
let chapterText = $(".entry-content").html();
chapterText = parseHtml(chapterText);
let nextChapter = null;
let prevChapter = null;
novelUrl = novelUrl + "/";
chapterUrl = chapterUrl + "/";
const chapter = {
extensionId: 30,
novelUrl,
chapterUrl,
chapterName,
chapterText,
nextChapter,
prevChapter,
};
res.json(chapter);
};
const searchScraper = async (req, res) => {
let searchTerm = req.query.s;
searchTerm = searchTerm.toLowerCase();
let url = baseUrl;
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novels = [];
$(".menu-item-1819")
.find(".sub-menu > li")
.each(function (result) {
const novelName = $(this).text();
if (!novelName.match(/Activas|Finalizadas|Dropeadas/)) {
const novelCover = $(this).find("img").attr("src");
let novelUrl = $(this).find("a").attr("href");
novelUrl = novelUrl.split("/");
novelUrl = novelUrl[novelUrl.length - 2] + "/";
const novel = {
extensionId: 30,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
}
});
novels = novels.filter((novel) =>
novel.novelName.toLowerCase().includes(searchTerm)
);
res.json(novels);
};
module.exports = vipNovelScraper = {
novelsScraper,
novelScraper,
chapterScraper,
searchScraper,
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 411 KiB