Skip to content

Commit

Permalink
fix: Update Sources (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
K1ngfish3r authored Jun 16, 2023
1 parent c0b4610 commit e66ee5f
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/sources/en/fastnovel.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const parseNovelAndChapters = async novelUrl => {
const novelId = loadedCheerio('#rating').attr('data-novel-id');

const getChapters = async id => {
const chapterListUrl = baseUrl + '/ajax/chapter-option?novelId=' + id;
const chapterListUrl = baseUrl + '/ajax/chapter-archive?novelId=' + id;

const data = await fetch(chapterListUrl);
const chapters = await data.text();
Expand Down
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
Loading

0 comments on commit e66ee5f

Please sign in to comment.