diff --git a/src/sources/en/rainofsnow.js b/src/sources/en/rainofsnow.js new file mode 100644 index 00000000..aa2576fd --- /dev/null +++ b/src/sources/en/rainofsnow.js @@ -0,0 +1,140 @@ +import cheerio from "react-native-cheerio"; +import { Status } from "../helpers/constants"; + +const sourceId = 78; + +const sourceName = "RainOfSnow"; + +const baseUrl = "https://rainofsnow.com/"; + +const popularNovels = async (page) => { + let url = baseUrl + "novels/page/" + page; + + const totalPages = 5; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".minbox").each(function () { + const novelName = $(this).find("h3").text(); + const novelCover = $(this).find("img").attr("data-src"); + const novelUrl = $(this).find("h3 > a").attr("href"); + + const novel = { + sourceId, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + return { novels, totalPages }; +}; + +const parseNovelAndChapters = async (novelUrl) => { + const url = novelUrl; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novel = { sourceId, sourceName, url, novelUrl }; + + novel.novelName = $("h2").text().trim(); + + novel.novelCover = $(".imagboca1 > img").attr("data-src"); + + novel.summary = $("#synop").text().trim(); + + novel.genre = $( + "body > div.queen > div > div > div.row > div.col-md-12.col-lg-7 > div > div.backcolor1 > ul > li:nth-child(5) > small" + ) + .text() + .trim(); + + novel.author = $( + "body > div.queen > div > div > div.row > div.col-md-12.col-lg-7 > div > div.backcolor1 > ul > li:nth-child(2) > small" + ).text(); + + novel.status = Status.UNKNOWN; + + let novelChapters = []; + + $("#chapter") + .find("li") + .each(function () { + const chapterName = $(this).find(".chapter").first().text().trim(); + const releaseDate = $(this).find("small").text(); + const chapterUrl = $(this).find("a").attr("href"); + + novelChapters.push({ chapterName, releaseDate, chapterUrl }); + }); + + novel.chapters = novelChapters; + + return novel; +}; + +const parseChapter = async (novelUrl, chapterUrl) => { + const result = await fetch(chapterUrl); + const body = await result.text(); + + $ = cheerio.load(body); + + let chapterName = $(".content > h2").text(); + let chapterText = $(".content").html(); + + const chapter = { + sourceId, + novelUrl, + chapterUrl, + chapterName, + chapterText, + }; + + return chapter; +}; + +const searchNovels = async (searchTerm) => { + let url = baseUrl + "?s=" + searchTerm; + + const result = await fetch(url); + const body = await result.text(); + + $ = cheerio.load(body); + + let novels = []; + + $(".minbox").each(function () { + const novelName = $(this).find("h3").text(); + const novelCover = $(this).find("img").attr("data-src"); + const novelUrl = $(this).find("h3 > a").attr("href"); + + const novel = { + sourceId, + novelName, + novelCover, + novelUrl, + }; + + novels.push(novel); + }); + + return novels; +}; + +const RainOfSnowScraper = { + popularNovels, + parseNovelAndChapters, + parseChapter, + searchNovels, +}; + +export default RainOfSnowScraper; diff --git a/src/sources/fr/noveldeglace.js b/src/sources/fr/noveldeglace.js index 33f5d638..a733fb22 100644 --- a/src/sources/fr/noveldeglace.js +++ b/src/sources/fr/noveldeglace.js @@ -84,8 +84,6 @@ const parseNovelAndChapters = async (novelUrl) => { novel.chapters = novelChapters; - console.log(novel); - return novel; }; @@ -140,8 +138,6 @@ const searchNovels = async (searchTerm) => { novel.novelName.toLowerCase().includes(searchTerm.toLowerCase()) ); - console.log(novels); - return novels; }; diff --git a/src/sources/sources.js b/src/sources/sources.js index 3082df02..1988c835 100644 --- a/src/sources/sources.js +++ b/src/sources/sources.js @@ -78,6 +78,7 @@ import LightNovelUpdatesScraper from "./en/lightnovelupdates"; import EpikNovelScraper from "./tr/epiknovel"; import TravisTranslationsScraper from "./en/travistranslations"; import NovelDeGlaceScraper from "./fr/noveldeglace"; +import RainOfSnowScraper from "./en/rainofsnow"; export const getSource = (sourceId) => { const scrapers = { @@ -157,6 +158,7 @@ export const getSource = (sourceId) => { 75: MysticalSeriesScraper, 76: TravisTranslationsScraper, 77: NovelDeGlaceScraper, + 78: RainOfSnowScraper, }; return scrapers[sourceId]; diff --git a/src/sources/sources.json b/src/sources/sources.json index d719b5dd..5fa85fa8 100644 --- a/src/sources/sources.json +++ b/src/sources/sources.json @@ -530,5 +530,12 @@ "sourceName": "NovelDeGlace", "icon": "https://github.com/LNReader/lnreader-sources/blob/main/src/fr/noveldeglace/icon.png?raw=true", "lang": "French" + }, + { + "sourceId": 78, + "url": "https://rainofsnow.com/", + "sourceName": "RainOfSnow", + "icon": "https://github.com/LNReader/lnreader-sources/blob/main/src/en/rainofsnow/icon.png?raw=true", + "lang": "French" } ]