From 8540e2e05ec5ea702fcb18d1268c3cfb48835a93 Mon Sep 17 00:00:00 2001 From: aleganza Date: Mon, 26 Feb 2024 04:13:44 +0100 Subject: [PATCH] fix: fetch all episodes info in AnimeUnity --- dist/providers/anime/animeunity.d.ts | 3 +- dist/providers/anime/animeunity.js | 30 ++++++++--- dist/providers/anime/animeunity.js.map | 2 +- docs/providers/animeunity.md | 75 +++++++++++++++----------- package.json | 3 +- src/providers/anime/animeunity.ts | 27 ++++++++-- test/anime/animeunity.test.ts | 7 +-- 7 files changed, 98 insertions(+), 49 deletions(-) diff --git a/dist/providers/anime/animeunity.d.ts b/dist/providers/anime/animeunity.d.ts index 5efec3656..04e4bdb20 100644 --- a/dist/providers/anime/animeunity.d.ts +++ b/dist/providers/anime/animeunity.d.ts @@ -10,8 +10,9 @@ declare class AnimeUnity extends AnimeParser { search: (query: string) => Promise>; /** * @param id Anime id + * @param page Page number */ - fetchAnimeInfo: (id: string) => Promise; + fetchAnimeInfo: (id: string, page?: number) => Promise; /** * * @param episodeId Episode id diff --git a/dist/providers/anime/animeunity.js b/dist/providers/anime/animeunity.js index f4499b4de..656d4124a 100644 --- a/dist/providers/anime/animeunity.js +++ b/dist/providers/anime/animeunity.js @@ -44,29 +44,45 @@ class AnimeUnity extends models_1.AnimeParser { }; /** * @param id Anime id + * @param page Page number */ - this.fetchAnimeInfo = async (id) => { + this.fetchAnimeInfo = async (id, page = 1) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; const url = `${this.baseUrl}/anime/${id}`; + const episodesPerPage = 120; + const lastPageEpisode = page * episodesPerPage; + const firstPageEpisode = lastPageEpisode - 119; + const url2 = `${this.baseUrl}/info_api/${id}/1?start_range=${firstPageEpisode}&end_range=${lastPageEpisode}`; try { const res = await this.client.get(url); const $ = (0, cheerio_1.load)(res.data); + const totalEpisodes = parseInt((_b = (_a = $('video-player')) === null || _a === void 0 ? void 0 : _a.attr('episodes_count')) !== null && _b !== void 0 ? _b : '0'); + const totalPages = Math.round(totalEpisodes / 120) + 1; + if (page < 1 || page > totalPages) + throw new Error(`Argument 'page' for ${id} must be between 1 and ${totalPages}!`); const animeInfo = { + currentPage: page, + hasNextPage: totalPages > page, + totalPages: totalPages, id: id, - title: (_a = $('h1.title')) === null || _a === void 0 ? void 0 : _a.text().trim(), + title: (_c = $('h1.title')) === null || _c === void 0 ? void 0 : _c.text().trim(), url: url, - alID: (_e = (_d = (_c = (_b = $('.banner')) === null || _b === void 0 ? void 0 : _b.attr('style')) === null || _c === void 0 ? void 0 : _c.split('/')) === null || _d === void 0 ? void 0 : _d.pop()) === null || _e === void 0 ? void 0 : _e.split('-')[0], - genres: (_g = (_f = $('.info-wrapper.pt-3.pb-3 small')) === null || _f === void 0 ? void 0 : _f.map((i, element) => { + alID: (_g = (_f = (_e = (_d = $('.banner')) === null || _d === void 0 ? void 0 : _d.attr('style')) === null || _e === void 0 ? void 0 : _e.split('/')) === null || _f === void 0 ? void 0 : _f.pop()) === null || _g === void 0 ? void 0 : _g.split('-')[0], + genres: (_j = (_h = $('.info-wrapper.pt-3.pb-3 small')) === null || _h === void 0 ? void 0 : _h.map((i, element) => { return $(element).text().replace(',', '').trim(); - }).toArray()) !== null && _g !== void 0 ? _g : undefined, - totalEpisodes: parseInt((_j = (_h = $('video-player')) === null || _h === void 0 ? void 0 : _h.attr('episodes_count')) !== null && _j !== void 0 ? _j : '0'), + }).toArray()) !== null && _j !== void 0 ? _j : undefined, + totalEpisodes: totalEpisodes, image: (_k = $('img.cover')) === null || _k === void 0 ? void 0 : _k.attr('src'), // image: $('meta[property="og:image"]')?.attr('content'), cover: (_m = (_l = $('.banner')) === null || _l === void 0 ? void 0 : _l.attr('src')) !== null && _m !== void 0 ? _m : (_p = (_o = $('.banner')) === null || _o === void 0 ? void 0 : _o.attr('style')) === null || _p === void 0 ? void 0 : _p.replace('background: url(', ''), description: $('.description').text().trim(), episodes: [] }; - const items = JSON.parse("" + $('video-player').attr('episodes') + ""); + // fetch episodes method 1 (only first page can be fetchedd) + // const items = JSON.parse("" + $('video-player').attr('episodes') + "") + // fetch episodes method 2 (all pages can be fetched) + const res2 = await this.client.get(url2); + const items = res2.data.episodes; for (const i in items) { (_q = animeInfo.episodes) === null || _q === void 0 ? void 0 : _q.push({ id: `${id}/${items[i].id}`, diff --git a/dist/providers/anime/animeunity.js.map b/dist/providers/anime/animeunity.js.map index 9170d333f..6f30e7213 100644 --- a/dist/providers/anime/animeunity.js.map +++ b/dist/providers/anime/animeunity.js.map @@ -1 +1 @@ -{"version":3,"file":"animeunity.js","sourceRoot":"","sources":["../../../src/providers/anime/animeunity.ts"],"names":[],"mappings":";;AAAA,qCAAwC;AAExC,yCAQsB;AAEtB,MAAM,UAAW,SAAQ,oBAAW;IAApC;;QACsB,SAAI,GAAG,YAAY,CAAC;QACnB,YAAO,GAAG,2BAA2B,CAAC;QACtC,SAAI,GAAG,6CAA6C,CAAC;QACrD,cAAS,GAAG,kBAAkB,CAAC;QAElD;;WAEG;QACM,WAAM,GAAG,KAAK,EAAE,KAAa,EAAkC,EAAE;;YACtE,IAAI,CAAC;gBACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,mBAAmB,KAAK,EAAE,CAAC,CAAC;gBAC7E,MAAM,CAAC,GAAG,IAAA,cAAI,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAEzB,IAAI,CAAC,CAAC;oBAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;gBAE/B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAA;gBAEjE,MAAM,YAAY,GAGd;oBACA,WAAW,EAAE,KAAK;oBAClB,OAAO,EAAE,EAAE;iBACd,CAAC;gBAEF,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE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Ac,CAAA;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC,CAAC;QAEF;;;WAGG;QACM,wBAAmB,GAAG,CAAC,SAAiB,EAA6B,EAAE;YAC5E,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC/C,CAAC,CAAC;IACN,CAAC;CAAA;AAED,kBAAe,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"animeunity.js","sourceRoot":"","sources":["../../../src/providers/anime/animeunity.ts"],"names":[],"mappings":";;AAAA,qCAAwC;AAExC,yCAQsB;AAEtB,MAAM,UAAW,SAAQ,oBAAW;IAApC;;QACsB,SAAI,GAAG,YAAY,CAAC;QACnB,YAAO,GAAG,2BAA2B,CAAC;QACtC,SAAI,GAAG,6CAA6C,CAAC;QACrD,cAAS,GAAG,kBAAkB,CAAC;QAElD;;WAEG;QACM,WAAM,GAAG,KAAK,EAAE,KAAa,EAAkC,EAAE;;YACtE,IAAI,CAAC;gBACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,mBAAmB,KAAK,EAAE,CAAC,CAAC;gBAC7E,MAAM,CAAC,GAAG,IAAA,cAAI,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAEzB,IAAI,CAAC,CAAC;oBAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;gBAE/B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAA;gBAEjE,MAAM,YAAY,GAGd;oBACA,WAAW,EAAE,KAAK;oBAClB,OAAO,EAAE,EAAE;iBACd,CAAC;gBAEF,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;o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AAC,CAAC,CAAA;oBAC9F,MAAM,UAAU,GAAG,MAAA,CAAC,CAAC,iCAAiC,CAAC,CAAC,IAAI,EAAE,0CAAE,KAAK,CAAC,qBAAqB,EAAG,CAAC,CAAC,CAAA;oBAChG,MAAM,OAAO,GAAG,MAAA,CAAC,CAAC,iCAAiC,CAAC,CAAC,IAAI,EAAE,0CAAE,KAAK,CAAC,kBAAkB,EAAG,CAAC,CAAC,CAAA;oBAE1F,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC;wBACxB,GAAG,EAAE,GAAG,MAAM,UAAU,KAAK,cAAc,SAAS,cAAc,SAAS,cAAc,SAAS,eAAe,UAAU,qBAAqB,OAAO,EAAE;wBACzJ,MAAM,EAAE,IAAI;qBACf,CAAC,CAAA;oBAEF,cAAc,CAAC,QAAQ,GAAG,MAAA,MAAA,CAAC,CAAC,wCAAwC,CAAC,CAAC,IAAI,EAAE,0CAAE,KAAK,CAAC,sBAAsB,EAAG,CAAC,CAAC,0CAAE,QAAQ,EAAE,CAAA;gBAC/H,CAAC;gBAED,OAAO,cAAc,CAAA;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC,CAAC;QAEF;;;WAGG;QACM,wBAAmB,GAAG,CAAC,SAAiB,EAA6B,EAAE;YAC5E,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC/C,CAAC,CAAC;IACN,CAAC;CAAA;AAED,kBAAe,UAAU,CAAA"} \ No newline at end of file diff --git a/docs/providers/animeunity.md b/docs/providers/animeunity.md index bfecb84e2..8953eb14b 100644 --- a/docs/providers/animeunity.md +++ b/docs/providers/animeunity.md @@ -21,7 +21,7 @@ const animeunity = new ANIME.AnimeUnity(); | query | `string` | query to search for. (*In this case, We're searching for `Jujutsu Kaisen 2`*) | ```ts -animeunity.search("Jujutsu Kaisen 2").then(data => { +animeunity.search("One Piece").then(data => { console.log(data); }) ``` @@ -33,21 +33,23 @@ output: hasNextPage: false, results: [ { - id: '4197-jujutsu-kaisen-2', - title: 'Jujutsu Kaisen 2', - url: 'https://www.animeunity.to/anime/4197-jujutsu-kaisen-2', - image: 'https://cdn.myanimelist.net/images/anime/1732/139397.jpg', - cover: 'https://s4.anilist.co/file/anilistcdn/media/anime/banner/145064-S7qAgxf6kMrW.jpg', + id: '12-one-piece', + title: 'One Piece', + url: 'https://www.animeunity.to/anime/12-one-piece', + image: 'https://cdn.myanimelist.net/images/anime/1810/139965.jpg', + cover: 'https://s4.anilist.co/file/anilistcdn/media/anime/banner/21-wf37VakJmZqs.jpg', subOrDub: 'sub' }, { - id: '4786-jujutsu-kaisen-2-ita', - title: 'Jujutsu Kaisen 2 (ITA)', - url: 'https://www.animeunity.to/anime/4786-jujutsu-kaisen-2-ita', - image: 'https://cdn.myanimelist.net/images/anime/1732/139397.jpg', - cover: 'https://s4.anilist.co/file/anilistcdn/media/anime/banner/145064-kH9vbOEitIhl.jpg', - subOrDub: 'dub' - } + id: '4123-one-piece-film-red', + title: 'One Piece Movie 15: Red', + url: 'https://www.animeunity.to/anime/4123-one-piece-film-red', + image: 'https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx141902-fTyoTk8F8qOl.jpg', + cover: 'https://s4.anilist.co/file/anilistcdn/media/anime/banner/141902-SvnRSXnN7DWC.jpg', + subOrDub: 'sub' + }, + {...}, + ... ] } ``` @@ -59,10 +61,16 @@ output: | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------- | | id | `string` | takes anime id as a parameter. (*anime id can be found in the anime search results or anime info object*) | +| page? | `number` | takes page number as a parameter | + +Why page number? AnimeUnity provides only 120 episodes at a time, how to use: +- page: 1, you'll get episodes info from 1 to 120; +- page: 4, you'll get episodes info from 361 to 480. +If no page number is passed, the first page will be fetched. ```ts -animesaturn.fetchAnimeInfo("4197-jujutsu-kaisen-2").then(data => { +animesaturn.fetchAnimeInfo("12-one-piece", 3).then(data => { console.log(data); }) ``` @@ -71,25 +79,28 @@ returns a promise which resolves into an anime info object (including the episod output: ```js { - id: '4197-jujutsu-kaisen-2', - title: 'Jujutsu Kaisen 2', - url: 'https://www.animeunity.to/anime/4197-jujutsu-kaisen-2', - alID: '145064', - genres: [ 'Action', 'Drama', 'Fantasy', 'School', 'Shounen', 'Supernatural' ], - totalEpisodes: 23, - image: 'https://img.animeunity.to/anime/139397.jpg', - cover: 'https://img.animeunity.to/anime/145064-S7qAgxf6kMrW.jpg', - description: 'Seconda stagione di Jujutsu Kaisen', + currentPage: 3, + hasNextPage: true, + totalPages: 10, + id: '12-one-piece', + title: 'One Piece', + url: 'https://www.animeunity.to/anime/12-one-piece', + alID: '21', + genres: [ 'Action', 'Adventure', 'Comedy', 'Drama', 'Fantasy', 'Shounen' ], + totalEpisodes: 1095, + image: 'https://img.animeunity.to/anime/139965.jpg', + cover: 'https://img.animeunity.to/anime/21-wf37VakJmZqs.jpg', + description: `Monkey D. Rufy รจ un giovane pirata sognatore che...`, episodes: [ { - id: '4197-jujutsu-kaisen-2/71631', - number: 1, - url: 'https://www.animeunity.to/anime/4197-jujutsu-kaisen-2/71631' + id: '12-one-piece/6225', + number: 241, + url: 'https://www.animeunity.to/anime/12-one-piece/6225' }, { - id: '4197-jujutsu-kaisen-2/71717', - number: 2, - url: 'https://www.animeunity.to/anime/4197-jujutsu-kaisen-2/71717' + id: '12-one-piece/6226', + number: 242, + url: 'https://www.animeunity.to/anime/12-one-piece/6226' }, {...}, ... @@ -108,7 +119,7 @@ output: In this example, we're getting the sources for the first episode of Jujutsu Kaisen 2. ```ts -animesaturn.fetchEpisodeSources("4197-jujutsu-kaisen-2/71631").then(data => { +animesaturn.fetchEpisodeSources("12-one-piece/6225").then(data => { console.log(data); }) ``` @@ -119,11 +130,11 @@ output: { sources: [ { - url: 'https://vixcloud.co/playlist/159548?token=EgLqNTtoByEjBWoxBnjRhA&token360p=&token480p=SqM7OBHTk2W6iebd18uvrg&token720p=sg9FbKumN1aPHyb1XA0F8w&token1080p=&referer=&expires=1709384998', + url: 'https://vixcloud.co/playlist/163605?token=k3foZ2UVnW80vOgGNXswJA&token360p=&token480p=1JYOeJihE4a9IzvY93O4Fg&token720p=a99ZCcvPp2r-dPhU0vGJ3g&token1080p=&referer=&expires=1714101108', isM3U8: true } ], - download: 'https://au-d1-03.scws-content.net/download/3/d/15/d15d70b0-0fe6-46f8-81bd-5a190dae685b/720p.mp4?token=Dzy4_BKCpk1N5bwQQQc8yg&expires=1704287398&filename=JujutsuKaisen2_Ep_01_SUB_ITA.mp4' + download: 'https://au-d1-01.scws-content.net/download/33/4/05/405f82d3-ff5f-47c6-a907-389f2fc65509/720p.mp4?token=B6Nf0xOc17nc1K5y19r-nQ&expires=1709003508&filename=OnePiece_Ep_0241_SUB_ITA.mp4' } ``` diff --git a/package.json b/package.json index 53b05b536..17da0d9a7 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "prepare": "husky install", "test": "jest", "test:gogoanime": "jest ./test/anime/gogoanime.test.ts", + "test:animeunity": "jest ./test/anime/animeunity.test.ts", "test:anime": "jest ./test/anime", "test:books": "jest ./test/books/libgen.test.ts", "test:comics": "jest ./test/comics", @@ -56,7 +57,7 @@ "dependencies": { "ascii-url-encoder": "^1.2.0", "axios": "^0.27.2", - "cheerio": "1.0.0-rc.12", + "cheerio": "^1.0.0-rc.12", "crypto-js": "^4.1.1", "form-data": "^4.0.0" }, diff --git a/src/providers/anime/animeunity.ts b/src/providers/anime/animeunity.ts index 606d1183d..8c841999d 100644 --- a/src/providers/anime/animeunity.ts +++ b/src/providers/anime/animeunity.ts @@ -57,15 +57,29 @@ class AnimeUnity extends AnimeParser { /** * @param id Anime id + * @param page Page number */ - override fetchAnimeInfo = async (id: string): Promise => { + override fetchAnimeInfo = async (id: string, page: number = 1): Promise => { const url = `${this.baseUrl}/anime/${id}` - + const episodesPerPage = 120 + const lastPageEpisode = page*episodesPerPage + const firstPageEpisode = lastPageEpisode-119 + const url2 = `${this.baseUrl}/info_api/${id}/1?start_range=${firstPageEpisode}&end_range=${lastPageEpisode}` + try { const res = await this.client.get(url); const $ = load(res.data); + + const totalEpisodes = parseInt($('video-player')?.attr('episodes_count') ?? '0') + const totalPages = Math.round(totalEpisodes/120) + 1 + + if(page < 1 || page > totalPages) + throw new Error(`Argument 'page' for ${id} must be between 1 and ${totalPages}!`); const animeInfo: IAnimeInfo = { + currentPage: page, + hasNextPage: totalPages > page, + totalPages: totalPages, id: id, title: $('h1.title')?.text().trim(), url: url, @@ -74,7 +88,7 @@ class AnimeUnity extends AnimeParser { $('.info-wrapper.pt-3.pb-3 small')?.map((i, element): string => { return $(element).text().replace(',', '').trim() }).toArray() ?? undefined, - totalEpisodes: parseInt($('video-player')?.attr('episodes_count') ?? '0'), + totalEpisodes: totalEpisodes, image: $('img.cover')?.attr('src'), // image: $('meta[property="og:image"]')?.attr('content'), cover: $('.banner')?.attr('src') ?? $('.banner')?.attr('style')?.replace('background: url(', ''), @@ -82,7 +96,12 @@ class AnimeUnity extends AnimeParser { episodes: [] } - const items = JSON.parse("" + $('video-player').attr('episodes') + "") + // fetch episodes method 1 (only first page can be fetchedd) + // const items = JSON.parse("" + $('video-player').attr('episodes') + "") + + // fetch episodes method 2 (all pages can be fetched) + const res2 = await this.client.get(url2); + const items = res2.data.episodes for(const i in items) { animeInfo.episodes?.push({ diff --git a/test/anime/animeunity.test.ts b/test/anime/animeunity.test.ts index 2050fc3f9..12628fd73 100644 --- a/test/anime/animeunity.test.ts +++ b/test/anime/animeunity.test.ts @@ -3,7 +3,7 @@ import { ANIME } from '../../src/providers'; jest.setTimeout(120000); const animeunity = new ANIME.AnimeUnity() -const animeName = 'Jujutsu Kaisen 2'; +const animeName = 'One Piece'; test('returns a filled array of anime list', async () => { const data = await animeunity.search(animeName); @@ -12,14 +12,15 @@ test('returns a filled array of anime list', async () => { test('returns a filled object of anime data', async () => { const res = await animeunity.search(animeName); - const data = await animeunity.fetchAnimeInfo(res.results[0].id); + const data = await animeunity.fetchAnimeInfo(res.results[0].id, 3); expect(data).not.toBeNull(); expect(data.results).not.toEqual([]); }); test('returns a filled object of episode sources', async () => { const res = await animeunity.search(animeName); - const info = await animeunity.fetchAnimeInfo(res.results[0].id); + const info = await animeunity.fetchAnimeInfo(res.results[0].id, 3); const data = await animeunity.fetchEpisodeSources(info.episodes![0].id) + console.log(data) expect(data.sources).not.toEqual([]); });