Skip to content

Commit

Permalink
The_Lazy_Guy Dev + TuNovelaLigera Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
K1ngfish3r committed Nov 3, 2023
1 parent 168f982 commit c2d499e
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 41 deletions.
139 changes: 139 additions & 0 deletions src/sources/en/icantreadjapanese.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { fetchHtml } from '@utils/fetch/fetch';
import * as cheerio from 'cheerio';
import { FilterInputs } from '../types/filterTypes';

const sourceId = 170;
const sourceName = 'I cant read japanese tl';

const baseUrl = 'https://icantreadjapanese.wordpress.com/';

const popularNovels = async (page, { filters }) => {
let link = `${baseUrl}`;

if (page === 1) {
link += (filters?.storyStatus ? filters.storyStatus : 'projects') + '/';
}

console.log(link);

const body = await fetchHtml({ url: link, sourceId });

const loadedCheerio = cheerio.load(body);

let novels = [];

loadedCheerio('figure.wp-block-image').each(function () {
const novelName = loadedCheerio(this).find('a').text();
const novelCover = loadedCheerio(this).find('img').attr('src');
const novelUrl = loadedCheerio(this).find('a').attr('href');

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

novels.push(novel);
});

return { novels };
};

const parseNovelAndChapters = async novelUrl => {
const body = await fetchHtml({ url: novelUrl, sourceId: sourceId });

let loadedCheerio = cheerio.load(body);

let novel = {
sourceId,
sourceName,
url: novelUrl,
novelUrl,
};

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

novel.novelCover = loadedCheerio('figure.wp-block-image > img').attr('src');

novel.author = loadedCheerio('.has-text-align-left')
.text()
.replace(/.*Author: (.*) \|.*/g, '$1');

novel.summary = loadedCheerio('.entry-content > p:first')
.nextUntil('hr:first')
.text();

let chapters = [];

loadedCheerio('.wp-block-column li a').each(function () {
let chapterName = loadedCheerio(this).text();
const releaseDate = null;
const chapterUrl = loadedCheerio(this).attr('href');

const volumeName = loadedCheerio(this)
.parent()
.prop('innerHTML')
.replace(/<a.*>/g, '')
.replace(/<br>/g, ' ')
.trim();
if (volumeName.length) {
chapterName = volumeName + ' - ' + chapterName;
}

chapters.push({ chapterName, releaseDate, chapterUrl });
});

novel.chapters = chapters;
return novel;
};

const parseChapter = async (novelUrl, chapterUrl) => {
const body = await fetchHtml({
url: chapterUrl,
sourceId: sourceId,
});

let loadedCheerio = cheerio.load(body);

const chapterName = loadedCheerio('h1.entry-title').text();

const chapterText = loadedCheerio('.entry-content').html();

const chapter = {
sourceId,
novelUrl,
chapterUrl,
chapterName,
chapterText,
};

return chapter;
};

const searchNovels = async () => {
showToast('Search is not implemented for this source');
return;
};

const filters = [
{
key: 'storyStatus',
label: 'Translation Status',
values: [
{ label: 'Ongoing Projects', value: 'projects' },
{
label: 'Maybe Will Read Again, Caught Up',
value: 'maybe-will-read-again-caught-up',
},
{ label: 'Dropped', value: 'dropped' },
{ label: 'Finished', value: 'finished' },
],
inputType: FilterInputs.Picker,
},
];

const ICantReadJPTLScraper = {
popularNovels,
parseNovelAndChapters,
parseChapter,
searchNovels,
filters,
};

export default ICantReadJPTLScraper;
77 changes: 37 additions & 40 deletions src/sources/es/tunovelaligera.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cheerio from 'cheerio';
import { defaultCoverUri, Status } from '../helpers/constants';
import { fetchHtml } from '@utils/fetch/fetch';
import { showToast } from '@hooks/showToast';

const sourceId = 23;
const sourceName = 'TuNovelaLigera';
Expand Down Expand Up @@ -92,59 +93,55 @@ const parseNovelAndChapters = async novelUrl => {

novel.summary = loadedCheerio('div.summary__content > p').text().trim();

let novelChapters = [];

const novelId =
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id');

let formData = new FormData();
formData.append('action', 'manga_get_chapters');
formData.append('manga', novelId);

const text = await fetchHtml({
url: 'https://tunovelaligera.com/wp-admin/admin-ajax.php',
init: {
method: 'POST',
body: formData,
},
});

loadedCheerio = cheerio.load(text);

loadedCheerio('.wp-manga-chapter').each(function () {
const chapterName = loadedCheerio(this)
.find('a')
.text()
.replace(/[\t\n]/g, '')
.trim();

const releaseDate = loadedCheerio(this).find('span').text().trim();

let chapterUrl = loadedCheerio(this).find('a').attr('href').split('/');

chapterUrl[6]
? (chapterUrl = chapterUrl[5] + '/' + chapterUrl[6])
: (chapterUrl = chapterUrl[5]);

novelChapters.push({ chapterName, releaseDate, chapterUrl });
});
const delay = ms => new Promise(res => setTimeout(res, ms));
let lastPage = 1;
lastPage = loadedCheerio('.lcp_paginator li:last').prev().text().trim();

const getChapters = async () => {
let novelChapters = [];
for (let i = 1; i <= lastPage; i++) {
const chaptersUrl = `${baseUrl}novelas/${novelUrl}?lcp_page0=${i}`;
showToast(`Getting Chapters Page ${i}/${lastPage}...`);
const chaptersHtml = await fetchHtml({
url: chaptersUrl,
sourceId,
});

loadedCheerio = cheerio.load(chaptersHtml);
loadedCheerio('.lcp_catlist li').each((i, el) => {
const chapterName = loadedCheerio(el)
.find('a')
.text()
.replace(/[\t\n]/g, '')
.trim();

const releaseDate = loadedCheerio(el).find('span').text().trim();

const chapterUrl = loadedCheerio(el).find('a').attr('href');

novelChapters.push({ chapterName, releaseDate, chapterUrl });
});
await delay(1000);
}
return novelChapters.reverse();
};

novel.chapters = novelChapters.reverse();
novel.chapters = await getChapters();

return novel;
};

const parseChapter = async (novelUrl, chapterUrl) => {
const url = `${baseUrl}novelas/${novelUrl}/${chapterUrl}`;
const url = chapterUrl;

const body = await fetchHtml({ url });

let loadedCheerio = cheerio.load(body);

let chapterName = loadedCheerio('h1#chapter-heading').text();

let chapterText = loadedCheerio('.text-left').html();
loadedCheerio('#hola_siguiente').next().find('div').remove();
let chapterText = loadedCheerio('#hola_siguiente').next().html();
novelUrl = novelUrl + '/';

const chapter = {
Expand Down
2 changes: 2 additions & 0 deletions src/sources/sourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import ScribbleHubScraper from './en/scribblehub';
import SyosetuScraper from './jp/syosetu';
import LNMTLScraper from './en/lnmtl';
import LightNovelFullScraper from './en/lightnovelfull';
import ICantReadJPTLScraper from './en/icantreadjapanese';
import {
AsuraLightNovelScraper,
ArMTLScraper,
Expand Down Expand Up @@ -338,6 +339,7 @@ export const sourceManager = (sourceId: number): Scraper => {
167: SmakolykyTlScraper, // @ts-ignore
168: LitSpaceScraper, // @ts-ignore
169: AsuraLightNovelScraper, // @ts-ignore
170: ICantReadJPTLScraper, // @ts-ignore
};

return scrapers[sourceId];
Expand Down
9 changes: 8 additions & 1 deletion src/sources/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,16 @@
},
{
"sourceId": 169,
"url": "AsuraLightNovelScraper",
"url": "https://asuralightnovel.com/",
"sourceName": "Asura Light Novel",
"icon": "https://asuralightnovel.com/wp-content/uploads/2021/06/favicon-asura-2.png",
"lang": "English"
},
{
"sourceId": 170,
"url": "https://icantreadjapanese.wordpress.com/",
"sourceName": "I Cant Read Japanese TL",
"icon": "https://icantreadjapanese.files.wordpress.com/2021/03/cropped-cropped-site-icon-1.png?w=16",
"lang": "English"
}
]

0 comments on commit c2d499e

Please sign in to comment.