From 2f18461bf4d615ac691269d916e6dbbc6961e105 Mon Sep 17 00:00:00 2001 From: capitanwesler Date: Mon, 1 Feb 2021 22:15:10 +0000 Subject: [PATCH] Adding the funcionality to the v2 with the new directory --- src/api/api.js | 2 +- src/v2/api/api.js | 32 ++++++++------- src/v2/utils/index.js | 91 +++++++++++++++++++------------------------ 3 files changed, 58 insertions(+), 67 deletions(-) diff --git a/src/api/api.js b/src/api/api.js index e167fc5..a106021 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -81,7 +81,7 @@ const getAllDirectory = async (genres) => { return !item.genres.includes("Ecchi") && !item.genres.includes("ecchi"); }); } else { - data = JSON.parse(JSON.stringify(require('../assets/directory.json'))); + data = directoryAnimes; } return data.map(doc => ({ diff --git a/src/v2/api/api.js b/src/v2/api/api.js index f2d21ae..f54a85d 100644 --- a/src/v2/api/api.js +++ b/src/v2/api/api.js @@ -19,11 +19,15 @@ const { videoServersJK, getAnimes, getDirectory, - getThemes + getThemes, + directoryAnimes, + radioStations, + animeGenres, + animeThemes } = require('../utils'); const ThemeParser = require('../utils/animetheme'); -const parserThemes = new ThemeParser() +const parserThemes = new ThemeParser(); const { BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE, GENRES_URL, BASE_THEMEMOE @@ -111,7 +115,7 @@ const getAnitakume = async () =>{ const getNews = async (pageRss) =>{ - const promises = [] + const promises = []; for(let i = 0; i <= pageRss.length -1; i++) { @@ -242,10 +246,10 @@ const getMoreInfo = async (title) =>{ try { - const promises = [] + 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]; + let data = directoryAnimes; + const res = data.filter(x => x.title === title)[0]; if (!res.jkanime) { promises.push({ @@ -257,9 +261,9 @@ const getMoreInfo = async (title) =>{ 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) + moreInfo: await animeExtraInfo(res.mal_id).then(info => info || null), + promo: await getAnimeVideoPromo(res.mal_id).then(promo => promo || null), + characters: await getAnimeCharacters(res.mal_id).then(characters => characters || null) }); } else { promises.push({ @@ -271,9 +275,9 @@ const getMoreInfo = async (title) =>{ 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) + moreInfo: await animeExtraInfo(res.mal_id).then(info => info || null), + promo: await getAnimeVideoPromo(res.mal_id).then(promo => promo || null), + characters: await getAnimeCharacters(res.mal_id).then(characters => characters || null) }); } @@ -343,7 +347,7 @@ const getYoutubeVideos = async (channelId) => { }; const getRadioStations = async () => { - return require('../assets/radiostations.json'); + return radioStations; } const getOpAndEd = async (title) => { @@ -432,7 +436,7 @@ const getAnimeGenres = async(genre, order, page) => { }; -const getAllThemes = async () => require('../../assets/themes.json'); +const getAllThemes = async () => animeThemes; module.exports = { schedule, diff --git a/src/v2/utils/index.js b/src/v2/utils/index.js index 1c3e35e..af425cd 100644 --- a/src/v2/utils/index.js +++ b/src/v2/utils/index.js @@ -1,10 +1,13 @@ const { BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, BASE_ARUPPI, ANIMEFLV_SEARCH, BASE_JKANIME } = require('../api/urls.js'); - const { homgot } = require('../api/apiCall.js'); +const directoryAnimes = JSON.parse(JSON.stringify(require('../../assets/directory.json'))); +const radioStations = require('../../assets/radiostations.json'); +const animeGenres = require('../../assets/genres.json'); +const animeThemes = require('../../assets/themes.json'); function btoa(str) { let buffer; @@ -194,54 +197,48 @@ const animeflvInfo = async (id) => { }; -const getAnimeCharacters = async(title) =>{ - - const matchAnime = await getMALid(title) +const getAnimeCharacters = async(mal_id) =>{ + let data; try { - if(matchAnime !== null) { - const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/characters_staff`, { parse: true }); - return data.characters.map(doc => ({ - id: doc.mal_id, - name: doc.name, - image: doc.image_url, - role: doc.role - })); - } - } catch (err) { - console.log(err) + data = await homgot(`${BASE_JIKAN}anime/${mal_id}/characters_staff`, { parse: true }); + }catch(error) { + console.log(error); } + if(data !== null) { + return data.characters.map(doc => ({ + id: doc.mal_id, + name: doc.name, + image: doc.image_url, + role: doc.role + })); + } }; -const getAnimeVideoPromo = async(title) =>{ - - const matchAnime = await getMALid(title) +const getAnimeVideoPromo = async(mal_id) =>{ + let data; try { - if(matchAnime !== null) { - const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/videos`, {parse: true}) - return data.promo.map(doc => ({ - title: doc.title, - previewImage: doc.image_url, - videoURL: doc.video_url - })); - } - } catch (err) { - console.log(err) + data = await homgot(`${BASE_JIKAN}anime/${mal_id}/videos`, {parse: true}); + }catch(error) { + console.log(error); } + if(data !== null) { + return data.promo.map(doc => ({ + title: doc.title, + previewImage: doc.image_url, + videoURL: doc.video_url + })); + } }; -const animeExtraInfo = async (title) => { - - const matchAnime = await getMALid(title) +const animeExtraInfo = async (mal_id) => { + const data = await homgot(`${BASE_JIKAN}anime/${mal_id}`, {parse: true}); try { - - if(matchAnime !== null) { - - const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}`, {parse: true}) + if(data !== null) { const promises = []; let broadcast = '' @@ -298,19 +295,6 @@ 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; - } else { - return matchAnime; - } - -}; - const imageUrlToBase64 = async (url) => { let img = await homgot(url) return img.rawBody.toString('base64'); @@ -491,11 +475,11 @@ const getDirectory = async (genres) => { let data if (genres === "sfw") { - data = JSON.parse(JSON.stringify(require('../../assets/directory.json'))).filter(function (item) { + data = directoryAnimes.filter(function (item) { return !item.genres.includes("Ecchi") && !item.genres.includes("ecchi"); }) } else { - data = JSON.parse(JSON.stringify(require('../../assets/directory.json'))); + data = directoryAnimes; } return data.map(doc => ({ @@ -520,7 +504,6 @@ module.exports = { getAnimeCharacters, getAnimeVideoPromo, animeExtraInfo, - getMALid, imageUrlToBase64, searchAnime, transformUrlServer, @@ -529,5 +512,9 @@ module.exports = { getThemes, getAnimes, getDirectory, - videoServersJK + videoServersJK, + directoryAnimes, + radioStations, + animeGenres, + animeThemes }