From 214a0aa15c071bbd1ed71cfc146e2e91c352e81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9luchu?= Date: Mon, 23 Nov 2020 18:48:49 +0100 Subject: [PATCH] v3.3.1 - Fix v2 MoreInfo --- README.md | 2 +- package-lock.json | 2 +- package.json | 2 +- src/api/api.js | 3 +- src/utils/index.js | 20 +++- src/v2/api/api.js | 91 ++++++++-------- src/v2/utils/index.js | 242 ++++++++++++++++++++++++++++-------------- 7 files changed, 231 insertions(+), 131 deletions(-) diff --git a/README.md b/README.md index 9cd1c64..31d6bf4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# **Aruppi API** (v3.3.0) +# **Aruppi API** (v3.3.1) > This API has everything about Japan, from anime, music, radio, images, videos ... to japanese culture > diff --git a/package-lock.json b/package-lock.json index 1876dfd..25d93d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "aruppi", - "version": "3.2.10", + "version": "3.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b23021f..fd55d24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aruppi", - "version": "3.3.0", + "version": "3.3.1", "description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app", "main": "./src/api/api.js", "scripts": { diff --git a/src/api/api.js b/src/api/api.js index b94e9ce..59aa48f 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -15,7 +15,8 @@ const { obtainPreviewNews, structureThemes, videoServersJK, - getThemes + getThemes, + getMALid } = require('../utils/index'); const ThemeParser = require('../utils/animetheme'); diff --git a/src/utils/index.js b/src/utils/index.js index 111b5b3..c61d447 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -290,13 +290,23 @@ const animeExtraInfo = async (title) => { const getMALid = async(title) =>{ - const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`,{ parse: true }) - const matchAnime = res.results.find(x => x.title === title); - if(typeof matchAnime === 'undefined') { - return null; + if (title === undefined || title === null) { + + return 1 + } else { - return matchAnime; + + const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`,{ parse: true }) + const matchAnime = res.results.find(x => x.title === title); + + if(typeof matchAnime === 'undefined') { + return null; + } else { + return matchAnime; + } + + } }; diff --git a/src/v2/api/api.js b/src/v2/api/api.js index fe7ed1c..116e06f 100644 --- a/src/v2/api/api.js +++ b/src/v2/api/api.js @@ -5,6 +5,7 @@ const { } = require('./apiCall'); const { + jkanimeInfo, animeflvGenres, animeflvInfo, imageUrlToBase64, @@ -15,6 +16,7 @@ const { transformUrlServer, obtainPreviewNews, structureThemes, + videoServersJK, getAnimes, getDirectory, getThemes @@ -238,55 +240,60 @@ const getSpecials = async (type, subType, page) =>{ const getMoreInfo = async (title) =>{ - let promises = []; - let animeId = '' - let animeType = '' - let animeIndex = '' - - await getAllAnimes().then(animes => { - for (const i in animes) { - if (animes[i].title.split('\t')[0] === title.split('\t')[0]) { - animeId = animes[i].id - animeIndex = animes[i].index - animeType = animes[i].type.toLowerCase() - break; - } + try { + + const promises = [] + + let data = JSON.parse(JSON.stringify(require('../../assets/directory.json'))); + const res = data.filter(x => x.title === title || x.mal_title === title)[0]; + + if (!res.jkanime) { + promises.push({ + title: res.title || null, + poster: res.poster || null, + synopsis: res.description || null, + status: res.state || null, + type: res.type || null, + rating: res.score || null, + genres: res.genres || null, + episodes: await animeflvInfo(res.id).then(episodes => episodes || null), + moreInfo: await animeExtraInfo(res.mal_title).then(info => info || null), + promo: await getAnimeVideoPromo(res.mal_title).then(promo => promo || null), + characters: await getAnimeCharacters(res.mal_title).then(characters => characters || null) + }); + } else { + promises.push({ + title: res.title || null, + poster: res.poster || null, + synopsis: res.description || null, + status: res.state || null, + type: res.type || null, + rating: res.score || null, + genres: res.genres || null, + episodes: await jkanimeInfo(res.id).then(episodes => episodes || null), + moreInfo: await animeExtraInfo(res.mal_title).then(info => info || null), + promo: await getAnimeVideoPromo(res.mal_title).then(promo => promo || null), + characters: await getAnimeCharacters(res.mal_title).then(characters => characters || null) + }); } - }); - try{ - promises.push(await animeflvInfo(`anime/${animeId}`, animeIndex).then(async extra => ({ - title: title || null, - poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, - banner: extra.animeExtraInfo[0].banner || null, - synopsis: extra.animeExtraInfo[0].synopsis || null, - debut: extra.animeExtraInfo[0].debut || null, - type: extra.animeExtraInfo[0].type || null, - rating: extra.animeExtraInfo[0].rating || null, - genres: extra.genres || null, - episodes: extra.listByEps || null, - moreInfo: await animeExtraInfo(title).then(info =>{ - return info || null - }), - promoList: await getAnimeVideoPromo(title).then(promo =>{ - return promo || null - }), - charactersList: await getAnimeCharacters(title).then(characters =>{ - return characters || null - }) - }))); - - return Promise.all(promises); - - }catch(err){ - console.log(err) + return promises; + + } catch (e) { + console.log(e) } }; const getAnimeServers = async (id) => { - const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true }); - return await transformUrlServer(data.servers); + + if (isNaN(id.split('/')[0])) { + return await videoServersJK(id) + } else { + const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true }); + return await transformUrlServer(data.servers); + } + }; const search = async (title) =>{ return await searchAnime(title); }; diff --git a/src/v2/utils/index.js b/src/v2/utils/index.js index 1f48546..edd5ade 100644 --- a/src/v2/utils/index.js +++ b/src/v2/utils/index.js @@ -1,11 +1,127 @@ const { - BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, BASE_ARUPPI, ANIMEFLV_SEARCH + BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, BASE_ARUPPI, ANIMEFLV_SEARCH, BASE_JKANIME } = require('../api/urls.js'); const { homgot } = require('../api/apiCall.js'); +function btoa(str) { + let buffer; + if (str instanceof Buffer) { + buffer = str; + } + else { + buffer = Buffer.from(str.toString(), 'binary'); + } + return buffer.toString('base64'); +} + +global.btoa = btoa; + +async function videoServersJK(id) { + + const $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true }); + + const scripts = $('script'); + const episodes = $('div#reproductor-box li'); + const serverNames = []; + let servers = []; + + episodes.each((index, element) => serverNames.push($(element).find('a').text())) + + for (let i = 0; i < scripts.length; i++) { + try { + const contents = $(scripts[i]).html(); + if ((contents || '').includes('var video = [];')) { + Array.from({ length: episodes.length }, (v, k) => { + let index = Number(k + 1); + let videoPageURL = contents.split(`video[${index}] = \'