Files
lnreader-plugins/plugins/russian/authortoday.ts
T
nyagami d818d1758f Beta phase (#801)
* beta host

* Refactor: url -> path (#757)

* refactor: url -> path

* clean up

* fix: json branch

* PagePlugin (#769)

* paginated novel support

* fix: truyenfull

* fix: tunovel, remove pageList

* parsePage support for webtest (#773)

* add parsePage api

* add parsePage UI

* add totalPages

* (FR src) Beta plugin & Added filters (#775)

* noveldeglace:
 - added filters
 - added latest
 - defaultCover fallback
 - change id to noveldeglace.com
 - added complementary infos in summary
 - added cover artist
 - chapters are now parts
 - show volume number for multi volume novels
 - better search
 - fix search page number
 - refactored for plugin beta
 - releaseDate as Date.toString()
 - separted parseNovels
 - separated getCheerio
 - loadedCheerio => $ for shorter lines & simpler test on web

* chireads:
 - fix different parsing for mobile version
 - added filters
 - added author
 - added status
 - added released date
 - refactored for plugin beta
 - separted parseNovels
 - separated getCheerio
 - loadedCheerio => $ for shorter lines & simpler test on web

* wpmangastream => lightnovelwp rework & new sources (#776)

* Added sources:
 - Knoxt (EN)
 - Baca Light Novel (ID)
 - AllNovelRead (ES)
 - DaoTranslate (EN)
 - جنة الروايات (AR)
 - Universal Novel (EN)
 - NovelTR (TR)
old sources auto-generated:
 - GenesisTls (EN)
 - NobleMTL (EN)
wpmangastream => lightnovelwp:
 - added doc
 - added filters in a separte file
 - semi-automatic filter generator
 - made it compatible with version 1.0.X and 1.1.X versions of the theme
 - loadedCheerio => $
 - icons in "/icons/lightnovel/id.png"
 - code cleanup

* removed auto-implemented sources

* Added README.md to lightnovelwp

* removed ai generated text for kolnovel

* added novelsknight

* added centralNovel

* pandamtl accual name

* adding folder plugin/arabic

* Fix: Vietnamese plugins (#777)

* fix: lightnovelvn

* add nettruyen

* add truyenchu

* fix: truyenconect

* Fix: Migrate plugins (#771)

* Add novel.ovh (#756)

* fix

* test

* fix

* date fix + master merge (#761)

* date fix

* Added Brazilian Portuguese E-Novel (#758)

* fixed single digit dates (#767)

Co-authored-by: NaddH1 <naderhorani@hotmail.com>

* fix

* test

* fix order

* Update renovels.ts

* require_chapters

* Delete plugins/english/genesistl.broken.ts

* Update novelTL.ts

---------

Co-authored-by: NaddH1 <naderhorani@hotmail.com>

* (src update) ENG (#772)

* allnovelfull

* bestlightnovel

* divinedaolibrary

* earlynovel

* lightnovelpub

* L

* M

* novelbin

* novelfull

* novelbuddy

* N S

* novel updates

* async sleep

* rename file

* pagePlugin

* Feat: minify js dir (#781)

* Multisrc: HotNovelPub (#784)

* HotNovelPub

* fix search

* Squashed commit of the following:

commit 3b759c68eddc06c0adfb959f775de069a85adca7
Author: nyagami <hoangquan05112002@gmail.com>
Date:   Sat Feb 17 20:33:47 2024 +0700

    Feat: minify js dir (#781)

* jsmin changed to terser

* test

* why I did it.

* test

* Update ranobelib.ts

* fix page

* Update ranobelib.ts

* updated modules

* Update terser.json

Co-authored-by: nyagami <hoangquan05112002@gmail.com>

* Update scripts/multisrc/hotnovelpub/template.ts

Co-authored-by: nyagami <hoangquan05112002@gmail.com>

* terser api

---------

Co-authored-by: nyagami <hoangquan05112002@gmail.com>

* Added sources & fix sources (#787)

* lightnovelwp:
 - fix author name
 - added more localisation of strings
 - README typo
 - error on !r.ok new message

* noveldeglace:
 - fix chapterNumber for parts
 - better dates
 - better search

* Added sources:
 - White Moonlight Novels (EN)
 - System Translation (EN)

* Resized centralnovel.png

* Add Faqwiki.us source (#792)

* Add Faqwiki.us source (beta branch)

* Fix Path, Fix Chapter Parsing, Fix Novel Title

* search novel path fix

* fix chapter parsing. some chapter in this site store their whole text in 1-4 <p>,

* Add WTR-LAB Source (#797)

* Add WTR-LAB Source (Beta Branch)

* Add other language from WTR-LAB source

* change lang to sourceLang

* remove id es tr lang from WTR-LAB

* Update plugins/english/wtrlab.ts

agree

Co-authored-by: nyagami <hoangquan05112002@gmail.com>

* Update plugins/english/wtrlab.ts

agree

Co-authored-by: nyagami <hoangquan05112002@gmail.com>

---------

Co-authored-by: nyagami <hoangquan05112002@gmail.com>

* revert: scripts to master

---------

Co-authored-by: Justin COLLON <48163201+error7404@users.noreply.github.com>
Co-authored-by: Rider21 <58046032+Rider21@users.noreply.github.com>
Co-authored-by: NaddH1 <naderhorani@hotmail.com>
Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
Co-authored-by: bregassa <bregas.sat1@gmail.com>
2024-02-25 14:52:37 +07:00

536 lines
17 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Plugin } from "@typings/plugin";
import { FilterTypes, Filters } from "@libs/filterInputs";
import { defaultCover } from "@libs/defaultCover";
import { fetchApi, fetchFile } from "@libs/fetch";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
import dayjs from "dayjs";
const apiUrl = "https://api.author.today/";
const token = "Bearer guest";
class AuthorToday implements Plugin.PluginBase {
id = "AT";
name = "Автор Тудей";
icon = "src/ru/authortoday/icon.png";
site = "https://author.today";
version = "1.0.0";
async popularNovels(
pageNo: number,
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = apiUrl + "v1/catalog/search?page=" + pageNo;
if (filters?.genre?.value) {
url += "&genre=" + filters.genre.value;
}
url +=
"&sorting=" +
(showLatestNovels ? "recent" : filters?.sort?.value || "popular");
url += "&form=" + (filters?.form?.value || "any");
url += "&state=" + (filters?.state?.value || "any");
url += "&series=" + (filters?.series?.value || "any");
url += "&access=" + (filters?.access?.value || "any");
url += "&promo=" + (filters?.promo?.value || "hide");
const result = await fetchApi(url, {
headers: {
Authorization: token,
},
});
const json = (await result.json()) as response;
const novels: Plugin.NovelItem[] = [];
if (json.code === "NotFound") {
return novels;
}
json?.searchResults?.forEach((novel) =>
novels.push({
name: novel.title,
cover: novel.coverUrl
? "https://cm.author.today/content/" + novel.coverUrl
: defaultCover,
path: "/work/" + novel.id,
}),
);
return novels;
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const workID = novelPath.split("/")[2];
const result = await fetchApi(`${apiUrl}v1/work/${workID}/details`, {
headers: {
Authorization: token,
},
});
const book = (await result.json()) as responseBook;
const novel: Plugin.SourceNovel = {
path: novelPath,
name: book.title,
cover: book.coverUrl ? book.coverUrl.split("?")[0] : defaultCover,
genres: book.tags?.join(", "),
summary: "",
author:
book.originalAuthor ||
book.authorFIO ||
book.coAuthorFIO ||
book.secondCoAuthorFIO ||
book.translator ||
"",
status: book.isFinished ? NovelStatus.Completed : NovelStatus.Ongoing,
};
if (book.annotation) {
novel.summary += book.annotation + "\n";
}
if (book.authorNotes) {
novel.summary += "Примечания автора:\n" + book.authorNotes;
}
const chaptersRaw = await fetchApi(`${apiUrl}v1/work/${workID}/content`, {
headers: {
Authorization: token,
},
});
const chaptersJSON = (await chaptersRaw.json()) as ChaptersEntity[];
const chapters: Plugin.ChapterItem[] = [];
chaptersJSON.forEach((chapter, chapterIndex) => {
if (chapter.isAvailable && !chapter.isDraft) {
chapters.push({
name: chapter.title || "Глава " + (chapterIndex + 1),
path: `v1/work/${workID}/chapter/${chapter.id}/text`,
releaseTime: dayjs(
chapter.publishTime || chapter.lastModificationTime,
).format("LLL"),
chapterNumber: (chapter.sortOrder || chapterIndex) + 1,
});
}
});
novel.chapters = chapters;
return novel;
}
async parseChapter(chapterPath: string): Promise<string> {
const result = await fetchApi(apiUrl + chapterPath, {
headers: {
Authorization: token,
},
});
const json = (await result.json()) as encryptedСhapter;
if (json.code) {
return json.code + "\n" + json?.message;
}
const key = json.key.split("").reverse().join("") + "@_@";
let text = "";
for (let i = 0; i < json.text.length; i++) {
text += String.fromCharCode(
json.text.charCodeAt(i) ^ key.charCodeAt(Math.floor(i % key.length)),
);
}
const loadedCheerio = parseHTML(text);
loadedCheerio("img").each((index, element) => {
if (!loadedCheerio(element).attr("src")?.startsWith("http")) {
const src = loadedCheerio(element).attr("src");
loadedCheerio(element).attr("src", this.site + src);
}
});
const chapterText = loadedCheerio.html();
return chapterText;
}
async searchNovels(
searchTerm: string,
pageNo: number | undefined = 1,
): Promise<Plugin.NovelItem[]> {
const url =
this.site + "/search?category=works&q=" + searchTerm + "&page=" + pageNo;
const result = await fetchApi(url).then((res) => res.text());
const loadedCheerio = parseHTML(result);
const novels: Plugin.NovelItem[] = [];
loadedCheerio("div.book-row").each((index, element) => {
const name = loadedCheerio(element)
.find('div[class="book-title"] a')
.text()
.trim();
let cover = loadedCheerio(element).find("img").attr("src");
const path = loadedCheerio(element)
.find('div[class="book-title"] a')
.attr("href");
cover = cover ? cover.split("?")[0] : defaultCover;
if (!path) return;
novels.push({ name, cover, path });
});
return novels;
}
fetchImage = fetchFile;
filters = {
sort: {
label: "Сортировка",
value: "popular",
options: [
{ label: "По популярности", value: "popular" },
{ label: "По количеству лайков", value: "likes" },
{ label: "По комментариям", value: "comments" },
{ label: "По новизне", value: "recent" },
{ label: "По просмотрам", value: "views" },
{ label: "Набирающие популярность", value: "trending" },
],
type: FilterTypes.Picker,
},
genre: {
label: "Жанры",
value: "",
options: [
{ label: "Все", value: "" },
{ label: "Альтернативная история", value: "sf-history" },
{ label: "Антиутопия", value: "dystopia" },
{ label: "Бизнес-литература", value: "biznes-literatura" },
{ label: "Боевая фантастика", value: "sf-action" },
{ label: "Боевик", value: "action" },
{ label: "Боевое фэнтези", value: "fantasy-action" },
{ label: "Бояръ-Аниме", value: "boyar-anime" },
{ label: "Героическая фантастика", value: "sf-heroic" },
{ label: "Героическое фэнтези", value: "heroic-fantasy" },
{ label: "Городское фэнтези", value: "urban-fantasy" },
{ label: "Детектив", value: "detective" },
{ label: "Детская литература", value: "detskaya-literatura" },
{ label: "Документальная проза", value: "non-fiction" },
{ label: "Историческая проза", value: "historical-fiction" },
{ label: "Исторические приключения", value: "historical-adventure" },
{ label: "Исторический детектив", value: "historical-mystery" },
{ label: "Исторический любовный роман", value: "historical-romance" },
{ label: "Историческое фэнтези", value: "historical-fantasy" },
{ label: "Киберпанк", value: "cyberpunk" },
{ label: "Короткий любовный роман", value: "short-romance" },
{ label: "Космическая фантастика", value: "sf-space" },
{ label: "ЛитРПГ", value: "litrpg" },
{ label: "Любовное фэнтези", value: "love-fantasy" },
{ label: "Любовные романы", value: "romance" },
{ label: "Мистика", value: "paranormal" },
{ label: "Назад в СССР", value: "back-to-ussr" },
{ label: "Научная фантастика", value: "science-fiction" },
{ label: "Подростковая проза", value: "teen-prose" },
{ label: "Политический роман", value: "political-fiction" },
{ label: "Попаданцы", value: "popadantsy" },
{ label: "Попаданцы в космос", value: "popadantsy-v-kosmos" },
{ label: "Попаданцы в магические миры", value: "popadantsy-v-magicheskie-miry" },
{ label: "Попаданцы во времени", value: "popadantsy-vo-vremeni" },
{ label: "Постапокалипсис", value: "postapocalyptic" },
{ label: "Поэзия", value: "poetry" },
{ label: "Приключения", value: "adventure" },
{ label: "Публицистика", value: "publicism" },
{ label: "Развитие личности", value: "razvitie-lichnosti" },
{ label: "Разное", value: "other" },
{ label: "РеалРПГ", value: "realrpg" },
{ label: "Романтическая эротика", value: "romantic-erotika" },
{ label: "Сказка", value: "fairy-tale" },
{ label: "Современная проза", value: "modern-prose" },
{ label: "Современный любовный роман", value: "contemporary-romance" },
{ label: "Социальная фантастика", value: "sf-social" },
{ label: "Стимпанк", value: "steampunk" },
{ label: "Темное фэнтези", value: "dark-fantasy" },
{ label: "Триллер", value: "thriller" },
{ label: "Ужасы", value: "horror" },
{ label: "Фантастика", value: "sci-fi" },
{ label: "Фантастический детектив", value: "detective-science-fiction" },
{ label: "Фанфик", value: "fanfiction" },
{ label: "Фэнтези", value: "fantasy" },
{ label: "Шпионский детектив", value: "spy-mystery" },
{ label: "Эпическое фэнтези", value: "epic-fantasy" },
{ label: "Эротика", value: "erotica" },
{ label: "Эротическая фантастика", value: "sf-erotika" },
{ label: "Эротический фанфик", value: "fanfiction-erotika" },
{ label: "Эротическое фэнтези", value: "fantasy-erotika" },
{ label: "Юмор", value: "humor" },
{ label: "Юмористическая фантастика", value: "sf-humor" },
{ label: "Юмористическое фэнтези", value: "ironical-fantasy" },
],
type: FilterTypes.Picker,
},
form: {
label: "Форма произведения",
value: "any",
options: [
{ label: "Любой", value: "any" },
{ label: "Перевод", value: "translation" },
{ label: "Повесть", value: "tale" },
{ label: "Рассказ", value: "story" },
{ label: "Роман", value: "novel" },
{ label: "Сборник поэзии", value: "poetry" },
{ label: "Сборник рассказов", value: "story-book" },
],
type: FilterTypes.Picker,
},
state: {
label: "Статус произведения",
value: "any",
options: [
{ label: "Любой статус", value: "any" },
{ label: "В процессе", value: "in-progress" },
{ label: "Завершено", value: "finished" },
],
type: FilterTypes.Picker,
},
series: {
label: "Статус цикла",
value: "any",
options: [
{ label: "Не важно", value: "any" },
{ label: "Вне цикла", value: "out" },
{ label: "Цикл завершен", value: "finished" },
{ label: "Цикл не завершен", value: "unfinished" },
],
type: FilterTypes.Picker,
},
access: {
label: "Тип доступа",
value: "any",
options: [
{ label: "Любой", value: "any" },
{ label: "Платный", value: "paid" },
{ label: "Бесплатный", value: "free" },
],
type: FilterTypes.Picker,
},
promo: {
label: "Промо-фрагмент",
value: "hide",
options: [
{ label: "Скрывать", value: "hide" },
{ label: "Показывать", value: "show" },
],
type: FilterTypes.Picker,
},
} satisfies Filters;
}
export default new AuthorToday();
interface response {
searchResults?: SearchResultsEntity[] | null;
realTotalCount: number;
code?: string;
errorMessage?: null;
isLastPage: boolean;
format: Format;
duration: Duration;
isWorkMarkEnabled: boolean;
}
interface SearchResultsEntity {
id: number;
title: string;
annotation: string;
authorId: number;
authorFIO: string;
authorUserName: string;
originalAuthor?: null;
coAuthorId?: number | null;
coAuthorFIO?: string | null;
coAuthorUserName?: string | null;
coAuthorConfirmed: boolean;
seriesId: number;
seriesTitle?: string | null;
publishTime: string;
lastModificationTime: string;
finishTime?: string | null;
isDraft: boolean;
formEnum: string;
genreId: number;
firstSubGenreId: number;
secondSubGenreId?: number | null;
adultOnly: boolean;
tags?: (string | null)[] | null;
coverUrl: string;
viewCount: number;
commentCount: number;
reviewCount: number;
textLength: number;
likeCount: number;
showAuthor: boolean;
price?: number | null;
discount?: null;
discountStartDate?: null;
discountEndDate?: null;
status: string;
promoFragment: boolean;
isExclusive: boolean;
format: string;
marks?: null[] | null;
isLiked: boolean;
isWorkMarkEnabled: boolean;
workInLibraryState: string;
}
interface Format {
enumValue: string;
value: string;
title: string;
mobileTitle: string;
}
interface Duration {
value: string;
title: string;
mobileTitle: string;
}
interface responseBook {
chapters?: ChaptersEntity[] | null;
allowDownloads: boolean;
downloadErrorCode: string;
downloadErrorMessage: string;
privacyDownloads: string;
collectionCount: number;
annotation: string;
authorNotes: string;
atRecommendation: boolean;
seriesWorkIds?: number[] | null;
seriesWorkNumber: number;
reviewCount: number;
tags?: string[] | null;
orderId?: null;
orderStatus: string;
orderStatusMessage?: null;
contests?: null[] | null;
galleryImages?: GalleryImagesEntity[] | null;
booktrailerVideoUrl?: null;
isExclusive: boolean;
freeChapterCount: number;
promoFragment: boolean;
recommendations?: RecommendationsEntity[] | null;
linkedWork?: null;
id: number;
title: string;
coverUrl: string;
lastModificationTime: string;
lastUpdateTime: string;
finishTime?: null;
isFinished: boolean;
textLength: number;
textLengthLastRead: number;
price: number;
discount?: null;
workForm: string;
status: string;
authorId: number;
authorFIO: string;
authorUserName: string;
originalAuthor?: null;
translator?: null;
reciter?: null;
coAuthorId?: null;
coAuthorFIO?: null;
coAuthorUserName?: null;
coAuthorConfirmed: boolean;
secondCoAuthorId?: null;
secondCoAuthorFIO?: null;
secondCoAuthorUserName?: null;
secondCoAuthorConfirmed: boolean;
isPurchased: boolean;
userLikeId?: null;
lastReadTime?: null;
lastChapterId?: null;
lastChapterProgress: number;
likeCount: number;
commentCount: number;
rewardCount: number;
rewardsEnabled: boolean;
inLibraryState: string;
addedToLibraryTime: string;
updateInLibraryTime: string;
privacyDisplay: string;
state: string;
isDraft: boolean;
enableRedLine: boolean;
enableTTS: boolean;
adultOnly: boolean;
seriesId: number;
seriesOrder: number;
seriesTitle: string;
afterword: string;
seriesNextWorkId?: null;
genreId: number;
firstSubGenreId: number;
secondSubGenreId: number;
format: string;
marks?: null;
purchaseTime?: null;
likeTime?: null;
markTime?: null;
}
interface ChaptersEntity {
id: number;
workId: number;
title: string;
isDraft: boolean;
sortOrder: number;
publishTime?: string;
lastModificationTime: string;
textLength: number;
isAvailable: boolean;
}
interface GalleryImagesEntity {
id: string;
caption?: null;
url: string;
height: number;
width: number;
}
interface RecommendationsEntity {
title: string;
coverUrl: string;
authorId: number;
authorFIO: string;
authorUserName: string;
originalAuthor?: null;
coAuthorId?: null;
coAuthorFIO?: null;
coAuthorUserName?: null;
coAuthorConfirmed: boolean;
secondCoAuthorId?: null;
secondCoAuthorFIO?: null;
secondCoAuthorUserName?: null;
secondCoAuthorConfirmed: boolean;
discount?: null;
price?: number | null;
lastModificationTime: string;
finishTime: string;
finished: boolean;
isExclusive: boolean;
format: string;
status: string;
state: string;
removalReason?: null;
removalReasonComment?: null;
id: number;
}
interface encryptedСhapter {
id: number;
title: string;
isDraft: boolean;
publishTime: string;
lastModificationTime: string;
text: string;
key: string;
code?: string;
message?: string;
}