From 09bcbd58f5563363f8f09d0d7f7765bb7a603350 Mon Sep 17 00:00:00 2001 From: Rider21 <58046032+Rider21@users.noreply.github.com> Date: Sat, 9 Apr 2022 17:19:27 +0300 Subject: [PATCH] feat(source): Add Renovels (#224) --- src/sources/ru/renovels.js | 96 ++++++++++++++++++++++++++++++++++++ src/sources/sourceManager.ts | 4 +- src/sources/sources.json | 7 +++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/sources/ru/renovels.js diff --git a/src/sources/ru/renovels.js b/src/sources/ru/renovels.js new file mode 100644 index 00000000..575b02a7 --- /dev/null +++ b/src/sources/ru/renovels.js @@ -0,0 +1,96 @@ +const sourceId = 116; +const sourceName = 'Renovels'; + +const baseUrl = 'https://renovels.org/'; + +const popularNovels = async page => { + const totalPages = 20; + const url = 'https://api.renovels.org/api/titles/last-chapters/?&count=20&page=' + page; + const result = await fetch(url); + let body = await result.json(); + + let novels = []; + + body.content.map(item => { + const novelName = item.rus_name; + const novelCover = 'https://api.renovels.org' + item.img.mid; + const novelUrl = item.dir; + const novel = { sourceId, novelName, novelCover, novelUrl }; + novels.push(novel); + }); + + return { totalPages, novels }; +}; + +const parseNovelAndChapters = async novelUrl => { + const result = await fetch('https://api.renovels.org/api/titles/' + novelUrl); + let body = await result.json(); + + let novel = { + sourceId, + sourceName, + url: baseUrl + 'novel/' + body.content.dir, + novelName: body.content.rus_name, + novelCover: 'https://api.renovels.org' + body.content.img.high, + summary: body.content.description, + novelUrl, + }; + + const chapterResult = await fetch(`https://api.renovels.org/api/titles/chapters/?branch_id=${body.content.id}&count=100&page=1`); + let volumes = await chapterResult.json(); + let chapters = []; + + volumes.content.map(item => { + const chapterName = + `Том ${item.tome} Глава ${item.chapter} ${item.name}`?.trim(); + const releaseDate = item.upload_date; + const chapterUrl = 'https://api.renovels.org/api/titles/chapters/' + item.branches[0].id + '/'; + + chapters.push({ chapterName, releaseDate, chapterUrl }); + }); + + novel.chapters = chapters; + + return novel; +}; + +const parseChapter = async (novelUrl, chapterUrl) => { + const result = await fetch(chapterUrl); + const body = await result.json(); + + const chapter = { + sourceId, + novelUrl, + chapterUrl, + chapterName: body.content.name || body.content.chapter, + chapterText: body.content.content, + }; + + return chapter; +}; + +const searchNovels = async searchTerm => { + const url = `https://api.renovels.org/api/search/?query=${searchTerm}&count=100&field=titles`; + const result = await fetch(url); + let body = await result.json(); + let novels = []; + + body.content.map(item => { + const novelName = item.rus_name; + const novelCover = 'https://api.renovels.org' + item.img.mid; + const novelUrl = item.dir; + const novel = { sourceId, novelName, novelCover, novelUrl }; + novels.push(novel); + }); + + return novels; +}; + +const RanobeLibScraper = { + popularNovels, + parseNovelAndChapters, + parseChapter, + searchNovels, +}; + +export default RanobeLibScraper; \ No newline at end of file diff --git a/src/sources/sourceManager.ts b/src/sources/sourceManager.ts index 3861b9b9..1934a98e 100644 --- a/src/sources/sourceManager.ts +++ b/src/sources/sourceManager.ts @@ -75,6 +75,8 @@ import { KolNovelScraper } from './multisrc/wpmangastream/WPMangaStreamGenerator import WLNUpdatesScraper from './en/wlnupdates'; import ReaperScansScraper from './en/reaperscans'; import RanobeHubScraper from './ru/ranobehub'; +import RanobeLibScraper from './ru/ranobelib'; +import RenovelsScraper from './ru/renovels'; import ArNovelScraper from './ar/arnovel'; import DivineDaoLibraryScraper from './en/divinedaolibrary'; import NovelOnlineFullScraper from './en/novelonlinefull'; @@ -97,7 +99,6 @@ import RewayatArScraper from './ar/rewayatar'; import MTLCornerScraper from './en/mtlcorner'; import NitroScansScraper from './en/nitroscans'; import NovelForestScraper from './en/novelforest'; -import RanobeLibScraper from './ru/ranobelib'; import NovelPubScraper from './en/novelpub'; import BestLightNovel from './en/bestlightnovel'; import NovelFullMeScraper from './en/NovelFullMe'; @@ -244,6 +245,7 @@ export const sourceManager = (sourceId: number): Scraper => { 113: NovelsCafeScraper, 114: LightNovelReaderScraper, 115: HakoLightNovelScraper, + 116: RenovelsScraper, }; return scrapers[sourceId]; diff --git a/src/sources/sources.json b/src/sources/sources.json index b56ece43..217f2517 100644 --- a/src/sources/sources.json +++ b/src/sources/sources.json @@ -775,5 +775,12 @@ "icon": "https://github.com/LNReader/lnreader-sources/blob/main/src/vi/hakolightnovel/icon.png?raw=true", "url": "https://ln.hako.re", "lang": "Vietnamese" + }, + { + "sourceId": 116, + "sourceName": "Renovels", + "url": "https://renovels.org", + "lang": "Russian", + "icon": "https://github.com/LNReader/lnreader-sources/blob/main/src/ru/renovels/icon.png?raw=true" } ]