Skip to content

Commit

Permalink
Add RuManhua (#766)
Browse files Browse the repository at this point in the history
* Add RuManhua

manga-download/hakuneko#7320

* requested changes
  • Loading branch information
MikeZeDev committed Sep 21, 2024
1 parent 11c62dc commit fe50b36
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
87 changes: 87 additions & 0 deletions web/src/engine/websites/RuManhua.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Tags } from '../Tags';
import icon from './RuManhua.webp';
import { Chapter, DecoratableMangaScraper, Manga, type MangaPlugin } from '../providers/MangaPlugin';
import * as Common from './decorators/Common';
import { FetchCSS, FetchJSON } from '../platform/FetchProvider';

type APIResponse<T> = {
data : T | string
}

type APIManga = {
id: string,
bookName: string
}

type APIChapter = {
chapterid: string,
chaptername: string
}

const pagesScript = `[... document.querySelectorAll('div.chapter-img-box img')].map(image=> image.dataset.src || image.src);`;

@Common.PagesSinglePageJS(pagesScript, 1500)
@Common.ImageAjax()
export default class extends DecoratableMangaScraper {

public constructor() {
super('rumanhua', 'RuManhua', 'https://rumanhua.com', Tags.Media.Manhwa, Tags.Media.Manhua, Tags.Language.Chinese, Tags.Source.Aggregator);
}

public override get Icon() {
return icon;
}

public override ValidateMangaURL(url: string): boolean {
return new RegExpSafe(`^${this.URI.origin}/[^/]+/$`).test(url);
}

public override async FetchManga(provider: MangaPlugin, url: string): Promise<Manga> {
const title = (await FetchCSS(new Request(url), 'div.book-name h1.name')).shift().textContent.trim();
const id = url.split('/').at(-2);
return new Manga(this, provider, id, title);
}

public override async FetchMangas(provider: MangaPlugin): Promise<Manga[]> {
const mangaList: Manga[] = [];
for (let page = 1, run = true; run; page++) {
const mangas = await this.GetMangasFromPage(page, provider);
mangas.length > 0 ? mangaList.push(...mangas) : run = false;
}
return mangaList;
}

private async GetMangasFromPage(page: number, provider: MangaPlugin): Promise<Manga[]> {
const { data } = await FetchJSON<APIResponse<APIManga[]>>(new Request(new URL('/data/sort', this.URI), {
method: 'POST',
body: `s=1&p=${page}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Origin: this.URI.origin,
Referer: this.URI.href,
'X-Requested-With': 'XMLHttpRequest'
}
}));
return data instanceof Array ? (data as APIManga[]).map(item => new Manga(this, provider, item.id, item.bookName)): [];
}

public override async FetchChapters(manga: Manga): Promise<Chapter[]> {
const chapterList = await Common.FetchChaptersSinglePageCSS.call(this, manga, 'div.chaplist-box ul li a');
const { data } = await FetchJSON<APIResponse<APIChapter[]>>(new Request(new URL('/morechapter', this.URI), {
method: 'POST',
body: `id=${manga.Identifier}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Origin: this.URI.origin,
Referer: this.URI.href,
'X-Requested-With': 'XMLHttpRequest'
}
}));

if (data instanceof Array) {
chapterList.push(...data.map(chapter => new Chapter(this, manga, `/${manga.Identifier}/${chapter.chapterid}.html`, chapter.chaptername)));
}
return chapterList;
}

}
Binary file added web/src/engine/websites/RuManhua.webp
Binary file not shown.
26 changes: 26 additions & 0 deletions web/src/engine/websites/RuManhua_e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe } from 'vitest';
import { TestFixture } from '../../../test/WebsitesFixture';

const config = {
plugin: {
id: 'rumanhua',
title: 'RuManhua'
},
container: {
url: 'https://rumanhua.com/IVppgVq/',
id: 'IVppgVq',
title: '我是怪兽大主宰'
},
child: {
id: '/IVppgVq/OagmJLY.html',
title: '第79话 吃龙心'
},
entry: {
index: 5,
size: 57_787,
type: 'image/jpeg'
}
};

const fixture = new TestFixture(config);
describe(fixture.Name, async () => (await fixture.Connect()).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 @@ -558,6 +558,7 @@ export { default as RizzComics } from './RizzComics';
export { default as RokuHentai } from './RokuHentai';
export { default as RomantikManga } from './RomantikManga';
export { default as RudraScans } from './RudraScans';
export { default as RuManhua } from './RuManhua';
export { default as RuyaManga } from './RuyaManga';
export { default as S2Manga } from './S2Manga';
export { default as Sadscans } from './Sadscans';
Expand Down

0 comments on commit fe50b36

Please sign in to comment.