From 9b0636c0590815dc19471a87f56c7ff7cd1337ab Mon Sep 17 00:00:00 2001 From: MikeZeDev Date: Sun, 15 Oct 2023 10:00:57 +0000 Subject: [PATCH] move manganexus from legacy (#252) * 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 --- .../websites/{legacy => }/MangaNexus.ts | 59 +++++++++++------- .../websites/{legacy => }/MangaNexus.webp | Bin web/src/engine/websites/MangaNexus_e2e.ts | 26 ++++++++ web/src/engine/websites/_index.ts | 2 +- 4 files changed, 62 insertions(+), 25 deletions(-) rename web/src/engine/websites/{legacy => }/MangaNexus.ts (65%) mode change 100755 => 100644 rename web/src/engine/websites/{legacy => }/MangaNexus.webp (100%) mode change 100755 => 100644 create mode 100644 web/src/engine/websites/MangaNexus_e2e.ts diff --git a/web/src/engine/websites/legacy/MangaNexus.ts b/web/src/engine/websites/MangaNexus.ts old mode 100755 new mode 100644 similarity index 65% rename from web/src/engine/websites/legacy/MangaNexus.ts rename to web/src/engine/websites/MangaNexus.ts index ffeab9155e..26a179c2da --- a/web/src/engine/websites/legacy/MangaNexus.ts +++ b/web/src/engine/websites/MangaNexus.ts @@ -1,36 +1,46 @@ -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 } @@ -38,9 +48,10 @@ type NEXTDATA = { @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; @@ -48,18 +59,18 @@ export default class extends DecoratableMangaScraper { public override async Initialize(): Promise { const request = new FetchRequest(this.URI.href); - const data = await FetchWindowScript(request, `__NEXT_DATA__`); - nextBuild = data.buildId; + const data = await FetchWindowScript(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 { - 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 { + 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(request); return new Manga(this, provider, slug, data.pageProps.manga.name.trim()); } @@ -75,7 +86,7 @@ export default class extends DecoratableMangaScraper { private async getMangasFromPage(page: number, provider: MangaPlugin): Promise { 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(request); return data.pageProps.mangas.items.map(element => new Manga(this, provider, element.slug, element.name.trim())); @@ -87,7 +98,7 @@ export default class extends DecoratableMangaScraper { public override async FetchChapters(manga: Manga): Promise { 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(request); return data.pageProps.chapters.map(chap => { @@ -98,7 +109,7 @@ export default class extends DecoratableMangaScraper { public override async FetchPages(chapter: Chapter): Promise { 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(request); return data.pageProps.chapter.pages.map(page => new Page(this, chapter, new URL(page))); diff --git a/web/src/engine/websites/legacy/MangaNexus.webp b/web/src/engine/websites/MangaNexus.webp old mode 100755 new mode 100644 similarity index 100% rename from web/src/engine/websites/legacy/MangaNexus.webp rename to web/src/engine/websites/MangaNexus.webp diff --git a/web/src/engine/websites/MangaNexus_e2e.ts b/web/src/engine/websites/MangaNexus_e2e.ts new file mode 100644 index 0000000000..664247996b --- /dev/null +++ b/web/src/engine/websites/MangaNexus_e2e.ts @@ -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()); \ No newline at end of file diff --git a/web/src/engine/websites/_index.ts b/web/src/engine/websites/_index.ts index a1e225fab4..a6934313bf 100755 --- a/web/src/engine/websites/_index.ts +++ b/web/src/engine/websites/_index.ts @@ -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'; @@ -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';