Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for sources #657

Merged
merged 7 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/sources/en/foxaholic.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ const parseNovelAndChapters = async novelUrl => {
}
});

loadedCheerio('.description-summary > div.summary__content')
.find('em')
.remove();

loadedCheerio('.description-summary > div.summary__content em').remove();
novel.summary = loadedCheerio('.description-summary > div.summary__content')
.text()
.trim();
Expand Down
13 changes: 11 additions & 2 deletions src/sources/en/lightnovelpub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchHtml } from '@utils/fetch/fetch';
import { fetchApi, fetchHtml } from '@utils/fetch/fetch';
import * as cheerio from 'cheerio';
const sourceId = 15;
const baseUrl = 'https://www.lightnovelpub.com/';
Expand Down Expand Up @@ -156,13 +156,22 @@ const parseChapter = async (novelUrl, chapterUrl) => {

const searchNovels = async searchTerm => {
const url = `${baseUrl}lnsearchlive`;
const link = `${baseUrl}search`;
const response = await fetchApi({ url: link, sourceId }).then(r => r.text());
const token = cheerio.load(response);
let verifytoken = token('#novelSearchForm > input').attr('value');

let formData = new FormData();
formData.append('inputContent', searchTerm);

const body = await fetchHtml({
url,
init: { method: 'POST', headers, body: formData },
init: {
method: 'POST',
headers: { 'LNRequestVerifyToken': verifytoken },
body: formData,
},
sourceId,
});

let loadedCheerio = cheerio.load(body);
Expand Down
19 changes: 15 additions & 4 deletions src/sources/en/novelupdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function getLocation(href) {
const parseChapter = async (novelUrl, chapterUrl) => {
const url = chapterUrl;

// console.log("Original URL: ", url);
// console.log('Original URL: ', url);

let result, body;

Expand All @@ -192,7 +192,7 @@ const parseChapter = async (novelUrl, chapterUrl) => {

// console.log(result.url);

// console.log("Redirected URL: ", result.url);
// console.log('Redirected URL: ', result.url);

const loadedCheerio = cheerio.load(body);

Expand All @@ -204,12 +204,20 @@ const parseChapter = async (novelUrl, chapterUrl) => {

let isWattpad = result.url.toLowerCase().includes('wattpad');

let isLightNovelsTls = result.url
.toLowerCase()
.includes('lightnovelstranslations');

let isiNovelTranslation = result.url
.toLowerCase()
.includes('inoveltranslation');

let isTravisTranslation = result.url
.toLowerCase()
.includes('travistranslations');

/**
* Checks if its a wwordpress site
* Checks if its a wordpress site
*/
let isWordPress =
loadedCheerio('meta[name="generator"]').attr('content') ||
Expand Down Expand Up @@ -238,7 +246,6 @@ const parseChapter = async (novelUrl, chapterUrl) => {
chapterText = loadedCheerio('.post').html();
} else if (isBlogspot) {
loadedCheerio('.post-share-buttons').remove();

chapterText = loadedCheerio('.entry-content').html();
} else if (isHostedNovel) {
chapterText = loadedCheerio('.chapter').html();
Expand All @@ -248,6 +255,10 @@ const parseChapter = async (novelUrl, chapterUrl) => {
chapterText = loadedCheerio('.container pre').html();
} else if (isTravisTranslation) {
chapterText = loadedCheerio('.reader-content').html();
} else if (isLightNovelsTls) {
chapterText = loadedCheerio('.text_story').html();
} else if (isiNovelTranslation) {
chapterText = loadedCheerio('.chakra-skeleton').html();
} else if (isWordPress) {
/**
* Remove wordpress bloat tags
Expand Down
113 changes: 62 additions & 51 deletions src/sources/id/indowebnovel.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import * as cheerio from 'cheerio';
import { fetchHtml } from '@utils/fetch/fetch';

const sourceId = 87;
const sourceName = 'IndoWebNovel';

const baseUrl = 'http://indowebnovel.id/';

const popularNovels = async page => {
const url = `${baseUrl}daftar-novel/`;
const url = `${baseUrl}id/advanced-search/page/${page}/?title=&author=&yearx=&status=&type=&order=title&country[]=china&country[]=jepang&country[]=korea&country[]=unknown`;

const result = await fetch(url);
const body = await result.text();
const body = await fetchHtml({ url, sourceId });

const loadedCheerio = cheerio.load(body);

let novels = [];

loadedCheerio('.novellist-blc li').each(function () {
const novelName = loadedCheerio(this).find('a').text();
const novelCover = null;
const novelUrl = loadedCheerio(this).find('a').attr('href');
loadedCheerio('.flexbox2-item').each(function () {
const novelName = loadedCheerio(this)
.find('.flexbox2-title span')
.first()
.text();
const novelCover = loadedCheerio(this).find('img').attr('src');
const novelUrl = loadedCheerio(this)
.find('.flexbox2-content > a')
.attr('href');

const novel = {
sourceId,
Expand All @@ -34,48 +39,60 @@ const popularNovels = async page => {
};

const parseNovelAndChapters = async novelUrl => {
const url = novelUrl;

const result = await fetch(url);
const body = await result.text();
const body = await fetchHtml({ url: novelUrl, sourceId });

let loadedCheerio = cheerio.load(body);

let novel = {
sourceId,
sourceName,
url,
url: novelUrl,
novelUrl,
novelName: '',
novelCover: '',
author: '',
status: '',
genre: '',
summary: '',
chapters: [],
};

novel.novelName = loadedCheerio('.series-title').text().trim();
novel.novelName = loadedCheerio('.series-title h2').text().trim();

novel.novelCover = loadedCheerio('.series-thumb > img').attr('src');
novel.novelCover = loadedCheerio('.series-thumb img').attr('src');

novel.summary = loadedCheerio('.series-synops').text().trim();
loadedCheerio('.series-infolist > li').each(function () {
const detailName = loadedCheerio(this).find('b').text().trim();
const detail = loadedCheerio(this).find('b').next().text().trim();

novel.status = loadedCheerio('.status').text().trim();
switch (detailName) {
case 'Author':
novel.author = detail;
break;
}
});

novel.genre = [];
novel.status = loadedCheerio('.status').text().trim();

loadedCheerio('.series-genres').each(function () {
novel.genre.push(loadedCheerio(this).find('a').text().trim());
});
novel.genre = loadedCheerio('.series-genres')
.children('a')
.map((i, el) => loadedCheerio(el).text())
.toArray()
.join(',');

novel.genre = novel.genre.toString();
loadedCheerio('.series-synops div').remove();
novel.summary = loadedCheerio('.series-synops').text().trim();

let chapters = [];

loadedCheerio('.series-chapterlist li').each(function () {
const chapterName = loadedCheerio(this).find('a').text().trim();
const releaseDate = null;
const chapterName = loadedCheerio(this)
.find('a span')
.first()
.text()
.replace(/.*?(Chapter.|[0-9])/g, '$1')
.replace(/Bahasa Indonesia/g, '')
.replace(/\s+/g, ' ')
.trim();

const releaseDate = loadedCheerio(this)
.find('a span')
.first()
.next()
.text();
const chapterUrl = loadedCheerio(this).find('a').attr('href');

chapters.push({ chapterName, releaseDate, chapterUrl });
Expand All @@ -87,10 +104,7 @@ const parseNovelAndChapters = async novelUrl => {
};

const parseChapter = async (novelUrl, chapterUrl) => {
const url = chapterUrl;

const result = await fetch(url);
const body = await result.text();
const body = await fetchHtml({ url: chapterUrl, sourceId });

let loadedCheerio = cheerio.load(body);

Expand All @@ -109,30 +123,27 @@ const parseChapter = async (novelUrl, chapterUrl) => {
};

const searchNovels = async searchTerm => {
const url = `${baseUrl}daftar-novel/`;
const url = `${baseUrl}id/?s=${searchTerm}`;

const result = await fetch(url);
const body = await result.text();
const body = await fetchHtml({ url, sourceId });

const loadedCheerio = cheerio.load(body);
let loadedCheerio = cheerio.load(body);

let novels = [];

loadedCheerio('.novellist-blc li').each(function () {
const novelName = loadedCheerio(this).find('a').text();
const novelCover = null;
const novelUrl = loadedCheerio(this).find('a').attr('href');
loadedCheerio('.flexbox2-item').each(function () {
const novelName = loadedCheerio(this)
.find('.flexbox2-title span')
.first()
.text();
const novelCover = loadedCheerio(this).find('img').attr('src');
const novelUrl = loadedCheerio(this)
.find('.flexbox2-content > a')
.attr('href');

const novel = {
sourceId,
novelName,
novelCover,
novelUrl,
};
const novel = { sourceId, novelName, novelCover, novelUrl };

if (novelName.toLowerCase().includes(searchTerm.toLowerCase())) {
novels.push(novel);
}
novels.push(novel);
});

return novels;
Expand Down
12 changes: 7 additions & 5 deletions src/sources/id/sakuranovel.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ const parseNovelAndChapters = async novelUrl => {
novel.status = loadedCheerio('.status').text().trim();

novel.genre = loadedCheerio('.series-genres')
.prop('innerHTML')
.replace(/<.*?>(.*?)<.*?>/g, '$1,')
.slice(0, -1);
.children('a')
.map((i, el) => loadedCheerio(el).text())
.toArray()
.join(',');

loadedCheerio('.series-synops div').remove();
novel.summary = loadedCheerio('.series-synops').text().trim();

let chapters = [];
Expand All @@ -76,8 +78,8 @@ const parseNovelAndChapters = async novelUrl => {
.find('a span')
.first()
.text()
.replace(`${novel.novelName} – `, '')
.replace('Bahasa Indonesia', '')
.replace(/.*?(Chapter.|[0-9])/g, '$1')
.replace(/Bahasa Indonesia/g, '')
.replace(/\s+/g, ' ')
.trim();

Expand Down
18 changes: 12 additions & 6 deletions src/sources/multisrc/madara/MadaraScraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,15 @@ class MadaraScraper {

loadedCheerio('.manga-title-badges').remove();

novel.novelName = loadedCheerio('.post-title > h1').text().trim();
novel.novelName = loadedCheerio('.post-title h1').text().trim();

novel.novelCover =
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCoverUri;

loadedCheerio('.post-content_item').each(function () {
const detailName = loadedCheerio(this)
.find('.summary-heading > h5')
.text()
.trim();
loadedCheerio('.post-content_item', '.post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();

switch (detailName) {
Expand All @@ -109,6 +106,7 @@ class MadaraScraper {
}
});

loadedCheerio('div.summary__content .code-block').remove();
novel.summary = loadedCheerio('div.summary__content').text().trim();

let novelChapters = [];
Expand Down Expand Up @@ -193,6 +191,14 @@ class MadaraScraper {
loadedCheerio('.text-center').text() ||
loadedCheerio('#chapter-heading').text();

if (loadedCheerio('.text-right')) {
loadedCheerio('.text-right div').remove();
} else if (loadedCheerio('.text-left')) {
loadedCheerio('.text-left div').remove();
} else if (loadedCheerio('.entry-content')) {
loadedCheerio('.entry-content div').remove();
}

let chapterText =
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
Expand Down
19 changes: 6 additions & 13 deletions src/sources/multisrc/wpmangastream/WPMangaStreamScraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ class WPMangaStreamScraper {

loadedCheerio('div.spe > span').each(function () {
const detailName = loadedCheerio(this).find('b').text().trim();
const detail = loadedCheerio(this).find('b').next().text().trim();
const status = loadedCheerio(this)
.children('b') //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text()
.trim();
const detail = loadedCheerio(this).find('b').remove().end().text().trim();

switch (detailName) {
case 'المؤلف:':
Expand All @@ -81,20 +75,19 @@ class WPMangaStreamScraper {
break;
case 'Status:':
case 'Seviye:':
novel.status = status;
novel.status = detail;
break;
}
});

novel.genre = loadedCheerio('.genxed').text().trim().replace(/\s/g, ',');

loadedCheerio('div[itemprop="description"] h3,p.a,strong').remove();
novel.summary = loadedCheerio('div[itemprop="description"]')
.find('h3 , p.a')
.remove()
.find('br')
.replaceWith('\n')
.end()
.prop('innerHTML')
.replace(/(<.*?>)/g, ' ')
.replace(/(&.*;)/g, '\n');
.text();

let novelChapters = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const KolNovelScraper = new WQMangaStreamScraper(
53,
'https://kolnovel.com/',
'KolNovel',
{ reverseChapters: true, ignoredStrings: true },
K1ngfish3r marked this conversation as resolved.
Show resolved Hide resolved
);
Loading