diff --git a/README.md b/README.md index f851aa1..86195ba 100644 --- a/README.md +++ b/README.md @@ -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: | diff --git a/index.js b/index.js index 4de947b..955838b 100644 --- a/index.js +++ b/index.js @@ -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")); diff --git a/sources.js b/sources.js index 03148d6..6870d44 100644 --- a/sources.js +++ b/sources.js @@ -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 diff --git a/src/en/scribblehub/ScribbleHub.js b/src/en/scribblehub/ScribbleHub.js new file mode 100644 index 0000000..c5023d6 --- /dev/null +++ b/src/en/scribblehub/ScribbleHub.js @@ -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; diff --git a/src/en/scribblehub/ScribbleHubScraper.js b/src/en/scribblehub/ScribbleHubScraper.js new file mode 100644 index 0000000..65e8cb9 --- /dev/null +++ b/src/en/scribblehub/ScribbleHubScraper.js @@ -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, +}; diff --git a/src/en/scribblehub/icon.png b/src/en/scribblehub/icon.png new file mode 100644 index 0000000..c3a558b Binary files /dev/null and b/src/en/scribblehub/icon.png differ