Skip to content

Commit

Permalink
Merge branch 'LNReader:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
K1ngfish3r authored Jun 24, 2024
2 parents 35e9469 + cd660fb commit 8cf08b2
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 48 deletions.
45 changes: 15 additions & 30 deletions src/sources/en/readlightnovel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { FilterInputs, SourceFilter } from '../types/filterTypes';

const sourceId = 2;
const sourceName = 'ReadLightNovel';
const baseUrl = 'https://www.readlightnovel.me';
const searchUrl = 'https://www.readlightnovel.me/detailed-search-210922';
const baseUrl = 'https://www.readlightnovel.today';
const searchUrl = 'https://www.readlightnovel.today/detailed-search-210922';

const popularNovels = async (page: number, options?: SourceOptions) => {
const url = `${baseUrl}/${
Expand Down Expand Up @@ -91,37 +91,22 @@ const parseNovelAndChapters = async (novelUrl: string) => {
}
});

let chapters: SourceChapterItem[] = [];
const chapters: SourceChapterItem[] = [];

loadedCheerio('.panel').each(function () {
let volumeName = loadedCheerio(this).find('h4.panel-title').text();

loadedCheerio(this)
.find('ul.chapter-chs > li')
.each(function () {
const chapterUrl = loadedCheerio(this)
.find('a')
.attr('href')
?.replace(`${baseUrl}/${novelUrl}/`, '');

if (chapterUrl) {
let chapterName = loadedCheerio(this).find('a').text();

const releaseDate = null;

if (volumeName.includes('Volume')) {
chapterName = volumeName + ' ' + chapterName;
}
loadedCheerio('ul.chapter-chs > li > a').each(function () {
const chapterUrl = loadedCheerio(this)
.attr('href')
?.replace?.(`${baseUrl}/${novelUrl}/`, '');

const chapter = {
chapterName,
releaseDate,
chapterUrl,
};
if (chapterUrl) {
const chapterName = loadedCheerio(this).text();

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

novel = {
Expand Down Expand Up @@ -172,7 +157,7 @@ const parseChapter = async (novelUrl: string, chapterUrl: string) => {
const chapterText = loadedCheerio('.desc').html() || '';

const chapter: SourceChapter = {
sourceId: 2,
sourceId,
novelUrl,
chapterUrl,
chapterName,
Expand Down
55 changes: 44 additions & 11 deletions src/sources/multisrc/ifreedom/IfreedomScraper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Status } from '../../helpers/constants';
import * as cheerio from 'cheerio';
import dayjs from 'dayjs';

class IfreedomScraper {
constructor(sourceId, baseUrl, sourceName, filters) {
Expand All @@ -17,15 +18,12 @@ class IfreedomScraper {
? 'По дате обновления'
: filters?.sort || 'По рейтингу');

if (filters?.status?.length) {
url += filters.status.map(i => '&status[]=' + i).join('');
}
if (filters?.lang?.length) {
url += filters.lang.map(i => '&lang[]=' + i).join('');
}
if (filters?.genre?.length) {
url += filters.genre.map(i => '&genre[]=' + i).join('');
}
Object.entries(filters || {}).forEach(([type, value]) => {
if (value instanceof Array && value.length) {
url += '&' + type + '[]=' + value.join('&' + type + '[]=');
}
});

url += '&bpage=' + page;

const body = await fetch(url).then(res => res.text());
Expand Down Expand Up @@ -95,12 +93,16 @@ class IfreedomScraper {
chapterName &&
chapterUrl
) {
const releaseDate = loadedCheerio(this)
const releaseTime = loadedCheerio(this)
.find('div.li-col2-ranobe')
.text()
.trim();

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

Expand Down Expand Up @@ -154,4 +156,35 @@ class IfreedomScraper {
}
}

function parseDate(dateString = '') {
const months = {
января: 1,
февраля: 2,
марта: 3,
апреля: 4,
мая: 5,
июня: 6,
июля: 7,
августа: 8,
сентября: 9,
октября: 10,
ноября: 11,
декабря: 12,
};

if (dateString.includes('.')) {
const [day, month, year] = dateString.split('.');
if (day && month && year) {
return dayjs(year + '-' + month + '-' + day).format('LL');
}
} else if (dateString.includes(' ')) {
const [day, month] = dateString.split(' ');
if (day && months[month]) {
const year = new Date().getFullYear();
return dayjs(year + '-' + months[month] + '-' + day).format('LL');
}
}
return dateString;
}

export default IfreedomScraper;
35 changes: 32 additions & 3 deletions src/sources/multisrc/rulate/RulateScraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FilterInputs } from '../../types/filterTypes';
import { htmlToText } from '../../helpers/htmlToText';
import { Status } from '../../helpers/constants';
import * as cheerio from 'cheerio';
import dayjs from 'dayjs';

class RulateScraper {
constructor(sourceId, baseUrl, sourceName, filter) {
Expand Down Expand Up @@ -204,7 +205,7 @@ class RulateScraper {
.find('td[class="t"] > a')
.text()
.trim();
const releaseDate = loadedCheerio(this)
const releaseTime = loadedCheerio(this)
.find('td > span')
.attr('title')
?.trim();
Expand All @@ -214,9 +215,13 @@ class RulateScraper {

if (
!loadedCheerio(this).find('td > span[class="disabled"]').length &&
releaseDate
releaseTime
) {
chapters.push({ chapterName, releaseDate, chapterUrl });
chapters.push({
chapterName,
releaseDate: parseDate(releaseTime),
chapterUrl,
});
}
});

Expand Down Expand Up @@ -287,4 +292,28 @@ class RulateScraper {
}
}

function parseDate(dateString = '') {
const months = {
'янв.': 1,
'февр.': 2,
'мар.': 3,
'апр.': 4,
мая: 5,
'июн.': 6,
'июл.': 7,
'авг.': 8,
'сент.': 9,
'окт.': 10,
'нояб.': 11,
'дек.': 12,
};
const [day, month, year, , time] = dateString.split(' ');
if (day && months[month] && year && time) {
return dayjs(year + '-' + months[month] + '-' + day + ' ' + time).format(
'LLL',
);
}
return dateString;
}

export default RulateScraper;
2 changes: 1 addition & 1 deletion src/sources/ru/bookriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const parseNovelAndChapters = async novelUrl => {
chapters.push({
chapterName: chapter.name,
releaseDate: dayjs(
chapter?.firstPublishedAt || chapter.createdAt,
chapter.firstPublishedAt || chapter.createdAt || undefined,
).format('LLL'),
chapterUrl: baseUrl + '/reader/' + book.slug + '/' + chapter.chapterId,
});
Expand Down
32 changes: 30 additions & 2 deletions src/sources/ru/freedlit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dayjs from 'dayjs';
import * as cheerio from 'cheerio';
import { FilterInputs } from '../types/filterTypes';
import {
Expand Down Expand Up @@ -67,10 +68,14 @@ const parseNovelAndChapters = async novelUrl => {

loadedCheerio('a.chapter-line').each(function () {
const chapterName = loadedCheerio(this).find('h6').text();
const releaseDate = loadedCheerio(this).find('span[class="date"]').text();
const chapterUrl = loadedCheerio(this).attr('href');
if (chapterName && chapterUrl) {
chapters.push({ chapterName, releaseDate, chapterUrl });
const releaseTime = loadedCheerio(this).find('span[class="date"]').text();
chapters.push({
chapterName,
releaseDate: parseDate(releaseTime),
chapterUrl,
});
}
});

Expand Down Expand Up @@ -249,4 +254,27 @@ const LitSpaceScraper = {
filters,
};

function parseDate(dateString = '') {
const months = {
января: 1,
февраля: 2,
марта: 3,
апреля: 4,
мая: 5,
июня: 6,
июля: 7,
августа: 8,
сентября: 9,
октября: 10,
ноября: 11,
декабря: 12,
};

const [day, month, year] = dateString.split(' ');
if (day && months[month] && year) {
return dayjs(year + '-' + months[month] + '-' + day).format('LL');
}
return dateString;
}

export default LitSpaceScraper;
29 changes: 28 additions & 1 deletion src/sources/ru/jaomix.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dayjs from 'dayjs';
import * as cheerio from 'cheerio';
import { Status } from '../helpers/constants';
import { FilterInputs } from '../types/filterTypes';
Expand Down Expand Up @@ -88,7 +89,7 @@ const parseNovelAndChapters = async novelUrl => {
loadedCheerio('.download-chapter div.title').each(function () {
chapters.push({
chapterName: loadedCheerio(this).find('a').attr('title'),
releaseDate: loadedCheerio(this).find('time').text(),
releaseDate: parseDate(loadedCheerio(this).find('time').text()),
chapterUrl: loadedCheerio(this).find('a').attr('href'),
});
});
Expand Down Expand Up @@ -314,4 +315,30 @@ const JaomixScraper = {
filters,
};

function parseDate(dateString = '') {
const months = {
Янв: 1,
Фев: 2,
Мар: 3,
Апр: 4,
Май: 5,
Июн: 6,
Июл: 7,
Авг: 8,
Сен: 9,
Окт: 10,
Ноя: 11,
Дек: 12,
};

const [time, day, month, year] = dateString.split(' ');
if (time && day && months[month] && year) {
return dayjs(year + '-' + months[month] + '-' + day + ' ' + time).format(
'LLL',
);
}

return dateString;
}

export default JaomixScraper;

0 comments on commit 8cf08b2

Please sign in to comment.