refactor: Overhaul Plugin Architecture & Playground UI (#1846)
* refactor: Move Plugins Out and Consolidate with Multisrc * feat: Overhaul Playground UI * feat: Add Filters to New UI * feat: Persist Selected Plugin * feat: Add Direct Parse Novel/Chapter Options and Feedback Toasts [skip ci] * feat: UX Improvements * chore: Update Plugin Path in Publish Workflow * fix: Add Backward Compatibility * chore: Update Plugin Publishing Script
This commit is contained in:
committed by
GitHub
parent
252beff0bf
commit
20c2b75b01
@@ -0,0 +1,424 @@
|
||||
import { CheerioAPI, load as parseHTML } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
|
||||
class dilartube implements Plugin.PluginBase {
|
||||
id = 'dilartube';
|
||||
name = 'dilar tube';
|
||||
version = '1.0.1';
|
||||
icon = 'src/ar/dilartube/icon.png';
|
||||
site = 'https://golden.rest/';
|
||||
|
||||
parseNovels(data: ApiResponse): Plugin.NovelItem[] {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
const seenTitles = new Set<string>();
|
||||
if (data.data && data.data.length > 0) {
|
||||
data.data
|
||||
.filter(dataItem => dataItem.is_novel)
|
||||
.forEach(dataItem => {
|
||||
const manga = dataItem;
|
||||
if (!seenTitles.has(dataItem.title)) {
|
||||
seenTitles.add(manga.title);
|
||||
novels.push({
|
||||
name: dataItem.title || 'novel',
|
||||
path: `mangas/${manga.id}`,
|
||||
cover: manga.cover
|
||||
? `${this.site}uploads/manga/cover/${manga.id}/${manga.cover}`
|
||||
: defaultCover,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (data.releases && data.releases.length > 0) {
|
||||
data.releases
|
||||
.filter(release => release.manga.is_novel)
|
||||
.forEach(release => {
|
||||
const manga = release.manga;
|
||||
if (!seenTitles.has(manga.title)) {
|
||||
seenTitles.add(manga.title);
|
||||
novels.push({
|
||||
name: manga.title || 'novel',
|
||||
path: `mangas/${manga.id}`,
|
||||
cover: manga.cover
|
||||
? `${this.site}uploads/manga/cover/${manga.id}/${manga.cover}`
|
||||
: defaultCover,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
page: number,
|
||||
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions<Filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = `${this.site}api/releases?page=${page}`;
|
||||
if (showLatestNovels) {
|
||||
link = `${this.site}api/releases?page=${page}`;
|
||||
}
|
||||
// if (filters) {
|
||||
// if (
|
||||
// Array.isArray(filters.categories.value) &&
|
||||
// filters.categories.value.length > 0
|
||||
// ) {
|
||||
// filters.categories.value.forEach((genre: string) => {
|
||||
// link += `&category=${genre}`;
|
||||
// });
|
||||
// }
|
||||
// if (filters.status.value !== '') {
|
||||
// link += `&status=${filters.status.value}`;
|
||||
// }
|
||||
// }
|
||||
// link += `?page=${page}`;
|
||||
// const body = await fetchApi(link).then(r => r.text());
|
||||
const response = await fetchApi(link).then(r => r.json());
|
||||
return this.parseNovels(response);
|
||||
}
|
||||
|
||||
async parseNovel(novelUrl: string): Promise<Plugin.SourceNovel> {
|
||||
const chapterItems: Plugin.ChapterItem[] = [];
|
||||
const fullUrl = this.site + 'api/' + novelUrl;
|
||||
const chapterUrl = this.site + 'api/' + novelUrl + '/releases';
|
||||
const manga = await fetchApi(fullUrl).then(r => r.json());
|
||||
const chapters = await fetchApi(chapterUrl).then(r => r.json());
|
||||
const mangaData = manga.mangaData;
|
||||
const chapterData = chapters.releases;
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelUrl,
|
||||
name: mangaData.arabic_title || 'Untitled',
|
||||
author:
|
||||
(mangaData.authors.length > 0 ? mangaData.authors[0].name : '') ||
|
||||
'Unknown',
|
||||
summary: mangaData.summary || '',
|
||||
cover: `${this.site}uploads/manga/cover/${mangaData.id}/${mangaData.cover}`,
|
||||
chapters: [],
|
||||
};
|
||||
const translationStatusId: string = mangaData.translation_status;
|
||||
const translationText =
|
||||
{
|
||||
'1': 'مستمره',
|
||||
'0': 'منتهية',
|
||||
'2': 'متوقفة',
|
||||
'3': 'غير مترجمه',
|
||||
}[translationStatusId] || 'غير معروف';
|
||||
const statusWords = new Set(['مكتمل', 'جديد', 'مستمر']);
|
||||
const mainGenres = mangaData.categories
|
||||
.map((category: { name: any }) => category.name)
|
||||
.join(',');
|
||||
novel.genres = `${translationText},${mainGenres}`;
|
||||
|
||||
const statusId: string = mangaData.story_status;
|
||||
const statusText =
|
||||
{
|
||||
'2': 'Ongoing',
|
||||
'3': 'Completed',
|
||||
}[statusId] || 'Unknown';
|
||||
novel.status = statusText;
|
||||
chapterData.map((item: ChapterRelease) => {
|
||||
chapterItems.push({
|
||||
name: item.title,
|
||||
releaseTime: new Date(item.created_at).toISOString(),
|
||||
path: `${novelUrl}/${mangaData.title.replace(' ', '-')}/${item.chapter}`,
|
||||
chapterNumber: item.chapter,
|
||||
});
|
||||
});
|
||||
novel.chapters = chapterItems.reverse();
|
||||
return novel;
|
||||
}
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const result = await fetchApi(new URL(chapterUrl, this.site).toString());
|
||||
const body = await result.text();
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const jsonData = loadedCheerio('script.js-react-on-rails-component').html();
|
||||
const parsedData = JSON.parse(jsonData as string);
|
||||
|
||||
const chapterText = parsedData.readerDataAction.readerData.release.content;
|
||||
return chapterText;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
page: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const formData = new FormData();
|
||||
formData.append('query', searchTerm);
|
||||
formData.append('includes', '["Manga","Team","Member"]');
|
||||
const response = await fetchApi('https://dilar.tube/api/quick_search', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
}).then(r => r.json());
|
||||
const data: ApiResponse = response[0];
|
||||
return this.parseNovels(data);
|
||||
}
|
||||
|
||||
// filters = {
|
||||
// types: {
|
||||
// value: [],
|
||||
// label: 'الأنواع',
|
||||
// options: [
|
||||
// { label: 'يابانية', value: '1' }, // Japanese
|
||||
// { label: 'كورية', value: '2' }, // Korean
|
||||
// { label: 'صينية', value: '3' }, // Chinese
|
||||
// { label: 'عربية', value: '4' }, // Arabic
|
||||
// { label: 'كوميك', value: '5' }, // Comic
|
||||
// { label: 'هواة', value: '6' }, // Amateur
|
||||
// { label: 'إندونيسية', value: '7' }, // Indonesian
|
||||
// { label: 'روسية', value: '8' }, // Russian
|
||||
// ],
|
||||
// type: FilterTypes.CheckboxGroup,
|
||||
// },
|
||||
|
||||
// status: {
|
||||
// value: '',
|
||||
// label: 'الحالة',
|
||||
// options: [
|
||||
// { label: 'مستمرة', value: '2' }, // Ongoing
|
||||
// { label: 'منتهية', value: '3' }, // Completed
|
||||
// ],
|
||||
// type: FilterTypes.CheckboxGroup,
|
||||
// },
|
||||
|
||||
// translation: {
|
||||
// value: [],
|
||||
// label: 'الترجمة',
|
||||
// options: [
|
||||
// { label: 'منتهية', value: '0' }, // Completed
|
||||
// { label: 'مستمرة', value: '1' }, // Ongoing
|
||||
// { label: 'متوقفة', value: '2' }, // Paused
|
||||
// { label: 'غير مترجمة', value: '3' }, // Not Translated
|
||||
// ],
|
||||
// type: FilterTypes.CheckboxGroup,
|
||||
// },
|
||||
// } satisfies Filters;
|
||||
}
|
||||
|
||||
export default new dilartube();
|
||||
|
||||
type Category = {
|
||||
id: number;
|
||||
name: string;
|
||||
icon: string | null;
|
||||
manga_id: number;
|
||||
};
|
||||
|
||||
type Type = {
|
||||
id: number;
|
||||
name: string;
|
||||
reading_direction: string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
type Manga = {
|
||||
id: number;
|
||||
title: string;
|
||||
summary: string;
|
||||
is_novel: boolean;
|
||||
is_oneshot: boolean;
|
||||
genre_id: number;
|
||||
cover: string;
|
||||
cover_pos: number;
|
||||
rectangle_cover_pos: number;
|
||||
banner: string;
|
||||
manga_type_id: number;
|
||||
reading_direction: string;
|
||||
story_status: number;
|
||||
translation_status: number;
|
||||
vols: number;
|
||||
chaps: number;
|
||||
reviewed: boolean;
|
||||
banned: boolean;
|
||||
rating: string;
|
||||
rates_count: number;
|
||||
commentable: boolean;
|
||||
show_comments: boolean;
|
||||
deleted_at: string | null;
|
||||
delete_reason: string;
|
||||
time_stamp: number;
|
||||
latest_chapterization_id: number;
|
||||
uniq_visitors_count: number;
|
||||
publisher_id: number | null;
|
||||
publisher_name: string | null;
|
||||
discord_url: string | null;
|
||||
mobile_exclusive: boolean;
|
||||
authors: any[];
|
||||
artists: any[];
|
||||
categories: Category[];
|
||||
type: Type;
|
||||
};
|
||||
type Release = {
|
||||
id: number;
|
||||
manga_id: number;
|
||||
created_at: string;
|
||||
time_stamp: number;
|
||||
views: number;
|
||||
encoded: boolean;
|
||||
showable: boolean;
|
||||
link_control: number;
|
||||
support_link: string;
|
||||
creator_id: number;
|
||||
chapterization_id: number;
|
||||
chapter: number;
|
||||
volume: number;
|
||||
title: string;
|
||||
team_id: number;
|
||||
team_name: string;
|
||||
team_rating: string;
|
||||
team_settings: string;
|
||||
team_paypal: string | null;
|
||||
has_rev_link: boolean;
|
||||
manga: Manga;
|
||||
};
|
||||
type ApiResponse = {
|
||||
releases: Release[];
|
||||
data: searchManga[];
|
||||
};
|
||||
type MangaCategory = {
|
||||
id: number;
|
||||
name: string;
|
||||
icon: string | null;
|
||||
manga_id: number;
|
||||
};
|
||||
type AuthorArtist = {
|
||||
id: number;
|
||||
name: string;
|
||||
manga_id: number;
|
||||
role: string;
|
||||
};
|
||||
|
||||
type MangaType = {
|
||||
id: number;
|
||||
name: string;
|
||||
reading_direction: string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
type MangaData = {
|
||||
id: number;
|
||||
title: string;
|
||||
summary: string;
|
||||
is_novel: boolean;
|
||||
is_oneshot: boolean;
|
||||
genre_id: number;
|
||||
cover: string;
|
||||
cover_pos: number;
|
||||
rectangle_cover_pos: number;
|
||||
banner: string;
|
||||
manga_type_id: number;
|
||||
reading_direction: string;
|
||||
story_status: number;
|
||||
translation_status: number;
|
||||
vols: number;
|
||||
chaps: number;
|
||||
reviewed: boolean;
|
||||
banned: boolean;
|
||||
rating: string;
|
||||
rates_count: number;
|
||||
commentable: boolean;
|
||||
show_comments: boolean;
|
||||
deleted_at: string | null;
|
||||
delete_reason: string | null;
|
||||
time_stamp: number;
|
||||
latest_chapterization_id: number;
|
||||
uniq_visitors_count: number;
|
||||
publisher_id: number | null;
|
||||
publisher_name: string | null;
|
||||
arabic_title: string;
|
||||
english: string;
|
||||
synonyms: string;
|
||||
japanese: string;
|
||||
over17: boolean;
|
||||
s_date: string;
|
||||
e_date: string | null;
|
||||
mal: string;
|
||||
mangaupdates: string;
|
||||
mangadex: string | null;
|
||||
anilist: string;
|
||||
official_site: string | null;
|
||||
manga_fox: string | null;
|
||||
wikia: string | null;
|
||||
mangarock_oid: string | null;
|
||||
comicvine_id: string | null;
|
||||
external_source: string | null;
|
||||
discord_url: string | null;
|
||||
discord_id: string | null;
|
||||
anime_start_end: string | null;
|
||||
creator_id: number;
|
||||
creator_nick: string;
|
||||
editor_id: number;
|
||||
editor_nick: string;
|
||||
mobile_exclusive: boolean;
|
||||
authors: AuthorArtist[];
|
||||
artists: AuthorArtist[];
|
||||
categories: MangaCategory[];
|
||||
type: MangaType;
|
||||
memberRating: number;
|
||||
};
|
||||
|
||||
type MangaResponse = {
|
||||
membersMentioning: any[];
|
||||
memberRates: any | null;
|
||||
mangaLogs: Record<string, any>;
|
||||
mangaData: MangaData;
|
||||
};
|
||||
type ChapterRelease = {
|
||||
id: number;
|
||||
manga_id: number;
|
||||
created_at: string; // ISO 8601 date string
|
||||
time_stamp: number;
|
||||
views: number;
|
||||
link_control: number;
|
||||
support_link: string;
|
||||
init_team: number;
|
||||
creator_id: number;
|
||||
chapterization_id: number;
|
||||
chapterization_time_stamp: number;
|
||||
chapter: number;
|
||||
volume: number;
|
||||
title: string;
|
||||
team_id: number;
|
||||
team_name: string;
|
||||
has_rev_link: boolean;
|
||||
};
|
||||
type searchManga = {
|
||||
filter: any;
|
||||
id: number;
|
||||
title: string;
|
||||
summary: string;
|
||||
is_novel: boolean;
|
||||
is_oneshot: boolean;
|
||||
genre_id: number;
|
||||
cover: string;
|
||||
cover_pos: number;
|
||||
rectangle_cover_pos: number;
|
||||
banner: string;
|
||||
manga_type_id: number;
|
||||
reading_direction: string;
|
||||
story_status: number;
|
||||
translation_status: number;
|
||||
vols: number;
|
||||
chaps: number;
|
||||
reviewed: boolean;
|
||||
banned: boolean;
|
||||
rating: string;
|
||||
rates_count: number;
|
||||
commentable: boolean;
|
||||
show_comments: boolean;
|
||||
deleted_at: string | null;
|
||||
delete_reason: string;
|
||||
time_stamp: number;
|
||||
latest_chapterization_id: number;
|
||||
uniq_visitors_count: number;
|
||||
publisher_id: number | null;
|
||||
publisher_name: string | null;
|
||||
discord_url: string | null;
|
||||
mobile_exclusive: boolean;
|
||||
authors: any[];
|
||||
artists: any[];
|
||||
categories: Category[];
|
||||
type: Type;
|
||||
};
|
||||
@@ -0,0 +1,264 @@
|
||||
import { CheerioAPI, load as parseHTML } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
|
||||
class RewayatClub implements Plugin.PagePlugin {
|
||||
id = 'rewayatclub';
|
||||
name = 'Rewayat Club';
|
||||
version = '1.0.2';
|
||||
icon = 'src/ar/rewayatclub/icon.png';
|
||||
site = 'https://rewayat.club/';
|
||||
|
||||
parseNovels(data: NovelData): Plugin.NovelItem[] {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
if (data.results === undefined) return novels;
|
||||
data.results.map((item: NovelEntry) => {
|
||||
novels.push({
|
||||
name: item.arabic || item.novel?.arabic || 'novel',
|
||||
path: item.slug
|
||||
? `novel/${item.slug}`
|
||||
: item.novel
|
||||
? `novel/${item.novel.slug}`
|
||||
: 'novel',
|
||||
cover: item.poster_url
|
||||
? `https://api.rewayat.club/${item.poster_url.slice(1)}`
|
||||
: item.novel
|
||||
? `https://api.rewayat.club/${item.novel.poster_url.slice(1)}`
|
||||
: defaultCover,
|
||||
});
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
page: number,
|
||||
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions<Filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = `https://api.rewayat.club/api/novels/`;
|
||||
let body: NovelData = {
|
||||
count: 0,
|
||||
next: '',
|
||||
previous: '',
|
||||
results: [],
|
||||
};
|
||||
if (showLatestNovels) {
|
||||
link = `${this.site}api/chapters/weekly/list/?page=${page}`;
|
||||
body = await fetchApi(link).then(r => r.json());
|
||||
} else if (filters) {
|
||||
if (filters.categories.value !== '') {
|
||||
link += `?type=${filters.categories.value}`;
|
||||
}
|
||||
if (filters.sortOptions.value !== '') {
|
||||
link += `&ordering=${filters.sortOptions.value}`;
|
||||
}
|
||||
if (filters.genre.value.length > 0) {
|
||||
filters.genre.value.forEach((genre: string) => {
|
||||
link += `&genre=${genre}`;
|
||||
});
|
||||
}
|
||||
link += `&page=${page}`;
|
||||
body = await fetchApi(link).then(r => r.json());
|
||||
}
|
||||
return this.parseNovels(body);
|
||||
}
|
||||
|
||||
async parseNovel(
|
||||
novelUrl: string,
|
||||
): Promise<Plugin.SourceNovel & { totalPages: number }> {
|
||||
const result = await fetchApi(new URL(novelUrl, this.site).toString());
|
||||
const body = await result.text();
|
||||
const loadedCheerio = parseHTML(body);
|
||||
const novel: Plugin.SourceNovel & { totalPages: number } = {
|
||||
path: novelUrl,
|
||||
name: loadedCheerio('h1.primary--text span').text().trim() || 'Untitled',
|
||||
author: loadedCheerio('.novel-author').text().trim(),
|
||||
summary: loadedCheerio('div.text-pre-line span').text().trim(),
|
||||
totalPages: 1,
|
||||
chapters: [],
|
||||
};
|
||||
const statusWords = new Set(['مكتملة', 'متوقفة', 'مستمرة']);
|
||||
const mainGenres = Array.from(loadedCheerio('.v-slide-group__content a'))
|
||||
.map(el => loadedCheerio(el).text().trim())
|
||||
.join(',');
|
||||
const statusGenre = Array.from(
|
||||
loadedCheerio('div.v-slide-group__content span.v-chip__content'),
|
||||
)
|
||||
.map(el => loadedCheerio(el).text().trim())
|
||||
.filter(text => statusWords.has(text));
|
||||
novel.genres = `${statusGenre},${mainGenres}`;
|
||||
const statusText = Array.from(
|
||||
loadedCheerio('div.v-slide-group__content span.v-chip__content'),
|
||||
)
|
||||
.map(el => loadedCheerio(el).text().trim())
|
||||
.filter(text => statusWords.has(text))
|
||||
.join();
|
||||
novel.status =
|
||||
{
|
||||
'متوقفة': 'On Hiatus',
|
||||
'مكتملة': 'Completed',
|
||||
'مستمرة': 'Ongoing',
|
||||
}[statusText] || 'Unknown';
|
||||
const imageRaw = loadedCheerio('body script:contains("__NUXT__")')
|
||||
.first()
|
||||
.text();
|
||||
const imageUrlRegex = /poster_url:"(\\u002F[^"]+)"/;
|
||||
const imageUrlMatch = imageRaw?.match(imageUrlRegex);
|
||||
const ImageUrlShort = imageUrlMatch
|
||||
? imageUrlMatch[1].replace(/\\u002F/g, '/').replace(/^\/*/, '')
|
||||
: defaultCover;
|
||||
const imageUrl = `https://api.rewayat.club/${ImageUrlShort}`;
|
||||
novel.cover = imageUrl;
|
||||
const chapterNumberStr = loadedCheerio('div.v-tab--active span.mr-1')
|
||||
.text()
|
||||
.replace(/[^\d]/g, '');
|
||||
const chapterNumber = parseInt(chapterNumberStr, 10);
|
||||
const pageNumber = Math.ceil(chapterNumber / 24);
|
||||
novel.totalPages = pageNumber;
|
||||
|
||||
return novel;
|
||||
}
|
||||
parseChapters(data: ChapterData, novelPath: string) {
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
data.results.map((item: ChapterEntry) => {
|
||||
chapter.push({
|
||||
name: item.title,
|
||||
releaseTime: new Date(item.date).toISOString(),
|
||||
path: `${novelPath}/${item.number}`,
|
||||
chapterNumber: item.number,
|
||||
});
|
||||
});
|
||||
return chapter;
|
||||
}
|
||||
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
|
||||
const pagePath = novelPath.slice(6);
|
||||
const pageUrl = `https://api.rewayat.club/api/chapters/${pagePath}/?ordering=number&page=${page}`;
|
||||
const dataJson = await fetchApi(pageUrl).then(r => r.json());
|
||||
const chapters = this.parseChapters(dataJson, novelPath);
|
||||
return {
|
||||
chapters,
|
||||
};
|
||||
}
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const link = this.site + 'api/chapters/' + chapterUrl.slice(6);
|
||||
const result = await fetchApi(link).then(r => r.json());
|
||||
let chapterText = result.content
|
||||
.flat()
|
||||
.join('<br>')
|
||||
.replace(/\n/g, '')
|
||||
.replace(/<p>/g, '\n');
|
||||
chapterText = chapterText.trim();
|
||||
return chapterText;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
page: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const searchUrl = `https://api.rewayat.club/api/novels/?type=0&ordering=-num_chapters&page=${page}&search=${searchTerm}`;
|
||||
|
||||
const result = await fetchApi(searchUrl).then(r => r.json());
|
||||
return this.parseNovels(result);
|
||||
}
|
||||
|
||||
filters = {
|
||||
genre: {
|
||||
value: [],
|
||||
label: 'Genres',
|
||||
options: [
|
||||
{ label: 'كوميديا', value: '1' }, // Comedy
|
||||
{ label: 'أكشن', value: '2' }, // Action
|
||||
{ label: 'دراما', value: '3' }, // Drama
|
||||
{ label: 'فانتازيا', value: '4' }, // Fantasy
|
||||
{ label: 'مهارات القتال', value: '5' }, // Combat Skills
|
||||
{ label: 'مغامرة', value: '6' }, // Adventure
|
||||
{ label: 'رومانسي', value: '7' }, // Romance
|
||||
{ label: 'خيال علمي', value: '8' }, // Science Fiction
|
||||
{ label: 'الحياة المدرسية', value: '9' }, // School Life
|
||||
{ label: 'قوى خارقة', value: '10' }, // Super Powers
|
||||
{ label: 'سحر', value: '11' }, // Magic
|
||||
{ label: 'رياضة', value: '12' }, // Sports
|
||||
{ label: 'رعب', value: '13' }, // Horror
|
||||
{ label: 'حريم', value: '14' }, // Harem
|
||||
],
|
||||
type: FilterTypes.CheckboxGroup,
|
||||
},
|
||||
categories: {
|
||||
value: '0',
|
||||
label: 'الفئات',
|
||||
options: [
|
||||
{ label: 'جميع الروايات', value: '0' },
|
||||
{ label: 'مترجمة', value: '1' },
|
||||
{ label: 'مؤلفة', value: '2' },
|
||||
{ label: 'مكتملة', value: '3' },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
sortOptions: {
|
||||
value: '-num_chapters',
|
||||
label: 'الترتيب',
|
||||
options: [
|
||||
{ label: 'عدد الفصول - من أقل ﻷعلى', value: 'num_chapters' },
|
||||
{ label: 'عدد الفصول - من أعلى ﻷقل', value: '-num_chapters' },
|
||||
{ label: 'الاسم - من أقل ﻷعلى', value: 'english' },
|
||||
{ label: 'الاسم - من أعلى ﻷقل', value: '-english' },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new RewayatClub();
|
||||
|
||||
type NovelEntry = {
|
||||
arabic: string;
|
||||
english: string;
|
||||
about: string;
|
||||
poster_url: string;
|
||||
slug: string;
|
||||
original: boolean;
|
||||
complete: boolean;
|
||||
num_chapters: number;
|
||||
genre: {
|
||||
id: number;
|
||||
arabic: string;
|
||||
english: string;
|
||||
};
|
||||
novel?: {
|
||||
arabic: string;
|
||||
english: string;
|
||||
slug: string;
|
||||
poster: string;
|
||||
id: number;
|
||||
poster_url: string;
|
||||
original: boolean;
|
||||
};
|
||||
};
|
||||
type NovelData = {
|
||||
count?: number;
|
||||
next?: string;
|
||||
previous?: string;
|
||||
results: NovelEntry[];
|
||||
};
|
||||
type ChapterEntry = {
|
||||
number: number;
|
||||
title: string;
|
||||
date: string;
|
||||
uploader: {
|
||||
username: string;
|
||||
id: number;
|
||||
};
|
||||
hitcounts: {
|
||||
hits: number;
|
||||
id: number;
|
||||
};
|
||||
read: any[];
|
||||
};
|
||||
|
||||
type ChapterData = {
|
||||
count: number;
|
||||
next: string;
|
||||
previous: string;
|
||||
results: ChapterEntry[];
|
||||
};
|
||||
@@ -0,0 +1,306 @@
|
||||
import { CheerioAPI, load as parseHTML } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
|
||||
class Sunovels implements Plugin.PagePlugin {
|
||||
id = 'sunovels';
|
||||
name = 'Sunovels';
|
||||
version = '1.0.0';
|
||||
icon = 'src/ar/sunovels/icon.png';
|
||||
site = 'https://sunovels.com/';
|
||||
|
||||
parseNovels(loadedCheerio: CheerioAPI): Plugin.NovelItem[] {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
const imageUrlList: string[] = [];
|
||||
loadedCheerio('script').each((idx, ele) => {
|
||||
const regax = /\/uploads\/[^\s"]+/g;
|
||||
const scriptText = loadedCheerio(ele).text();
|
||||
const imageUrlMatched = scriptText.match(regax);
|
||||
if (imageUrlMatched) {
|
||||
imageUrlList.push(...imageUrlMatched);
|
||||
}
|
||||
});
|
||||
let counter = 0;
|
||||
loadedCheerio('.list-item').each((idx, ele) => {
|
||||
loadedCheerio(ele)
|
||||
.find('a')
|
||||
.each((idx, ele) => {
|
||||
const novelName = loadedCheerio(ele).find('h4').text().trim();
|
||||
const novelUrl =
|
||||
loadedCheerio(ele).attr('href')?.trim().replace(/^\/*/, '') || '';
|
||||
let novelCover = defaultCover;
|
||||
if (imageUrlList.length > 0) {
|
||||
novelCover = this.site + imageUrlList[counter].slice(1);
|
||||
} else {
|
||||
const imageUrl = loadedCheerio(ele).find('img').attr('src');
|
||||
novelCover = this.site + imageUrl?.slice(1);
|
||||
}
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl,
|
||||
};
|
||||
counter++;
|
||||
novels.push(novel);
|
||||
});
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
page: number,
|
||||
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions<Filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const pageCorrected = page - 1;
|
||||
let link = `${this.site}library?`;
|
||||
|
||||
if (filters) {
|
||||
if (
|
||||
Array.isArray(filters.categories.value) &&
|
||||
filters.categories.value.length > 0
|
||||
) {
|
||||
filters.categories.value.forEach((genre: string) => {
|
||||
link += `&category=${genre}`;
|
||||
});
|
||||
}
|
||||
if (filters.status.value !== '') {
|
||||
link += `&status=${filters.status.value}`;
|
||||
}
|
||||
}
|
||||
link += `&page=${pageCorrected}`;
|
||||
const body = await fetchApi(link).then(r => r.text());
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
|
||||
async parseNovel(
|
||||
novelUrl: string,
|
||||
): Promise<Plugin.SourceNovel & { totalPages: number }> {
|
||||
const result = await fetchApi(new URL(novelUrl, this.site).toString());
|
||||
const body = await result.text();
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel & { totalPages: number } = {
|
||||
path: novelUrl,
|
||||
name: loadedCheerio('div.main-head h3').text().trim() || 'Untitled',
|
||||
author: loadedCheerio('.novel-author').text().trim(),
|
||||
summary: loadedCheerio('section.info-section div.description p')
|
||||
.text()
|
||||
.trim(),
|
||||
totalPages: 1,
|
||||
chapters: [],
|
||||
};
|
||||
const statusWords = new Set(['مكتمل', 'جديد', 'مستمر']);
|
||||
const mainGenres = Array.from(loadedCheerio('div.categories li.tag'))
|
||||
.map(el => loadedCheerio(el).text().trim())
|
||||
.join(',');
|
||||
const statusGenre = Array.from(
|
||||
loadedCheerio('div.header-stats span').eq(3).find('strong'),
|
||||
)
|
||||
.map(el => loadedCheerio(el).text().trim())
|
||||
.filter(text => statusWords.has(text));
|
||||
novel.genres = `${statusGenre},${mainGenres}`;
|
||||
const statusText = Array.from(
|
||||
loadedCheerio('div.header-stats span').eq(3).find('strong'),
|
||||
)
|
||||
.map(el => loadedCheerio(el).text().trim())
|
||||
.filter(text => statusWords.has(text))
|
||||
.join();
|
||||
novel.status =
|
||||
{
|
||||
'جديد': 'Ongoing',
|
||||
'مكتمل': 'Completed',
|
||||
'مستمر': 'Ongoing',
|
||||
}[statusText] || 'Unknown';
|
||||
const imageUrl = loadedCheerio('div.img-container figure.cover img').attr(
|
||||
'src',
|
||||
);
|
||||
const imageUrlFull = this.site + imageUrl?.slice(1);
|
||||
novel.cover = imageUrlFull;
|
||||
const chapterNumberStr = loadedCheerio('div.header-stats span')
|
||||
.first()
|
||||
.text()
|
||||
.replace(/[^\d]/g, '');
|
||||
const chapterNumber = parseInt(chapterNumberStr, 10);
|
||||
const pageNumber = Math.ceil(chapterNumber / 50);
|
||||
novel.totalPages = pageNumber;
|
||||
|
||||
return novel;
|
||||
}
|
||||
parseChapters(data: { chapters: ChapterEntry[] }) {
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
data.chapters.map((item: ChapterEntry) => {
|
||||
chapter.push({
|
||||
name: item.chapterName,
|
||||
releaseTime: new Date(item.releaseTime).toISOString(),
|
||||
path: item.chapterUrl,
|
||||
chapterNumber: item.chapterNumber,
|
||||
});
|
||||
});
|
||||
return chapter;
|
||||
}
|
||||
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
|
||||
const numPage = parseInt(page, 10);
|
||||
const pageCorrected = numPage - 1;
|
||||
const pagePath = novelPath;
|
||||
const firstUrl = this.site + pagePath;
|
||||
const pageUrl = firstUrl + '?activeTab=chapters&page=' + pageCorrected;
|
||||
const body = await fetchApi(pageUrl).then(r => r.text());
|
||||
const loadedCheerio = parseHTML(body);
|
||||
const dataJson: {
|
||||
pages_count: string;
|
||||
chapters: ChapterEntry[];
|
||||
} = { pages_count: '', chapters: [] };
|
||||
const chaptersinfo: {
|
||||
chapterName: string;
|
||||
chapterUrl: string;
|
||||
releaseTime: string;
|
||||
chapterNumber: string | number;
|
||||
}[] = [];
|
||||
loadedCheerio('ul.chaptersList a').each((i, el) => {
|
||||
const chapterName: string = loadedCheerio(el).attr('title') ?? '';
|
||||
const chapterUrl = loadedCheerio(el)
|
||||
.attr('href')
|
||||
?.trim()
|
||||
.replace(/^\/*/, '');
|
||||
const dateAttr = loadedCheerio(el)
|
||||
.find('time.chapter-update')
|
||||
.attr('datetime');
|
||||
const date = new Date(dateAttr);
|
||||
const releaseTime = date.toISOString();
|
||||
const chapternumber = loadedCheerio(el)
|
||||
.find('strong.chapter-title')
|
||||
.text()
|
||||
.replace(/[^\d٠-٩]/g, '');
|
||||
const chapterNumber = parseInt(chapternumber, 10);
|
||||
chaptersinfo.push({
|
||||
chapterName: chapterName,
|
||||
chapterUrl: chapterUrl || '',
|
||||
releaseTime: releaseTime || '',
|
||||
chapterNumber: chapterNumber || '',
|
||||
});
|
||||
});
|
||||
const pagecount = loadedCheerio('ul.pagination a.active').text();
|
||||
dataJson.pages_count = pagecount;
|
||||
|
||||
dataJson.chapters = chaptersinfo;
|
||||
const chapters = this.parseChapters(dataJson);
|
||||
return {
|
||||
chapters,
|
||||
};
|
||||
}
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const result = await fetchApi(new URL(chapterUrl, this.site).toString());
|
||||
const body = await result.text();
|
||||
const loadedCheerio = parseHTML(body);
|
||||
let chapterText = '';
|
||||
loadedCheerio('div.chapter-content').each((idx, ele) => {
|
||||
loadedCheerio(ele)
|
||||
.find('p')
|
||||
.not('.d-none')
|
||||
.each((idx, textEle) => {
|
||||
chapterText +=
|
||||
loadedCheerio(textEle)
|
||||
.map((_, pEle) => loadedCheerio(pEle).text().trim())
|
||||
.get()
|
||||
.join(' ') + ' ';
|
||||
});
|
||||
});
|
||||
chapterText = chapterText.trim();
|
||||
return chapterText;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
page: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const searchUrl = `${this.site}search?page=${page}&title=${searchTerm}`;
|
||||
|
||||
const result = await fetchApi(searchUrl);
|
||||
const body = await result.text();
|
||||
const loadedCheerio = parseHTML(body);
|
||||
return this.parseNovels(loadedCheerio);
|
||||
}
|
||||
|
||||
filters = {
|
||||
categories: {
|
||||
value: [],
|
||||
label: 'التصنيفات',
|
||||
options: [
|
||||
{ label: 'Wuxia', value: 'Wuxia' },
|
||||
{ label: 'Xianxia', value: 'Xianxia' },
|
||||
{ label: 'XUANHUAN', value: 'XUANHUAN' },
|
||||
{ label: 'أصلية', value: 'أصلية' }, // Original
|
||||
{ label: 'أكشن', value: 'أكشن' }, // Action
|
||||
{ label: 'إثارة', value: 'إثارة' }, // Thriller
|
||||
{ label: 'إنتقال الى عالم أخر', value: 'إنتقال+الى+عالم+أخر' }, // Isekai
|
||||
{ label: 'إيتشي', value: 'إيتشي' }, // Ecchi
|
||||
{ label: 'الخيال العلمي', value: 'الخيال+العلمي' }, // Science Fiction
|
||||
{ label: 'بوليسي', value: 'بوليسي' }, // Detective
|
||||
{ label: 'تاريخي', value: 'تاريخي' }, // Historical
|
||||
{ label: 'تقمص شخصيات', value: 'تقمص+شخصيات' }, // Roleplaying
|
||||
{ label: 'جريمة', value: 'جريمة' }, // Crime
|
||||
{ label: 'جوسى', value: 'جوسى' }, // Josei
|
||||
{ label: 'حريم', value: 'حريم' }, // Harem
|
||||
{ label: 'حياة مدرسية', value: 'حياة+مدرسية' }, // School Life
|
||||
{ label: 'خارقة للطبيعة', value: 'خارقة+للطبيعة' }, // Supernatural
|
||||
{ label: 'خيالي', value: 'خيالي' }, // Fantasy
|
||||
{ label: 'دراما', value: 'دراما' }, // Drama
|
||||
{ label: 'رعب', value: 'رعب' }, // Horror
|
||||
{ label: 'رومانسي', value: 'رومانسي' }, // Romance
|
||||
{ label: 'سحر', value: 'سحر' }, // Magic
|
||||
{ label: 'سينن', value: 'سينن' }, // Seinen
|
||||
{ label: 'شريحة من الحياة', value: 'شريحة+من+الحياة' }, // Slice of Life
|
||||
{ label: 'شونين', value: 'شونين' }, // Shounen
|
||||
{ label: 'غموض', value: 'غموض' }, // Mystery
|
||||
{ label: 'فنون القتال', value: 'فنون+القتال' }, // Martial Arts
|
||||
{ label: 'قوى خارقة', value: 'قوى+خارقة' }, // Super Powers
|
||||
{ label: 'كوميدى', value: 'كوميدى' }, // Comedy
|
||||
{ label: 'مأساوي', value: 'مأساوي' }, // Tragedy
|
||||
{ label: 'ما بعد الكارثة', value: 'ما+بعد+الكارثة' }, // Post-Apocalypse
|
||||
{ label: 'مغامرة', value: 'مغامرة' }, // Adventure
|
||||
{ label: 'ميكا', value: 'ميكا' }, // Mecha
|
||||
{ label: 'ناضج', value: 'ناضج' }, // Mature
|
||||
{ label: 'نفسي', value: 'نفسي' }, // Psychological
|
||||
{ label: 'فانتازيا', value: 'فانتازيا' }, // Fantasy
|
||||
{ label: 'رياضة', value: 'رياضة' }, // Sports
|
||||
{ label: 'ابراج', value: 'ابراج' }, // Astrology
|
||||
{ label: 'الالهة', value: 'الالهة' }, // Deities
|
||||
{ label: 'شياطين', value: 'شياطين' }, // Demons
|
||||
{ label: 'السفر عبر الزمن', value: 'السفر+عبر+الزمن' }, // Time Travel
|
||||
{ label: 'رواية صينية', value: 'رواية+صينية' }, // Chinese Novel
|
||||
{ label: 'رواية ويب', value: 'رواية+ويب' }, // Web Novel
|
||||
{ label: 'لايت نوفل', value: 'لايت+نوفل' }, // Light Novel
|
||||
{ label: 'كوري', value: 'كوري' }, // Korean
|
||||
{ label: '+18', value: '%2B18' }, // +18
|
||||
{ label: 'إيسكاي', value: 'إيسكاي' }, // Isekai
|
||||
{ label: 'ياباني', value: 'ياباني' }, // Japanese
|
||||
{ label: 'مؤلفة', value: 'مؤلفة' }, // Authored
|
||||
],
|
||||
type: FilterTypes.CheckboxGroup,
|
||||
},
|
||||
status: {
|
||||
value: '',
|
||||
label: 'الحالة',
|
||||
options: [
|
||||
{ label: 'جميع الروايات', value: '' },
|
||||
{ label: 'مكتمل', value: 'Completed' },
|
||||
{ label: 'جديد', value: 'New' },
|
||||
{ label: 'مستمر', value: 'Ongoing' },
|
||||
],
|
||||
type: FilterTypes.Picker,
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new Sunovels();
|
||||
|
||||
type ChapterEntry = {
|
||||
chapterName: string;
|
||||
chapterUrl: string;
|
||||
releaseTime: string;
|
||||
chapterNumber: string | number;
|
||||
};
|
||||
Reference in New Issue
Block a user