diff --git a/README.md b/README.md index 7a85e42..84ccadf 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Sources for [LNReader](https://github.com/rajarsheechatterjee/lnreader) | 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: | ## Setup locally diff --git a/index.js b/index.js index a71a29d..2f86b32 100644 --- a/index.js +++ b/index.js @@ -49,6 +49,7 @@ app.use("/api/24/", require("./src/es/skynovels/Skynovels")); 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")); const PORT = process.env.PORT || 5000; diff --git a/sources.js b/sources.js index 899ab47..8fc9a36 100644 --- a/sources.js +++ b/sources.js @@ -260,6 +260,15 @@ extensions = [ sourceLanguage: "Spanish", status: 1, }, + { + sourceId: 29, + sourceUrl: "https://hasutl.wordpress.com/", + sourceName: "Hasu Translations", + sourceCover: + "https://github.com/rajarsheechatterjee/lnreader-extensions/blob/main/src/es/yuukitls/icon.png?raw=true", + sourceLanguage: "Spanish", + status: 1, + }, ]; module.exports = extensions; diff --git a/src/es/hasutl/Hasutl.js b/src/es/hasutl/Hasutl.js new file mode 100644 index 0000000..53112b7 --- /dev/null +++ b/src/es/hasutl/Hasutl.js @@ -0,0 +1,14 @@ +const express = require("express"); +const HasutlScraper = require("./HasutlScraper"); + +const router = express.Router(); + +router.get("/novels/", HasutlScraper.novelsScraper); + +router.get("/novel/:novelUrl", HasutlScraper.novelScraper); + +router.get("/novel/:novelUrl/:chapterUrl", HasutlScraper.chapterScraper); + +router.get("/search/", HasutlScraper.searchScraper); + +module.exports = router; diff --git a/src/es/hasutl/HasutlScraper.js b/src/es/hasutl/HasutlScraper.js new file mode 100644 index 0000000..90e8814 --- /dev/null +++ b/src/es/hasutl/HasutlScraper.js @@ -0,0 +1,199 @@ +const cheerio = require("cheerio"); +const fetch = require("node-fetch"); +const { htmlToText } = require("html-to-text"); +const { parseHtml } = require("../../helper"); + +const baseUrl = "https://hasutl.wordpress.com/"; + +const novelsScraper = async (req, res) => { + let url = baseUrl + "light-novels-activas/"; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $("div.wp-block-columns").each(function (result) { + const novelName = $(this).find(".wp-block-button").text(); + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).find(".wp-block-button > a").attr("href"); + novelUrl = novelUrl.replace(baseUrl, ""); + + const novel = { + extensionId: 29, + 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 = 29; + + novel.sourceName = "Hasu Translations"; + + novel.sourceUrl = url; + + novel.novelUrl = `${novelUrl}/`; + + novel.novelName = $(".post-header").text(); + + novel.novelCover = $(".summary_image > a > img").attr("src"); + + let details = $(".post-content").find("p").html(); + + detailName = details.match(/(.|\n)*?<\/strong>/g); + details = details.match(/<\/strong>(.|\n)*?
/g); + details = details.map((detail) => detail.replace(/<\/strong>|
/g, "")); + + novel["Genre(s)"] = ""; + + detailName.map((detail, index) => { + if (detail.includes("Autor")) { + novel["Author(s)"] = details[index]; + } + if (detail.includes("Géneros")) { + novel["Genre(s)"] = details[index].replace(/\s/g, ""); + } + if (detail.includes("Artista")) { + novel["Artist(s)"] = details[index]; + } + }); + + let novelSummary = $(".post-content").find("p").html(); + novel.novelSummary = htmlToText(novelSummary); + + let novelChapters = []; + + $(".wp-block-media-text__content") + .find("a") + .each(function (result) { + const chapterName = $(this).text().trim(); + + const releaseDate = null; + + let chapterUrl = $(this).attr("href").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 = $(".post-title").text(); + + let chapterText = $(".post-content").html(); + chapterText = parseHtml(chapterText); + + let nextChapter = null; + + // if ($(".nav-next").length) { + // nextChapter = $(".nav-next") + // .find("a") + // .attr("href") + // .replace(baseUrl + "vipnovel/" + novelUrl + "/", ""); + // } + + let prevChapter = null; + + // if ($(".nav-previous").length) { + // prevChapter = $(".nav-previous") + // .find("a") + // .attr("href") + // .replace(baseUrl + "vipnovel/" + novelUrl + "/", ""); + // } + + novelUrl = novelUrl + "/"; + chapterUrl = chapterUrl; + + const chapter = { + extensionId: 29, + novelUrl, + chapterUrl, + chapterName, + chapterText, + nextChapter, + prevChapter, + }; + + res.json(chapter); +}; + +const searchScraper = async (req, res) => { + const searchTerm = req.query.s; + + const url = `${baseUrl}?s=${searchTerm}&post_type=wp-manga`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".post-container ").each(function (result) { + const novelName = $(this).find(".post-header").text(); + if ( + !novelName.includes("Cap") && + !novelName.includes("Vol") && + !novelName.includes("Light Novels") + ) { + const novelCover = $(this).find("img").attr("src"); + + let novelUrl = $(this).find("a").attr("href"); + novelUrl = novelUrl.replace(baseUrl, ""); + + const novel = { + extensionId: 29, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + } + }); + + res.json(novels); +}; + +module.exports = HasutlScraper = { + novelsScraper, + novelScraper, + chapterScraper, + searchScraper, +}; diff --git a/src/es/hasutl/icon.png b/src/es/hasutl/icon.png new file mode 100644 index 0000000..9ca3582 Binary files /dev/null and b/src/es/hasutl/icon.png differ