feat(source): Add Rain Of Snow

Closes LNReader/lnreader-sources#60
This commit is contained in:
Rajarshee Chatterjee
2021-09-15 10:09:09 +05:30
parent f0cfd9066b
commit e01fc21a49
4 changed files with 149 additions and 4 deletions
+140
View File
@@ -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;
-4
View File
@@ -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;
};
+2
View File
@@ -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];
+7
View File
@@ -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"
}
]