Skip to content

Commit

Permalink
add RidiBooks (#410)
Browse files Browse the repository at this point in the history
* add RidiBooks

* Update RidiBooks.ts

* Update _index.ts

* Update RidiBooks.ts
  • Loading branch information
MikeZeDev authored Dec 16, 2023
1 parent 883c9a0 commit 584ab45
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
114 changes: 114 additions & 0 deletions web/src/engine/websites/RidiBooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { Tags } from '../Tags';
import icon from './RidiBooks.webp';
import { Chapter, DecoratableMangaScraper, Manga, type MangaPlugin, Page } from '../providers/MangaPlugin';
import * as Common from './decorators/Common';
import { FetchJSON, FetchRequest, FetchWindowScript } from '../FetchProvider';

type APIMangas = {
data: {
items: APIManga[]
pagination: {
nextPage: string,
}
}
}

type APIManga = {
book: {
bookId: string,
title: string
serial: {
title: string
}
}
}

type APIPages = {
data: {
pages: {
src: string
}[]
}
success: boolean,

}

type ChapterID = {
id: string,
title: string
}

type BookDetail = {
series_id: string,
series_title: string
};

@Common.ImageAjax()
export default class extends DecoratableMangaScraper {
private apiUrl = 'https://api.ridibooks.com';

public constructor() {
super('ridibooks', 'RidiBooks', 'https://ridibooks.com', Tags.Media.Manhwa, Tags.Language.Korean, Tags.Source.Official);
}

public override get Icon() {
return icon;
}

public override ValidateMangaURL(url: string): boolean {
return new RegExp(`^${this.URI.origin}/books/\\d+`).test(url);
}

public override async FetchManga(provider: MangaPlugin, url: string): Promise<Manga> {
const data = await FetchWindowScript<BookDetail>(new FetchRequest(url), 'bookDetail');
return new Manga(this, provider, data.series_id, data.series_title.trim());
}

public override async FetchMangas(provider: MangaPlugin): Promise<Manga[]> {
const mangaList : Manga[] = [];
let uri : URL | null = new URL('/v2/category/books', this.apiUrl);

uri.search = new URLSearchParams({
category_id: '1600',
tab: 'books',
platform: 'web',
order_by: 'popular',
limit: '60',
offset: '0'
}).toString();

while (uri) {
const { data } = await FetchJSON<APIMangas>(new FetchRequest(uri.href));
const mangas = data.items.map(({ book }) => {
const title = book.serial?.title ? book.serial.title.trim() : book.title.trim();
return new Manga(this, provider, book.bookId, title);
});
mangaList.push(...mangas);
uri = data.pagination.nextPage && new URL(data.pagination.nextPage, this.apiUrl);
}
return mangaList.distinct();
}

public override async FetchChapters(manga: Manga): Promise<Chapter[]> {
const uri = new URL(`/books/${manga.Identifier}`, this.URI);
const data = await FetchWindowScript<ChapterID[]>(new FetchRequest(uri.href), 'seriesBookListJson');
return data.map(chapter => {
const title = chapter.title.replace(manga.Title, '').trim();
return new Chapter(this, manga, chapter.id, title != '' ? title : chapter.title.trim());
});
}

public override async FetchPages(chapter: Chapter): Promise<Page[]> {
const uri = new URL('/api/web-viewer/generate', this.URI);
const data = await FetchJSON<APIPages>(new FetchRequest(uri.href, {
method: 'POST',
body: JSON.stringify({
book_id: chapter.Identifier
}),
headers: {
'Content-Type': 'application/json',
},
}));
return data.success ? data.data.pages.map(page => new Page(this, chapter, new URL(page.src))) : [];
}
}
Binary file added web/src/engine/websites/RidiBooks.webp
Binary file not shown.
26 changes: 26 additions & 0 deletions web/src/engine/websites/RidiBooks_e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { TestFixture } from '../../../test/WebsitesFixture';

const config = {
plugin: {
id: 'ridibooks',
title: 'RidiBooks'
},
container: {
url: 'https://ridibooks.com/books/5207000001',
id: '5207000001',
title: '품격을 배반한다',
timeout: 10000
},
child: {
id: '5207000001',
title: '프롤로그'
},
entry: {
index: 0,
size: 164_679,
type: 'image/jpeg'
}
};

const fixture = new TestFixture(config);
describe(fixture.Name, () => fixture.AssertWebsite());
1 change: 1 addition & 0 deletions web/src/engine/websites/_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export { default as ReaperScansFR } from './ReaperScansFR';
export { default as ReaperScansTR } from './ReaperScansTR';
export { default as ResetScans } from './ResetScans';
export { default as Retsu } from './Retsu';
export { default as RidiBooks } from './RidiBooks';
export { default as RightDarkScan } from './RightDarkScan';
export { default as Rio2Manga } from './Rio2Manga';
export { default as RizzComics } from './RizzComics';
Expand Down

0 comments on commit 584ab45

Please sign in to comment.