From d5a8ca2b4713ee77758dcae6f478d37b0fe60770 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Sun, 12 Jun 2022 21:15:25 +0530 Subject: [PATCH] feat(source): Add Liebe Schnee Hiver Novel (Closes LNReader/lnreader-sources#232) --- .../wpmangastream/WPMangaStreamGenerator.js | 9 ++++- .../wpmangastream/WPMangaStreamScraper.js | 40 +++++++++---------- src/sources/sourceManager.ts | 6 ++- src/sources/sources.json | 7 ++++ 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/sources/multisrc/wpmangastream/WPMangaStreamGenerator.js b/src/sources/multisrc/wpmangastream/WPMangaStreamGenerator.js index 3554d03c..86713f0b 100644 --- a/src/sources/multisrc/wpmangastream/WPMangaStreamGenerator.js +++ b/src/sources/multisrc/wpmangastream/WPMangaStreamGenerator.js @@ -2,6 +2,13 @@ import WPMangaStreamScraper from './WPMangaStreamScraper'; export const KolNovelScraper = new WPMangaStreamScraper( 53, - 'https://alightnovel.com/', + 'https://kolnovel.com/', 'KolNovel', ); + +export const LiebeSchneeHiverNovelScraper = new WPMangaStreamScraper( + 123, + 'https://lshnovel.com/', + 'Liebe Schnee Hiver Novel', + { totalPages: 1 }, +); diff --git a/src/sources/multisrc/wpmangastream/WPMangaStreamScraper.js b/src/sources/multisrc/wpmangastream/WPMangaStreamScraper.js index 55384109..21f152a6 100644 --- a/src/sources/multisrc/wpmangastream/WPMangaStreamScraper.js +++ b/src/sources/multisrc/wpmangastream/WPMangaStreamScraper.js @@ -1,13 +1,15 @@ import * as cheerio from 'cheerio'; class WPMangaStreamScraper { - constructor(sourceId, baseUrl, sourceName) { + constructor(sourceId, baseUrl, sourceName, options) { this.sourceId = sourceId; this.baseUrl = baseUrl; this.sourceName = sourceName; + this.language = options?.language; + this.totalPages = options?.totalPages; } async popularNovels(page) { - let totalPages = 100; + let totalPages = this.totalPages; let url = this.baseUrl + 'series/?page=' + page + '&status=&order=popular'; let sourceId = this.sourceId; @@ -23,7 +25,7 @@ class WPMangaStreamScraper { let image = loadedCheerio(this).find('img'); const novelCover = image.attr('src'); - let novelUrl = loadedCheerio(this).find('a').attr('href').split('/')[4]; + const novelUrl = loadedCheerio(this).find('a').attr('href'); const novel = { sourceId, @@ -39,7 +41,7 @@ class WPMangaStreamScraper { } async parseNovelAndChapters(novelUrl) { - const url = `${this.baseUrl}series/${novelUrl}/`; + const url = novelUrl; const result = await fetch(url); const body = await result.text(); @@ -64,19 +66,20 @@ class WPMangaStreamScraper { const detailName = loadedCheerio(this).find('b').text().trim(); const detail = loadedCheerio(this).find('b').next().text().trim(); - if (loadedCheerio(this).text().includes('الحالة:')) { - novel.status = loadedCheerio(this).text().replace('الحالة: ', ''); - } - switch (detailName) { case 'المؤلف:': - novel.auhtor = detail; + case 'Yazar:': + novel.author = detail; + break; + case 'Seviye:': + novel.status = detail; + break; + case 'Tür:': + novel.genre = detail?.replace(/\s/g, ','); break; } }); - novel.genre = loadedCheerio('.genxed').text().replace(/\s/g, ','); - novel.summary = loadedCheerio('div[itemprop="description"]').text().trim(); let novelChapters = []; @@ -91,15 +94,12 @@ class WPMangaStreamScraper { const releaseDate = loadedCheerio(this).find('.epl-date').text().trim(); - const chapterUrl = loadedCheerio(this) - .find('a') - .attr('href') - .split('/')[3]; + const chapterUrl = loadedCheerio(this).find('a').attr('href'); novelChapters.push({ chapterName, releaseDate, chapterUrl }); }); - novel.chapters = novelChapters.reverse(); + novel.chapters = novelChapters; return novel; } @@ -107,7 +107,7 @@ class WPMangaStreamScraper { async parseChapter(novelUrl, chapterUrl) { let sourceId = this.sourceId; - const url = `${this.baseUrl}${chapterUrl}`; + const url = chapterUrl; const result = await fetch(url); const body = await result.text(); @@ -141,10 +141,8 @@ class WPMangaStreamScraper { loadedCheerio('article.bs').each(function () { const novelName = loadedCheerio(this).find('.ntitle').text().trim(); - let image = loadedCheerio(this).find('img'); - const novelCover = image.attr('src'); - - let novelUrl = loadedCheerio(this).find('a').attr('href').split('/')[4]; + const novelCover = loadedCheerio(this).find('img').attr('src'); + const novelUrl = loadedCheerio(this).find('a').attr('href'); const novel = { sourceId, diff --git a/src/sources/sourceManager.ts b/src/sources/sourceManager.ts index 7941e8ac..f49f6003 100644 --- a/src/sources/sourceManager.ts +++ b/src/sources/sourceManager.ts @@ -73,7 +73,10 @@ import WuxiaCityScraper from './en/wuxiacity'; import NovelUpdatesScraper from './en/novelupdates'; import RanobesScraper from './en/ranobes'; import YushuboScraper from './ch/yushubo'; -import { KolNovelScraper } from './multisrc/wpmangastream/WPMangaStreamGenerator'; +import { + KolNovelScraper, + LiebeSchneeHiverNovelScraper, +} from './multisrc/wpmangastream/WPMangaStreamGenerator'; import WLNUpdatesScraper from './en/wlnupdates'; import ReaperScansScraper from './en/reaperscans'; import JaomixScraper from './ru/jaomix'; @@ -266,6 +269,7 @@ export const sourceManager = (sourceId: number): Scraper => { 120: MTNovelScraper, 121: SonicMTLScraper, 122: MTLNovelDotClubScraper, + 123: LiebeSchneeHiverNovelScraper, }; return scrapers[sourceId]; diff --git a/src/sources/sources.json b/src/sources/sources.json index 4b5e3a8d..eac11b19 100644 --- a/src/sources/sources.json +++ b/src/sources/sources.json @@ -817,5 +817,12 @@ "icon": "https://github.com/LNReader/lnreader-sources/blob/master/icons/multisrc/madara/icons/mtlnovel.club.png?raw=true", "url": "https://mtlnovel.club/", "lang": "English" + }, + { + "sourceId": 123, + "sourceName": "Liebe Schnee Hiver Novel", + "url": "https://lshnovel.com/", + "icon": "https://github.com/LNReader/lnreader-sources/blob/master/icons/multisrc/wpmangastream/icons/lshnovel.png?raw=true", + "lang": "Turkish" } ]