Add Scribble Hub

This commit is contained in:
Rajarshee Chatterjee
2021-06-30 08:23:23 +05:30
parent bfaf1981d0
commit 738e311731
6 changed files with 211 additions and 0 deletions
+1
View File
@@ -30,6 +30,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader)
| https://comrademao.com/ | :heavy_check_mark: |
| https://www.novelpassion.com/ | :heavy_check_mark: |
| https://www.royalroad.com/ | :heavy_check_mark: |
| https://www.scribblehub.com/ | :heavy_check_mark: |
| https://tunovelaligera.com/ | :heavy_check_mark: |
| https://www.skynovels.net/ | :heavy_check_mark: |
| https://einherjarproject.net/ | :heavy_check_mark: |
+1
View File
@@ -44,6 +44,7 @@ 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"));
app.use("/api/35/", require("./src/en/scribblehub/ScribbleHub"));
// Spanish
app.use("/api/23/", require("./src/es/tunovelaligera/Tunovelaligera"));
+9
View File
@@ -228,6 +228,15 @@ extensions = [
sourceLanguage: "English",
status: 1,
},
{
sourceId: 35,
sourceUrl: "https://www.scribblehub.com/",
sourceName: "Scribble Hub",
sourceCover:
"https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/en/scribblehub/icon.png?raw=true",
sourceLanguage: "English",
status: 1,
},
/**
* Spanish
+14
View File
@@ -0,0 +1,14 @@
const express = require("express");
const ScribbleHubScraper = require("./ScribbleHubScraper");
const router = express.Router();
router.get("/novels/", ScribbleHubScraper.novelsScraper);
router.get("/novel/:novelUrl", ScribbleHubScraper.novelScraper);
router.get("/novel/:novelUrl/:chapterUrl", ScribbleHubScraper.chapterScraper);
router.get("/search/", ScribbleHubScraper.searchScraper);
module.exports = router;
+186
View File
@@ -0,0 +1,186 @@
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const { htmlToText } = require("html-to-text");
const { parseHtml } = require("../../helper");
const FormData = require("form-data");
const baseUrl = "https://www.scribblehub.com/";
const novelsScraper = async (req, res) => {
let url = baseUrl + "series-ranking/?sort=1&order=4&pg=1";
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novels = [];
$("div.search_main_box").each(function (result) {
const novelName = $(this).find("div.search_title > a").text();
const novelCover = $(this).find("div.search_img > img").attr("src");
let novelUrl = $(this).find("div.search_title > a").attr("href");
novelUrl = novelUrl.split("/");
novelUrl = novelUrl[4] + "-" + novelUrl[5];
const novel = {
extensionId: 35,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
});
res.json(novels);
};
const novelScraper = async (req, res) => {
const novelUrl = req.params.novelUrl;
const url = baseUrl + "read/" + novelUrl;
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novel = {};
novel.extensionId = 35;
novel.sourceName = "Scribble Hub";
novel.sourceUrl = url;
novel.novelUrl = novelUrl;
novel.novelName = $("div.fic_title").text();
novel.novelCover = $("div.fic_image > img").attr("src");
novel.novelSummary = $("div.wi_fic_desc").text();
novel["Genre(s)"] = "";
$("span.wi_fic_genre")
.find("span")
.each(function (res) {
novel["Genre(s)"] += $(this).text() + ",";
});
if (novel["Genre(s)"]) {
novel["Genre(s)"] = novel["Genre(s)"].slice(0, -1);
}
novel["Author(s)"] = $("span.auth_name_fic").text();
let formData = new FormData();
formData.append("action", "wi_getreleases_pagination");
formData.append("pagenum", "-1");
formData.append("mypostid", novelUrl.split("-")[0]);
const data = await fetch(
"https://www.scribblehub.com/wp-admin/admin-ajax.php",
{
method: "POST",
body: formData,
}
);
const text = await data.text();
$ = cheerio.load(text);
let novelChapters = [];
$(".toc_w").each(function (result) {
const chapterName = $(this).find(".toc_a").text();
const releaseDate = $(this).find(".fic_date_pub").text();
const chapterUrl = $(this).find("a").attr("href").split("/")[6];
// .replace("/novel/" + novelUrl + "/", "");
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}read/${novelUrl}/chapter/${chapterUrl}`;
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let chapterName = $("div.chapter-title").text();
let chapterText = $("div.chp_raw").html();
chapterText = parseHtml(chapterText);
let nextChapter = null;
let prevChapter = null;
const chapter = {
extensionId: 35,
novelUrl,
chapterUrl,
chapterName,
chapterText,
nextChapter,
prevChapter,
};
res.json(chapter);
};
const searchScraper = async (req, res) => {
const searchTerm = req.query.s;
const url =
"https://www.scribblehub.com/?s=" +
searchTerm +
"&post_type=fictionposts";
const result = await fetch(url);
const body = await result.text();
$ = cheerio.load(body);
let novels = [];
$("div.search_main_box").each(function (result) {
const novelName = $(this).find("div.search_title > a").text();
const novelCover = $(this).find("div.search_img > img").attr("src");
let novelUrl = $(this).find("div.search_title > a").attr("href");
novelUrl = novelUrl.split("/");
novelUrl = novelUrl[4] + "-" + novelUrl[5];
const novel = {
extensionId: 35,
novelName,
novelCover,
novelUrl,
};
novels.push(novel);
});
res.json(novels);
};
module.exports = vipNovelScraper = {
novelsScraper,
novelScraper,
chapterScraper,
searchScraper,
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB