Merge pull request #14 from aruppi/feature/improving

Fixing some issues with jkanime servers
pull/25/head^2
Jesús María 5 years ago committed by GitHub
commit 26c0d766cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,4 @@
# **Aruppi API** (v3.3.6)
# **Aruppi API** (v3.3.7)
> This API has everything about Japan, from anime, music, radio, images, videos ... to japanese culture
>

2
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "aruppi",
"version": "3.3.6",
"version": "3.3.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -1,6 +1,6 @@
{
"name": "aruppi",
"version": "3.3.6",
"version": "3.3.7",
"description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app",
"main": "./src/api/api.js",
"scripts": {

@ -16,11 +16,11 @@ const {
structureThemes,
videoServersJK,
getThemes,
getMALid
getRelatedAnimes
} = require('../utils/index');
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, BASE_THEMEMOE, BASE_ANIMEFLV, BASE_ARUPPI
@ -77,15 +77,17 @@ const getAllAnimes = async () =>{
const getAllDirectory = async (genres) => {
let data
if (genres === "sfw") {
let data;
if (genres === 'sfw') {
data = JSON.parse(JSON.stringify(require('../assets/directory.json'))).filter(function (item) {
return !item.genres.includes("Ecchi") && !item.genres.includes("ecchi");
})
});
} else {
data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
}
return data.map(doc => ({
id: doc.id,
title: doc.title,
@ -238,45 +240,25 @@ const getMoreInfo = async (title) =>{
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)
});
let result = data.filter(anime => anime.title === title)[0];
return {
title: result.title || null,
poster: result.poster || null,
synopsis: result.description || null,
status: result.state || null,
type: result.type || null,
rating: result.score || null,
genres: result.genres || null,
moreInfo: await animeExtraInfo(result.mal_title).then(info => info || null),
promo: await getAnimeVideoPromo(result.mal_title).then(promo => promo || null),
characters: await getAnimeCharacters(result.mal_title).then(characters => characters || null),
related: await getRelatedAnimes(result.id)
}
return promises;
} catch (e) {
console.log(e)
console.log(e);
}
};
@ -285,25 +267,17 @@ const getEpisodes = async (title) =>{
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];
const result = data.filter(x => x.title === title || x.mal_title === title)[0];
if (!res.jkanime) {
promises.push({
episodes: await animeflvInfo(res.id).then(episodes => episodes || null),
});
if (!result.jkanime) {
return await animeflvInfo(result.id).then(episodes => episodes || null);
} else {
promises.push({
episodes: await jkanimeInfo(res.id).then(episodes => episodes || null),
});
return await jkanimeInfo(result.id).then(episodes => episodes || null);
}
return promises;
} catch (e) {
console.log(e)
console.log(e);
}
};
@ -311,10 +285,15 @@ const getEpisodes = async (title) =>{
const getAnimeServers = async (id) => {
if (isNaN(id.split('/')[0])) {
return await videoServersJK(id)
return await videoServersJK(id);
} else {
const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true });
return await transformUrlServer(data.servers);
}
};
@ -392,7 +371,7 @@ const getOpAndEd = async (title) => await structureThemes(await parserThemes.ser
const getThemesYear = async (year) => {
let data = []
let data = [];
if (year === undefined) {
return await parserThemes.allYears();
} else {
@ -510,7 +489,7 @@ const getPlatforms = async (id) => {
const getProfilePlatform = async (id) => {
let data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/platforms/${id}.json`, { parse: true })
let data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/platforms/${id}.json`, { parse: true });
let channelId = { id: data[0].youtubeId, part: 'snippet,id', order: 'date', maxResults: '50', prop: 'items' };
let videos = await getYoutubeVideos(channelId)
@ -562,5 +541,6 @@ module.exports = {
getDestAnimePlatforms,
getPlatforms,
getSectionYoutubeVideos,
getProfilePlatform
getProfilePlatform,
getRelatedAnimes
};

@ -1,27 +1,30 @@
const got = require('got');
const got = require('got'); // This is to make a HTTP request without doing AJAX
const cheerio = require('cheerio');
const { CookieJar} = require('tough-cookie');
const cookieJar = new CookieJar();
let response
let data
let response;
let data;
const homgot = async (url, options) => {
if (options !== undefined) {
if (options.scrapy) {
response = await got(url, { cookieJar })
data = await cheerio.load(response.body)
response = await got(url, { cookieJar });
data = await cheerio.load(response.body);
}
if (options.parse) {
data = await got(url, { cookieJar }).json()
data = await got(url, { cookieJar }).json();
}
} else {
data = await got.get(url, { cookieJar });
}
return data
return data;
}
module.exports = {homgot}
module.exports = { homgot };

@ -270,13 +270,11 @@ router.get('/moreInfo/:title' , (req, res) =>{
api.getMoreInfo(title)
.then(info => {
if (info.length > 0) {
res.status(200).json({
info
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
)
if (info !== undefined) {
res.status(200).json(info);
} else {
res.status(500).json({ message: 'Aruppi lost in the shell'});
}
}).catch((err) =>{
console.error(err);
});
@ -289,12 +287,14 @@ router.get('/getEpisodes/:title' , (req, res) =>{
api.getEpisodes(title)
.then(episodes => {
if (episodes.length > 0) {
res.status(200).json(episodes);
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
)
res.status(200).json({episodes});
} else {
res.status(500).json({ message: 'Aruppi lost in the shell'});
}
}).catch((err) =>{
console.error(err);
});
@ -310,9 +310,9 @@ router.get('/getAnimeServers/:id([^/]+/[^/]+)' , (req, res) =>{
res.status(200).json({
servers
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
)
} else {
res.status(500).json({ message: 'Aruppi lost in the shell'});
}
}).catch((err) =>{
console.error(err);
});
@ -434,15 +434,16 @@ router.get('/themes/:title' , (req, res) =>{
let title = req.params.title;
api.getOpAndEd(title)
.then(themes => {
if (themes.length > 0) {
if (themes) {
res.status(200).json({
themes
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
)
} else {
res.status(500).json({ message: 'Aruppi lost in the shell'});
}
}).catch((err) =>{
console.error(err);
});

@ -13,6 +13,8 @@ function shutdown() {
process.exit();
}
// @TESTING
process.on('SIGINT', shutdown);
process.on('SIGQUIT', shutdown);
process.on('SIGTERM', shutdown);

@ -19,7 +19,7 @@ class ThemeParser {
return await this.parseLinks();
}
catch(err) {
throw err;
console.log(err);
}
}
@ -30,18 +30,18 @@ class ThemeParser {
return await this.parseYears();
}
catch(err) {
throw err;
console.log(err);
}
}
async serie(query) {
async serie(title) {
try {
this.animes = [];
this.$ = await redditocall('anime_index');
return await this.parseSerie(query);
return await this.parseSerie(title);
}
catch(err) {
throw err;
console.log(err);
}
}
@ -52,7 +52,7 @@ class ThemeParser {
return await this.parseArtists();
}
catch(err) {
throw err;
console.log(err);
}
}
@ -63,7 +63,7 @@ class ThemeParser {
return await this.parseArtist();
}
catch(err) {
throw err;
console.log(err);
}
}
@ -74,13 +74,14 @@ class ThemeParser {
return await this.parseRandom(query);
}
catch(err) {
throw err;
console.log(err);
}
}
async year(date) {
let animes = [];
this.$ = await redditocall(date)
this.$ = await redditocall(date);
this.$('h3').each((i, el) => {
let parsed = this.parseAnime(el);
parsed.year = date;
@ -102,13 +103,13 @@ class ThemeParser {
let parsed = this.parseAnime(this.$('h3')[rand]);
resolve(parsed);
})
});
}
parseYears() {
return new Promise(async resolve => {
let promises = []
let promises = [];
let data = this.$('h3 a');
for (let i = 0; i < data.length; i++) {
@ -119,12 +120,12 @@ class ThemeParser {
})
if (i === data.length - 1) {
resolve(promises)
resolve(promises);
}
}
})
});
}
parseArtists() {
@ -169,22 +170,31 @@ class ThemeParser {
})
}
parseSerie(query){
/* - ParseSerie
Parse the HTML from the redditocall
and search for the h3 tag to be the
same of the title and resolve a object.
*/
parseSerie(title) {
return new Promise(async resolve => {
let data = this.$('p a');
for (let i = 0; i < data.length; i++) {
let serieElement = data[i].children[0].data
let serieElement = data[i].children[0].data;
if (serieElement.split(" (")[0] === query) {
if (serieElement.split(" (")[0] === title) {
let year = this.$('p a')[i].attribs.href.split('/r/AnimeThemes/wiki/')[1].split('#wiki')[0];
this.$ = await redditocall(this.$('p a')[i].attribs.href.split('/r/AnimeThemes/wiki/')[1].split('#wiki')[0]);
for (let i = 0; i < this.$('h3').length; i++) {
if (this.$('h3')[i].children[0].children[0].data === query) {
if (this.$('h3')[i].children[0].children[0].data === title) {
let parsed = this.parseAnime(this.$('h3')[i]);
parsed.year = year;
resolve(parsed);
}
}
@ -192,17 +202,18 @@ class ThemeParser {
}
}
})
});
}
parseLinks() {
return new Promise(async resolve => {
let years = this.$('h3 a');
this.$('h3 a')[0].children[0].data
for (let i = 0; i < years.length; i++) {
let yearElement = years[i];
await this.year(this.$(yearElement).attr('href').split('/')[4])
.then(async animes => {
this.animes = this.animes.concat(animes);
@ -215,65 +226,80 @@ class ThemeParser {
})
}
parseAnime(dat) {
let el = this.$(dat).children('a');
parseAnime(element) {
let el = this.$(element).children('a');
let title = el.text();
let malId = el.attr('href').split('/')[4];
let next = this.$(dat).next();
let mal_id = el.attr('href').split('/')[4];
let next = this.$(element).next();
let theme = {
id: malId,
id: mal_id,
title
}
};
if (next.prop("tagName") === "TABLE") {
if (next.prop("tagName") === "P") {
theme.themes = this.parseTable(next.next());
} else if (next.prop("tagName") === "TABLE") {
theme.themes = this.parseTable(next);
}else if (next.prop("tagName") === "P") {
theme.themes = this.parseTable(next.next());
}
return theme;
}
parseTable(table) {
if (table.prop('tagName') !== "TABLE") {
return this.parseTable(table.next());
/* - ParseTable
Parse the table tag from the HTML
and returns a object with all the
information.
*/
parseTable(element) {
if (element.prop('tagName') !== "TABLE") {
return this.parseTable(element.next());
}
let themes = [];
table.children('tbody').children('tr').each(function () {
const $ = cheerio.load(this);
const td = $('td'); // Theme row
let name = replaceAll(td.first().text(), "&quot;", "\"")
let linkEl = td.eq(1).children().first();
let link = linkEl.attr('href');
let linkDesc = linkEl.text();
let episodes = td.eq(2).text();
let notes = td.eq(3).text();
element.find('tbody').find('tr').each((i, elem) => {
let name = replaceAll(elem.children[1].children[0].data, "&quot;", "\"");
let link = elem.children[3].children[0].attribs.href;
let linkDesc = elem.children[3].children[0].children[0].data;
let episodes = elem.children[5].children.length > 0 ? elem.children[5].children[0].data : "";
let notes = elem.children[7].children.length > 0 ? elem.children[7].children[0].data : "";
themes.push({
name,
link,
desc: linkDesc,
type: (name.startsWith('OP') ? 'opening' : 'ending'),
type: name.startsWith('OP') ? 'Opening' : name.startsWith('ED') ? 'Ending' : 'OP/ED',
episodes,
notes
})
})
});
});
return themes;
}
}
async function redditocall(href) {
let resp = await homgot(REDDIT_ANIMETHEMES + href + ".json", { parse: true })
let resp = await homgot(REDDIT_ANIMETHEMES + href + ".json", { parse: true });
return cheerio.load(getHTML(resp.data.content_html));
}
function getHTML(str) {
let html = replaceAll(str, "&lt;", "<")
html = replaceAll(html, "&gt;", ">")
let html = replaceAll(str, "&lt;", "<");
html = replaceAll(html, "&gt;", ">");
return html;
}
@ -281,4 +307,5 @@ function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
module.exports = ThemeParser;

@ -22,91 +22,107 @@ global.btoa = btoa;
async function videoServersJK(id) {
const $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true });
let servers = {};
let script;
const serverNames = $('div#reproductor-box li').map((index, element) => {
return $(element).find('a').text();
}).get();
const scripts = $('script');
const episodes = $('div#reproductor-box li');
const serverNames = [];
let servers = [];
episodes.each((index, element) => serverNames.push($(element).find('a').text()))
$('script').each((index, element) => {
if ($(element).html().includes('var video = [];')) {
script = $(element).html();
}
});
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}] = \'<iframe class="player_conte" src="`)[1].split('"')[0];
servers.push({ iframe: videoPageURL });
});
let videoUrls = script.match(/(?<=src=").*?(?=[\*"])/gi);
for (let i = 0; i < serverNames.length; i++) {
servers[serverNames[i]] = videoUrls[i];
}
} catch (err) {
console.log(err)
console.log(err);
return null;
}
}
let serverList = [];
for (let server in servers) {
if (serverNames[serverNames.indexOf(server)].toLowerCase() === 'desu') {
serverList.push({
id: serverNames[serverNames.indexOf(server)].toLowerCase(),
url: await desuServerUrl(servers[server]) !== null ? await desuServerUrl(servers[server]) : servers[server],
direct: true
});
}else {
serverList.push({
id: serverNames[server].toLowerCase(),
url: await getVideoURL(servers[server].iframe),
id: serverNames[serverNames.indexOf(server)].toLowerCase(),
url: servers[server],
direct: true
});
}
}
serverList = serverList.filter(x => x.id !== 'xtreme s' && x.id !== 'desuka');
return await Promise.all(serverList);
return serverList;
}
async function getVideoURL(url) {
async function desuServerUrl(url) {
const $ = await homgot(url, { scrapy: true});
let script;
const video = $('video');
if (video.length) {
const src = $(video).find('source').attr('src');
return src || null;
$('script').each((index, element) => {
if ($(element).html().includes('var parts = {')) {
if ($(element).html()) {
script = $(element).html();
}else {
return null;
}
else {
const scripts = $('script');
const l = global;
const ll = String;
const $script2 = $(scripts[1]).html();
eval($script2);
return l.ss || null;
}
});
let result = script.match(/swarmId: '(https:\/\/\S+)'/gi)
.toString()
.split('\'')[1];
return result;
}
const jkanimeInfo = async (id) => {
let $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true });
let nextEpisodeDate
let rawNextEpisode = $('div[id="container"] div.left-container div[id="proxep"] p')[0]
let nextEpisodeDate;
let rawNextEpisode = $('div[id="container"] div.left-container div[id="proxep"] p')[0];
if (rawNextEpisode === undefined) {
nextEpisodeDate = null
nextEpisodeDate = null;
} else {
if (rawNextEpisode.children[1].data === ' ') {
nextEpisodeDate = null
nextEpisodeDate = null;
} else {
nextEpisodeDate = rawNextEpisode.children[1].data.trim()
nextEpisodeDate = rawNextEpisode.children[1].data.trim();
}
}
const eps_temp_list = [];
let episodes_aired = '';
$('div#container div.left-container div.navigation a').each(async (index, element) => {
const $element = $(element);
const total_eps = $element.text();
eps_temp_list.push(total_eps);
})
});
try { episodes_aired = eps_temp_list[0].split('-')[1].trim(); } catch (err) { }
const animeListEps = [{ nextEpisodeDate: nextEpisodeDate }];
for (let i = 1; i <= episodes_aired; i++) {
let episode = i;
let animeId = $('div[id="container"] div.content-box div[id="episodes-content"]')[0].children[1].children[3].attribs.src.split('/')[7].split('.jpg')[0];
@ -122,8 +138,52 @@ const jkanimeInfo = async (id) => {
};
function getPoster(id) {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
for (let anime of data) {
if (anime.id === id) {
return anime.poster;
}
}
return "";
};
async function getRelatedAnimes(id) {
const $ = await homgot(`${BASE_ANIMEFLV}/anime/${id}`, { scrapy: true });
let listRelated = {};
let relatedAnimes = [];
if ($('ul.ListAnmRel').length) {
$('ul.ListAnmRel li a').each((index, element) => {
listRelated[$(element).text()] = $(element).attr('href');
});
for (related in listRelated) {
let posterUrl = getPoster(listRelated[related].split('/')[2]);
relatedAnimes.push(
{
id: listRelated[related].split('/')[2],
title: related,
poster: posterUrl
}
);
}
return relatedAnimes;
}else {
return [];
}
};
const animeflvGenres = async (id) => {
let $ = await homgot(`${BASE_ANIMEFLV}${id}`, { scrapy: true });
let $ = await homgot(`${BASE_ANIMEFLV}/${id}`, { scrapy: true });
$('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => {
return $(element).attr('href').split('=')[1] || null;
});
@ -131,45 +191,51 @@ const animeflvGenres = async (id) => {
const animeflvInfo = async (id) => {
let $ = await homgot(`${BASE_ANIMEFLV}anime/${id}`, { scrapy: true });
let $ = await homgot(`${BASE_ANIMEFLV}/anime/${id}`, { scrapy: true });
let scripts = $('script').toArray();
const anime_info_ids = [];
const anime_eps_data = [];
Array.from({ length: scripts.length }, (v, k) => {
const contents = $(scripts[k]).html();
for (let script of scripts) {
const contents = $(script).html();
if ((contents || '').includes('var anime_info = [')) {
let anime_info = contents.split('var anime_info = ')[1].split(';\n')[0];
let dat_anime_info = JSON.parse(anime_info);
anime_info_ids.push(dat_anime_info);
}
if ((contents || '').includes('var episodes = [')) {
let episodes = contents.split('var episodes = ')[1].split(';')[0];
let eps_data = JSON.parse(episodes)
let eps_data = JSON.parse(episodes);
anime_eps_data.push(eps_data);
}
});
}
const animeId = id;
let nextEpisodeDate
let nextEpisodeDate;
if (anime_info_ids.length > 0) {
if (anime_info_ids[0].length === 4) {
nextEpisodeDate = anime_info_ids[0][3]
nextEpisodeDate = anime_info_ids[0][3];
} else {
nextEpisodeDate = null
nextEpisodeDate = null;
}
}
const amimeTempList = [];
for (const [key] of Object.entries(anime_eps_data)) {
let episode = anime_eps_data[key].map(x => x[0]);
let episodeId = anime_eps_data[key].map(x => x[1]);
amimeTempList.push(episode, episodeId);
}
const animeListEps = [{ nextEpisodeDate: nextEpisodeDate }];
Array.from({ length: amimeTempList[1].length }, (v, k) => {
let data = amimeTempList.map(x => x[k]);
for (let i = 0; i < amimeTempList[1].length; i++) {
let data = amimeTempList.map(x => x[i]);
let episode = data[0];
let id = data[1];
let link = `${id}/${animeId}-${episode}`
@ -177,16 +243,16 @@ const animeflvInfo = async (id) => {
animeListEps.push({
episode: episode,
id: link,
})
})
return animeListEps
});
}
return animeListEps;
};
const getAnimeCharacters = async(title) =>{
const matchAnime = await getMALid(title)
const matchAnime = await getMALid(title);
try {
if(matchAnime !== null) {
@ -199,18 +265,20 @@ const getAnimeCharacters = async(title) =>{
}));
}
} catch (err) {
console.log(err)
console.log(err);
}
};
const getAnimeVideoPromo = async(title) =>{
const matchAnime = await getMALid(title)
const matchAnime = await getMALid(title);
try {
if(matchAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/videos`, {parse: true})
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,
@ -218,22 +286,22 @@ const getAnimeVideoPromo = async(title) =>{
}));
}
} catch (err) {
console.log(err)
console.log(err);
}
};
const animeExtraInfo = async (title) => {
const matchAnime = await getMALid(title)
const matchAnime = await getMALid(title);
try {
if(matchAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}`, {parse: true})
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}`, {parse: true});
const promises = [];
let broadcast = ''
let broadcast = '';
Array(data).map(doc => {
@ -283,21 +351,19 @@ const animeExtraInfo = async (title) => {
}
} catch (err) {
console.log(err)
console.log(err);
}
};
const getMALid = async (title) =>{
if (title === undefined || title === null) {
return 1
return 1;
} else {
const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`,{ parse: true })
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') {
@ -305,12 +371,10 @@ const getMALid = async(title) =>{
} else {
return matchAnime;
}
}
};
const imageUrlToBase64 = async (url) => {
let img = await homgot(url)
return img.rawBody.toString('base64');
@ -319,7 +383,7 @@ const imageUrlToBase64 = async (url) => {
const searchAnime = async (query) => {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
let queryLowerCase = query.toLowerCase()
let queryLowerCase = query.toLowerCase();
const res = data.filter(x => x.title.toLowerCase().includes(queryLowerCase));
return res.map(doc => ({
@ -336,8 +400,8 @@ const transformUrlServer = async (urlReal) => {
for (const data of urlReal) {
if (data.server === 'amus' || data.server === 'natsuki') {
let res = await homgot(data.code.replace("embed", "check"), { parse: true });
data.code = res.file || null
data.direct = true
data.code = res.file || null;
data.direct = true;
}
}
@ -384,44 +448,63 @@ const obtainPreviewNews = (encoded) => {
return image;
}
/* - StructureThemes
This function only parses the theme/themes
if indv is true, then only return a object, if it's false
then returns a array with the themes selected.
*/
const structureThemes = async (body, indv) => {
const promises = []
if (indv === true) {
promises.push({
return {
title: body.title,
year: body.year,
themes: await getThemesData(body.themes),
});
themes: await getThemesData(body.themes)
};
} else {
for (let i = 0; i <= body.length - 1; i++) {
promises.push({
const themes = [];
themes.push({
title: body[i].title,
year: body[i].year,
themes: await getThemesData(body[i].themes),
});
}
return themes;
}
return promises;
};
/* - GetThemesData
Get the themes from the object and
format to a new array of items where
these items are formatted better.
*/
const getThemesData = async (themes) => {
let promises = []
let items = [];
for (let i = 0; i <= themes.length - 1; i++) {
promises.push({
items.push({
title: themes[i].name.split('"')[1] || 'Remasterización',
type: themes[i].name.split('"')[0] || 'OP/ED',
episodes: themes[i].episodes || null,
type: themes[i].type,
episodes: themes[i].episodes !== "" ? themes[i].episodes : null,
notes: themes[i].notes !== "" ? themes[i].notes : null,
video: themes[i].link
});
}
return promises.filter(x => x.title !== 'Remasterización');
return items.filter(x => x.title !== 'Remasterización');
};
@ -441,13 +524,14 @@ module.exports = {
animeflvInfo,
getAnimeCharacters,
getAnimeVideoPromo,
getRelatedAnimes,
animeExtraInfo,
getMALid,
imageUrlToBase64,
searchAnime,
transformUrlServer,
obtainPreviewNews,
structureThemes,
getThemes,
getMALid,
videoServersJK
}

Loading…
Cancel
Save