Skip to content

Commit

Permalink
move manganexus from legacy (#252)
Browse files Browse the repository at this point in the history
* move manganexus from legacy

test is a bit lacking, cant get pictures, i suspect the CDN geoblock (usual PT-br blocking)

* add regionlocked tag

* Update MangaNexus.ts
  • Loading branch information
MikeZeDev authored Oct 15, 2023
1 parent e14d068 commit 9b0636c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
59 changes: 35 additions & 24 deletions web/src/engine/websites/legacy/MangaNexus.ts → web/src/engine/websites/MangaNexus.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,65 +1,76 @@
import { Tags } from '../../Tags';
import { Tags } from '../Tags';
import icon from './MangaNexus.webp';
import { Chapter, DecoratableMangaScraper, Manga, Page, type MangaPlugin } from '../../providers/MangaPlugin';
import * as Common from '../decorators/Common';
import { FetchJSON, FetchRequest, FetchWindowScript } from '../../FetchProvider';

let nextBuild = '';
import { Chapter, DecoratableMangaScraper, Manga, Page, type MangaPlugin } from '../providers/MangaPlugin';
import * as Common from './decorators/Common';
import { FetchJSON, FetchRequest, FetchWindowScript } from '../FetchProvider';

type JSONMangas = {
pageProps: {
mangas: {
items :{ id: string, name: string, slug: string } []
items: APIManga[]
}
}
}

type JSONManga = {
pageProps: {
manga: { id: string, name: string, slug: string }
chapters: { id: string, number: string, slug: string, name: string }[]
manga: APIManga,
chapters: APIChapter[]
}
}

type JSONChapter = {
pageProps: {
manga: { id: string, name: string, slug: string }
chapter: {
id: string, number: string, slug: string, name: string, mangaId: string,
pages: string[]
}
manga: APIManga,
chapter: APIChapter
}
}

type APIManga = {
id: string,
name: string,
slug : string
}

type APIChapter = {
id: string,
number: string,
slug: string,
name: string,
mangaId: string,
pages : string[],
}

type NEXTDATA = {
buildId: string
}

@Common.ImageAjax()

export default class extends DecoratableMangaScraper {
private nextBuild = '';

public constructor() {
super('manganexus', `MangaNexus`, 'https://manganexus.net', Tags.Language.Portuguese, Tags.Media.Manga, Tags.Media.Manhua, Tags.Media.Manhwa, Tags.Source.Aggregator);
super('manganexus', `MangaNexus`, 'https://manganexus.net', Tags.Language.Portuguese, Tags.Media.Manga, Tags.Media.Manhua, Tags.Media.Manhwa, Tags.Source.Aggregator, Tags.Accessibility.RegionLocked);
}
public override get Icon() {
return icon;
}

public override async Initialize(): Promise<void> {
const request = new FetchRequest(this.URI.href);
const data = await FetchWindowScript<NEXTDATA>(request, `__NEXT_DATA__`);
nextBuild = data.buildId;
const data = await FetchWindowScript<NEXTDATA>(request, `__NEXT_DATA__`, 2000);
this.nextBuild = data.buildId;
}

public override ValidateMangaURL(url: string): boolean {
return /https?:\/\/manganexus\.net\/manga\//.test(url);
}

public override async FetchManga(provider: MangaPlugin, _url : string): Promise<Manga> {
const slug = _url.split('/').pop();
const url = new URL('/_next/data/' + nextBuild + '/manga/' + slug + '.json?slug=' + slug, this.URI).href;
const request = new FetchRequest(url);
public override async FetchManga(provider: MangaPlugin, url : string): Promise<Manga> {
const slug = url.split('/').pop();
const jsonUrl = new URL(`/_next/data/${ this.nextBuild }/manga/${ slug }.json?slug=${ slug }`, this.URI).href;
const request = new FetchRequest(jsonUrl);
const data = await FetchJSON<JSONManga>(request);
return new Manga(this, provider, slug, data.pageProps.manga.name.trim());
}
Expand All @@ -75,7 +86,7 @@ export default class extends DecoratableMangaScraper {

private async getMangasFromPage(page: number, provider: MangaPlugin): Promise<Manga[]> {
try {
const url = new URL('/_next/data/' + nextBuild + '/lista-de-mangas.json?p=' + page, this.URI).href;
const url = new URL(`/_next/data/${this.nextBuild}/lista-de-mangas.json?p=${page}`, this.URI).href;
const request = new FetchRequest(url);
const data = await FetchJSON<JSONMangas>(request);
return data.pageProps.mangas.items.map(element => new Manga(this, provider, element.slug, element.name.trim()));
Expand All @@ -87,7 +98,7 @@ export default class extends DecoratableMangaScraper {

public override async FetchChapters(manga: Manga): Promise<Chapter[]> {
const slug = manga.Identifier;
const url = new URL('/_next/data/' + nextBuild + '/manga/' + slug + '.json?slug=' + slug, this.URI).href;
const url = new URL(`/_next/data/${this.nextBuild}/manga/${ slug }.json?slug=${ slug }`, this.URI).href;
const request = new FetchRequest(url);
const data = await FetchJSON<JSONManga>(request);
return data.pageProps.chapters.map(chap => {
Expand All @@ -98,7 +109,7 @@ export default class extends DecoratableMangaScraper {

public override async FetchPages(chapter: Chapter): Promise<Page[]> {
const mangaSlug = chapter.Parent.Identifier;
const url = new URL('/_next/data/' + nextBuild + '/manga/' + mangaSlug + '/capitulo/' + chapter.Identifier + '.json', this.URI).href;
const url = new URL(`/_next/data/${this.nextBuild}/manga/${mangaSlug}/capitulo/${ chapter.Identifier}.json`, this.URI).href;
const request = new FetchRequest(url);
const data = await FetchJSON<JSONChapter>(request);
return data.pageProps.chapter.pages.map(page => new Page(this, chapter, new URL(page)));
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions web/src/engine/websites/MangaNexus_e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { TestFixture, type Config } from '../../../test/WebsitesFixture';

const config: Config = {
plugin: {
id: 'manganexus',
title: 'MangaNexus'
},
container: {
url: 'https://manganexus.net/manga/the-return-of-the-iron-blood-sword-hound-17339',
id: 'the-return-of-the-iron-blood-sword-hound-17339',
title: 'The Return of the Iron-Blood Sword Hound'
},
child: {
id: '1',
title: 'Capítulo 1'
},
/* Cant get picture, chances are its geoblocked by CF // TODO: FIX the test with picture
entry: {
index: 0,
size: 188_488,
type: 'image/jpeg'
}*/
};

const fixture = new TestFixture(config);
describe(fixture.Name, () => fixture.AssertWebsite());
2 changes: 1 addition & 1 deletion web/src/engine/websites/_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export { default as MangaLike } from './MangaLike';
export { default as MangaLover } from './MangaLover';
export { default as MangaMonarca } from './MangaMonarca';
export { default as MangaNel } from './MangaNel';
export { default as MangaNexus } from './MangaNexus';
export { default as MangaOkur } from './MangaOkur';
export { default as MangaPill } from './MangaPill';
export { default as MangaRead } from './MangaRead';
Expand Down Expand Up @@ -633,7 +634,6 @@ export { default as MangaNeloInfo } from './legacy/MangaNeloInfo';
export { default as MangaNeloMe } from './legacy/MangaNeloMe';
export { default as Manganelos } from './legacy/Manganelos';
export { default as MangaNeloToday } from './legacy/MangaNeloToday';
export { default as MangaNexus } from './legacy/MangaNexus';
export { default as MangaOku } from './legacy/MangaOku';
export { default as MangaOnline } from './legacy/MangaOnline';
export { default as MangaOnlineBR } from './legacy/MangaOnlineBR';
Expand Down

0 comments on commit 9b0636c

Please sign in to comment.