Files
lnreader-plugins/plugins/russian/tsundokunoveltl[noveltl].ts
T
nyagami e602df44c8 Full TS for Plugins (#538)
* remove lang, descrription in plugin script

* remove languages import

* Update README.md

* fix: missing lang

* clean: remove description

* feat(Add Sources) (#15)

* add many sources

* add showToast

* feat(Add Source): (#16)

* add source

* remove descriptions

* Early Novel & Fast Novel (#1)

* some more plugin

* plugin

* try something new

* yes

* try yes

* genres is plural

* fastnovel full fix

* testings

* early check

* earlynovel fixed

* showToast check

* earlynovel done

* fastnovel fixe

* again

* showToasts again

* fix for fastnovel

* done

* for pr

* Update freenovelupdates.js

* MTL Reader and MTL Novel (#2)

* first

* test

* wops

* mtlreaders

* ok

* for PR

* Nitro Scans and Novel Hold (#3)

* start feature

* more feature

* something

* eslint

* yes

* maybe

* wa

* asdasd

* amazing

* change it up

* for pr

* WPmangastream and Novelfull (#4) (#17)

* source generation

* fix json parse error

* update plguins

* delete fetchApi, nobleMTL (.js)

* delete showToast.js

* Typescript Support (#18)

* Initial TS Config

* Initial TS Config

* Fix most errors

* Fix test webserver

* Fix webserver isPlugin not working

* Fix typos

* Add check if plugins have all the fields

* Move exports.protected to the bottom of the plugin

* Change username, reponame and branchname

* Fix no exports error

* Fix type

* Fix typo in tsc_fix

* Remove const from exports to not re-define consts

* Readd const becuause exports may not exist.

* Fix plugins to work in-app

* Fix NobleMTL

* Remove fix_ts.ts

* Change template.ts

* delete cheerio_space

* move api into ./testweb

* remove js dir

* remove js dir (again)

* remove ./js (again)

* init multisrc generator (test)

* remove module.exports in libs

* madara generator

* update template

* rename generator, TS for hako

* fix icon url for madara

* fix icon for madara (again)

* update Readme, nodemon

* export default for all libs

* fix madara novelurl

* update: pluginId, name, filename for madara

* feat: check same id error

* update: precommit, fix: require.default

* Revert "update: precommit, fix: require.default"

This reverts commit c642c5c72241f13eccfe417210c22272c4739ffa.

* Port all plugins to ts (#19)

- fix cheerio
- remove export default
- fix spelling

* update template

* add multisrc noveltl, update generator param, fix web search

* fix undefined id for Snailulitka

* add rulate multisrc, fix max length textarea

* add readwn multisrc

* delete: erolate and rulate are in multisrc

* Change broken extension and show error on commit for those files (#20)

* Change to .broken.ts and show error on commit for those files

* remove novelStatus

* fix: wrong id in github action

* remove mangastream multisrc

* update icon for readwn multisrc

---------

Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
Co-authored-by: Marcin Majewski <skilletssgames@gmail.com>
2023-08-17 08:49:45 +05:30

219 lines
9.9 KiB
TypeScript

import { load as parseHTML } from "cheerio";
import dayjs from 'dayjs';
import { fetchFile, fetchApi } from "@libs/fetch";
import { Novel, Plugin, Chapter } from "@typings/plugin";
// import { parseMadaraDate } from "@libs/parseMadaraDate";
// import { isUrlAbsolute } from '@libs/isAbsoluteUrl';
// import { showToast } from "@libs/showToast";
import { Filter, FilterInputs } from "@libs/filterInputs";
import { NovelStatus } from '@libs/novelStatus';
import { defaultCover } from "@libs/defaultCover";
export const id = "tsundoku.novel";
export const name = "TsundokuTrans";
export const icon = "";
export const version = "1.0.0";
export const site = "https://tsundoku.novel.tl";
export const filters: Filter[] = [{"key":"tags","label":"Тэги","values":[{"label":"Боги","value":318},{"label":"Боевая академия","value":75},{"label":"Вампиры","value":742},{"label":"Влияние прошлого","value":517},{"label":"Война","value":750},{"label":"Главная героиня — женщина","value":277},{"label":"Главный герой — мужчина","value":419},{"label":"Демоны","value":193},{"label":"Драконы","value":218},{"label":"Королевская особа","value":596},{"label":"Коррупция","value":157},{"label":"Магия","value":412},{"label":"Мастер подземелий","value":222},{"label":"Мечи и магия","value":697},{"label":"Мечники","value":698},{"label":"Монстры","value":454},{"label":"Недооцененный главный герой","value":734},{"label":"От слабого к сильному","value":752},{"label":"R-15","value":570},{"label":"R-18","value":571}],"inputType":FilterInputs.Checkbox}];
exports["protected"] = false;
const baseUrl = site;
const domain = baseUrl.split('//')[1];
export const popularNovels: Plugin.popularNovels = async function (
page,
{ filters }
) {
const result = await fetchApi('https://api.novel.tl/api/site/v2/graphql', {
method: 'post',
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Content-Type': 'application/json',
'Alt-Used': 'api.novel.tl',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
},
referrer: baseUrl,
body: JSON.stringify({
operationName: 'Projects',
query:
'query Projects($hostname:String! $filter:SearchFilter $page:Int $limit:Int){projects(section:{fullUrl:$hostname}filter:$filter page:{pageSize:$limit,pageNumber:$page}){content{title url covers{url}}}}',
variables: {
filter: filters?.tags?.length ?? 0 > 0 ? { tags: filters?.tags } : {},
hostname: domain,
limit: 40,
page,
},
}),
});
const json: any = await result.json();
const novels: Novel.Item[] = json.data?.projects?.content?.map((novel: any) => ({
name: novel.title,
url: baseUrl + '/r/' + novel.url,
cover: novel.covers[0]?.url
? baseUrl + novel.covers[0].url
: defaultCover,
}));
return novels;
};
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
async function (novelUrl) {
const result = await fetchApi('https://api.novel.tl/api/site/v2/graphql', {
method: 'post',
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Content-Type': 'application/json',
'Alt-Used': 'api.novel.tl',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
},
referrer: baseUrl,
body: JSON.stringify({
operationName: 'Book',
query:
'query Book($url:String){project(project:{fullUrl:$url}){title translationStatus url covers{url}persons(langs:["ru","en","*"]roles:["author","illustrator","original_story","original_design"]){role name{firstName lastName}}genres{nameRu nameEng}tags{nameRu nameEng}annotation{text}subprojects{content{title volumes{content{url shortName chapters{title publishDate url published}}}}}}}',
variables: {
hostname: domain,
project: novelUrl,
url: novelUrl,
},
}),
});
const json: any = await result.json();
const novel: Novel.instance = {
url: novelUrl,
name: json.data.project.title,
cover: json.data.project.covers[0]?.url
? baseUrl + json.data.project.covers[0].url
: defaultCover,
summary: parseHTML(json.data.project.annotation?.text).text(),
author:
json.data.project.persons[0].name.firstName +
' ' +
json.data.project.persons[0].name.lastName,
status:
json.data.project.translationStatus === 'active'
? NovelStatus.Ongoing
: NovelStatus.Completed,
};
let genres = []
.concat(json.data.project.tags, json.data.project.genres)
.map((item: any) => item?.nameRu || item?.nameEng)
.filter(item => item);
if (genres.length > 0) {
novel.genres = genres.join(',');
}
let novelChapters: Chapter.Item[] = [];
json.data.project.subprojects.content.forEach((work: any) =>
work.volumes.content.forEach((volume: any) =>
volume.chapters.forEach(
(chapter: any) =>
chapter?.published &&
novelChapters.push({
name: volume.shortName + ' ' + chapter.title,
url: novelUrl + '/' + volume.url + '/' + chapter.url,
releaseTime: dayjs(chapter.publishDate).format('LLL'),
}),
),
),
);
novel.chapters = novelChapters;
return novel;
};
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
const result = await fetchApi('https://api.novel.tl/api/site/v2/graphql', {
method: 'post',
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Content-Type': 'application/json',
'Alt-Used': 'api.novel.tl',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
},
referrer: baseUrl,
body: JSON.stringify({
operationName: 'EReaderData',
query:
'query EReaderData($url:String!,$chapterSelector:Selector!){project(project:{fullUrl:$url}){title url}chapter(chapter:$chapterSelector){title text{text}}}',
variables: {
chapterSelector: {
fullUrl: chapterUrl,
},
url: chapterUrl,
},
}),
});
const json: any = await result.json();
return parseHTML(json.data.chapter.text.text).html();
};
export const searchNovels: Plugin.searchNovels = async (searchTerm) => {
const result = await fetchApi('https://api.novel.tl/api/site/v2/graphql', {
method: 'post',
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Content-Type': 'application/json',
'Alt-Used': 'api.novel.tl',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site',
},
referrer: baseUrl,
body: JSON.stringify({
operationName: 'Projects',
query:
'query Projects($hostname:String! $filter:SearchFilter $page:Int $limit:Int){projects(section:{fullUrl:$hostname}filter:$filter page:{pageSize:$limit,pageNumber:$page}){content{title url covers{url}}}}',
variables: {
filter: {
query: searchTerm,
},
hostname: domain,
limit: 40,
page: 1,
},
}),
});
const json: any = await result.json();
const novels: Novel.Item[] = [];
json?.data?.projects?.content?.forEach((novel: any) =>
novels.push({
name: novel.title,
url: baseUrl + '/r/' + novel.url,
cover: novel.covers[0]?.url
? baseUrl + novel.covers[0].url
: defaultCover,
}),
);
return novels;
};
export const fetchImage: Plugin.fetchImage = async (url) => {
return await fetchFile(url, {});
};