diff --git a/src/sources/br/ArthurScans.js b/src/sources/br/ArthurScans.js new file mode 100644 index 00000000..b12cd5d9 --- /dev/null +++ b/src/sources/br/ArthurScans.js @@ -0,0 +1,166 @@ +import cheerio from "react-native-cheerio"; +import { Status } from "../helpers/constants"; + +const baseUrl = "https://arthurscan.xyz/"; + +const sourceId = 80; +const sourceName = "ArthurScans (Br)"; + +const popularNovels = async (page) => { + let url = baseUrl + "/manga/page/" + page + "/?m_orderby=rating"; + + const totalPages = 2; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".page-item-detail").each(function () { + const novelName = $(this).find(".item-summary h3").text().trim(); + const novelCover = $(this).find(".img-responsive").attr("data-src"); + + let novelUrl = $(this).find("div > a").attr("href"); + + const novel = { + sourceId, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + return { totalPages, novels }; +}; + +const parseNovelAndChapters = async (novelUrl) => { + const url = novelUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novel = { sourceId, url, sourceName }; + + $(".post-title > h3 > span").remove(); + + novel.novelUrl = novelUrl; + + novel.novelName = $(".post-title > h1").text().trim(); + + novel.novelCover = $(".summary_image > a > img").attr("data-src"); + + $(".post-content_item").each(function () { + const detailName = $(this).find(".summary-heading > h5").text().trim(); + const detail = $(this).find(".summary-content").text().trim(); + + switch (detailName) { + case "Genre(s)": + novel.genre = detail.replace(/[\t\n]/g, ","); + break; + case "Author(s)": + novel.author = detail; + break; + case "Status": + novel.status = detail.includes("OnGoing") + ? Status.ONGOING + : Status.COMPLETED; + break; + } + }); + + $(".description-summary > div.summary__content").find("em").remove(); + $(".premium-block").remove(); + + novel.summary = $("div.summary__content").text().trim(); + + let novelChapters = []; + + const data = await fetch(novelUrl + "ajax/chapters", { method: "POST" }); + const text = await data.text(); + + $ = cheerio.load(text); + + $(".wp-manga-chapter").each(function () { + $("i").remove(); + + const chapterName = $(this).find("a").text().trim(); + const releaseDate = null; + + const chapterUrl = $(this).find("a").attr("href"); + + const chapter = { chapterName, releaseDate, chapterUrl }; + + novelChapters.push(chapter); + }); + + novel.chapters = novelChapters.reverse(); + + return novel; +}; + +const parseChapter = async (novelUrl, chapterUrl) => { + const url = chapterUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + const chapterName = $("#chapter-heading").text(); + const chapterText = $(".reading-content").html(); + + const chapter = { + sourceId, + novelUrl, + chapterUrl, + chapterName, + chapterText, + }; + + return chapter; +}; + +const searchNovels = async (searchTerm) => { + const url = `${baseUrl}?s=${searchTerm}&post_type=wp-manga`; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".c-tabs-item__content").each(function (result) { + const novelName = $(this).find(".post-title > h3").text().trim(); + const novelCover = $(this).find("div > div > a > img").attr("data-src"); + + let novelUrl = $(this).find("div > div > a").attr("href"); + novelUrl = novelUrl.replace(`${baseUrl}/`, ""); + + const novel = { + sourceId, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + return novels; +}; + +const ArthurScansScraper = { + popularNovels, + parseNovelAndChapters, + parseChapter, + searchNovels, +}; + +export default ArthurScansScraper; diff --git a/src/sources/br/ReaperScansBr.js b/src/sources/br/ReaperScansBr.js index 6a09c4c1..54deac73 100644 --- a/src/sources/br/ReaperScansBr.js +++ b/src/sources/br/ReaperScansBr.js @@ -38,8 +38,6 @@ const popularNovels = async (page) => { novels.push(novel); }); - console.log(novels); - return { totalPages, novels }; }; @@ -107,7 +105,6 @@ const parseNovelAndChapters = async (novelUrl) => { const parseChapter = async (novelUrl, chapterUrl) => { const url = chapterUrl; - console.log(url); const result = await fetch(url); const body = await result.text(); diff --git a/src/sources/helpers/htmlToText.js b/src/sources/helpers/htmlToText.js index ef1b56b6..e02f7023 100644 --- a/src/sources/helpers/htmlToText.js +++ b/src/sources/helpers/htmlToText.js @@ -67,7 +67,10 @@ const htmlToText = (html, options = {}) => { * -> [img](src) */ - // .replace(/<\s*img[^>]*src=['"](.*?)['"][^>]*>/gi, "[img]($1)") + .replace( + /<\s*img[^>]*[src|data-src]=['"](.*?)['"][^>]*>/gi, + "[Image]($1)\n" + ) /** * Remove remaining tags diff --git a/src/sources/multisrc/madara/MadaraGenerator.js b/src/sources/multisrc/madara/MadaraGenerator.js index 0aa78253..9ff1484e 100644 --- a/src/sources/multisrc/madara/MadaraGenerator.js +++ b/src/sources/multisrc/madara/MadaraGenerator.js @@ -22,6 +22,7 @@ const getPath = (extensionId) => { 62: { novels: "novel", novel: "novel", chapter: "novel" }, 63: { novels: "novel", novel: "novel", chapter: "novel" }, 75: { novels: "series", novel: "series", chapter: "series" }, + 80: { novels: "manga", novel: "manga", chapter: "manga" }, }; return ( diff --git a/src/sources/sources.js b/src/sources/sources.js index ec7d78cd..be00063e 100644 --- a/src/sources/sources.js +++ b/src/sources/sources.js @@ -80,6 +80,7 @@ import TravisTranslationsScraper from "./en/travistranslations"; import NovelDeGlaceScraper from "./fr/noveldeglace"; import RainOfSnowScraper from "./en/rainofsnow"; import ReaperScansBrScraper from "./br/ReaperScansBr"; +import ArthurScansScraper from "./br/ArthurScans"; export const getSource = (sourceId) => { const scrapers = { @@ -161,6 +162,7 @@ export const getSource = (sourceId) => { 77: NovelDeGlaceScraper, 78: RainOfSnowScraper, 79: ReaperScansBrScraper, + 80: ArthurScansScraper, }; return scrapers[sourceId]; diff --git a/src/sources/sources.json b/src/sources/sources.json index 37e79431..f75ab95a 100644 --- a/src/sources/sources.json +++ b/src/sources/sources.json @@ -541,8 +541,15 @@ { "sourceId": 79, "url": "https://reaperscans.com.br/", - "sourceName": "ReaperScans (BR)", + "sourceName": "ReaperScans (Br)", "icon": "https://github.com/LNReader/lnreader-sources/blob/main/src/en/reaperscans/icon.png?raw=true", "lang": "Portuguese (Brazil)" + }, + { + "sourceId": 80, + "url": "https://arthurscan.xyz/", + "sourceName": "ArthurScans (Br)", + "icon": "https://github.com/LNReader/lnreader-sources/blob/main/multisrc/madara/icons/arthurscans.png?raw=true", + "lang": "Portuguese (Brazil)" } ]