Skip to content

Commit

Permalink
fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
Rider21 committed Feb 8, 2024
1 parent 5d58eb5 commit c53dc8c
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/sources/en/readlightnovel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,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?.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;
27 changes: 26 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,28 @@ 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 c53dc8c

Please sign in to comment.