Fixes more info and show deprecated version

pull/1/head
Jéluchu 5 years ago
parent bde127a98a
commit 1578c02352

@ -185,9 +185,13 @@ router.get('/moreInfo/:title' , (req, res) =>{
api.getMoreInfo(title)
.then(info =>{
if (info.length > 0) {
res.status(200).json({
info
});
} else (
res.status(404).json({ message: 'Aruppi lost in the shell'})
)
}).catch((err) =>{
console.error(err);
});

@ -20,6 +20,12 @@ app.get('/', (req, res) => {
});
});
app.get('/api/v1', (req, res) => {
res.json({
message: 'Sorry, version (api/v1) is deprecated, if you want to see content go to api/v2'
});
});
app.use('/api/v2', api);
app.use(middlewares);

@ -6,8 +6,18 @@ const {
BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, SEARCH_URL, BASE_ARUPPI, BASE_THEMEMOE
} = require('../api/urls');
const animeflvInfo = async (id, index) =>{
try{
const animeflvInfo = async (id, index) => {
let poster = ""
let banner = ""
let synopsis = ""
let rating = ""
let debut = ""
let type = ""
do {
try {
const res = await cloudscraper(`${BASE_ANIMEFLV}anime/${id}`);
const body = await res;
@ -19,13 +29,12 @@ const animeflvInfo = async (id, index) =>{
const genres = [];
let listByEps;
let poster = `${BASE_ANIMEFLV}` + $('body div div div div div aside div.AnimeCover div.Image figure img').attr('src')
const banner = poster.replace('covers' , 'banners').trim();
let synopsis = $('body div div div div div main section div.Description p').text().trim();
let rating = $('body div div div.Ficha.fchlt div.Container div.vtshr div.Votes span#votes_prmd').text();
const debut = $('body div.Wrapper div.Body div div.Container div.BX.Row.BFluid.Sp20 aside.SidebarA.BFixed p.AnmStts').text();
const type = $('body div.Wrapper div.Body div div.Ficha.fchlt div.Container span.Type').text()
poster = `${BASE_ANIMEFLV}` + $('body div div div div div aside div.AnimeCover div.Image figure img').attr('src')
banner = poster.replace('covers', 'banners').trim();
synopsis = $('body div div div div div main section div.Description p').text().trim();
rating = $('body div div div.Ficha.fchlt div.Container div.vtshr div.Votes span#votes_prmd').text();
debut = $('body div.Wrapper div.Body div div.Container div.BX.Row.BFluid.Sp20 aside.SidebarA.BFixed p.AnmStts').text();
type = $('body div.Wrapper div.Body div div.Ficha.fchlt div.Container span.Type').text()
animeExtraInfo.push({
poster: poster,
@ -36,22 +45,22 @@ const animeflvInfo = async (id, index) =>{
type: type,
})
$('main.Main section.WdgtCn nav.Nvgnrs a').each((index , element) =>{
$('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => {
const $element = $(element);
const genre = $element.attr('href').split('=')[1] || null;
genres.push(genre);
});
Array.from({length: scripts.length} , (v , k) =>{
Array.from({length: scripts.length}, (v, k) => {
const $script = $(scripts[k]);
const contents = $script.html();
if((contents || '').includes('var anime_info = [')) {
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 = [')) {
if ((contents || '').includes('var episodes = [')) {
let episodes = contents.split('var episodes = ')[1].split(';')[0];
let eps_data = JSON.parse(episodes)
anime_eps_data.push(eps_data);
@ -59,16 +68,24 @@ const animeflvInfo = async (id, index) =>{
});
const AnimeThumbnailsId = index;
const animeId = id;
let nextEpisodeDate = anime_info_ids[0][3] || null;
let nextEpisodeDate
if (anime_info_ids.length > 0) {
if (anime_info_ids[0].length === 4) {
nextEpisodeDate = anime_info_ids[0][3]
} else {
nextEpisodeDate = null
}
}
const amimeTempList = [];
for(const [key , value] of Object.entries(anime_eps_data)){
for (const [key, value] 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);
amimeTempList.push(episode, episodeId);
}
const animeListEps = [{nextEpisodeDate: nextEpisodeDate}];
Array.from({length: amimeTempList[1].length} , (v , k) =>{
Array.from({length: amimeTempList[1].length}, (v, k) => {
let data = amimeTempList.map(x => x[k]);
let episode = data[0];
let id = data[1];
@ -84,38 +101,42 @@ const animeflvInfo = async (id, index) =>{
listByEps = animeListEps;
return {listByEps , genres , animeExtraInfo};
}catch(err){
return {listByEps, genres, animeExtraInfo};
} catch (err) {
console.error(err)
}
} while (poster === "" && banner === "" && synopsis === "" && rating === "" && debut === "" && type === "")
};
const getAnimeCharacters = async(title) =>{
const getAnimeCharacters = async (title) => {
const res = await cloudscraper(`${BASE_JIKAN}search/anime?q=${title}`);
const matchAnime = JSON.parse(res).results.filter(x => x.title === title);
const malId = matchAnime[0].mal_id;
if(typeof matchAnime[0].mal_id === 'undefined') return null;
if (typeof matchAnime[0].mal_id === 'undefined') return null;
const jikanCharactersURL = `${BASE_JIKAN}anime/${malId}/characters_staff`;
const data = await cloudscraper.get(jikanCharactersURL);
let body = JSON.parse(data).characters;
if(typeof body === 'undefined') return null;
if (typeof body === 'undefined') return null;
const charactersId = body.map(doc =>{
const charactersId = body.map(doc => {
return doc.mal_id
})
const charactersNames = body.map(doc => {
return doc.name;
});
const charactersImages = body.map(doc =>{
const charactersImages = body.map(doc => {
return doc.image_url
});
let characters = [];
Array.from({length: charactersNames.length} , (v , k) =>{
Array.from({length: charactersNames.length}, (v, k) => {
const id = charactersId[k];
let name = charactersNames[k];
let characterImg = charactersImages[k];
@ -129,19 +150,19 @@ const getAnimeCharacters = async(title) =>{
return Promise.all(characters);
};
const getAnimeVideoPromo = async(title) =>{
const getAnimeVideoPromo = async (title) => {
const res = await cloudscraper(`${BASE_JIKAN}search/anime?q=${title}`);
const matchAnime = JSON.parse(res).results.filter(x => x.title === title);
const malId = matchAnime[0].mal_id;
if(typeof matchAnime[0].mal_id === 'undefined') return null;
if (typeof matchAnime[0].mal_id === 'undefined') return null;
const jikanCharactersURL = `${BASE_JIKAN}anime/${malId}/videos`;
const data = await cloudscraper.get(jikanCharactersURL);
const body = JSON.parse(data).promo;
const promises = [];
body.map(doc =>{
body.map(doc => {
promises.push({
title: doc.title,
previewImage: doc.image_url,
@ -152,19 +173,19 @@ const getAnimeVideoPromo = async(title) =>{
return Promise.all(promises);
};
const animeExtraInfo = async(title) =>{
const animeExtraInfo = async (title) => {
const res = await cloudscraper(`${BASE_JIKAN}search/anime?q=${title}`);
const matchAnime = JSON.parse(res).results.filter(x => x.title === title);
const malId = matchAnime[0].mal_id;
if(typeof matchAnime[0].mal_id === 'undefined') return null;
if (typeof matchAnime[0].mal_id === 'undefined') return null;
const animeDetails = `${BASE_JIKAN}anime/${malId}`;
const data = await cloudscraper.get(animeDetails);
const body = Array(JSON.parse(data));
const promises = [];
body.map(doc =>{
body.map(doc => {
let airDay
@ -219,7 +240,7 @@ const animeExtraInfo = async(title) =>{
titleJapanese: doc.title_japanese,
source: doc.source,
totalEpisodes: doc.episodes,
aired:{
aired: {
from: doc.aired.from,
to: doc.aired.to
},
@ -236,20 +257,21 @@ const animeExtraInfo = async(title) =>{
return Promise.all(promises);
};
const imageUrlToBase64 = async(url) => {
return await base64.encode(url, {string:true});
const imageUrlToBase64 = async (url) => {
return await base64.encode(url, {string: true});
};
const search = async() =>{ }
const search = async () => {
}
const searchAnime = async(query) => {
const searchAnime = async (query) => {
const res = await cloudscraper(`${SEARCH_URL}${query}`);
const body = await res;
const $ = cheerio.load(body);
const promises = [];
$('div.Container ul.ListAnimes li article').each((index , element) =>{
$('div.Container ul.ListAnimes li article').each((index, element) => {
const $element = $(element);
const id = $element.find('div.Description a.Button').attr('href').slice(1);
const title = $element.find('a h3').text();
@ -269,22 +291,22 @@ const searchAnime = async(query) => {
};
const transformUrlServer = async(urlReal) =>{
const transformUrlServer = async (urlReal) => {
let res
let body
const promises = []
for(i = 0; i <= urlReal.length -1; i++){
for (i = 0; i <= urlReal.length - 1; i++) {
switch (urlReal[i].server) {
case "amus":
res = await cloudscraper(urlReal[i].code.replace("embed","check"));
res = await cloudscraper(urlReal[i].code.replace("embed", "check"));
body = await res;
urlReal[i].code = JSON.parse(body).file
urlReal[i].direct = true
break;
case "natsuki":
res = await cloudscraper(urlReal[i].code.replace("embed","check"));
res = await cloudscraper(urlReal[i].code.replace("embed", "check"));
body = await res;
urlReal[i].code = JSON.parse(body).file
urlReal[i].direct = true
@ -295,7 +317,7 @@ const transformUrlServer = async(urlReal) =>{
}
}
urlReal.map(doc =>{
urlReal.map(doc => {
promises.push({
id: doc.title.toLowerCase(),
url: doc.code,
@ -317,7 +339,6 @@ const obtainPreviewNews = (encoded) => {
.substring(encoded.indexOf("<img src=\""), encoded.indexOf("\" alt"))
.substring(10).replace("http", "https")
.replace("httpss", "https")
} else if (encoded.includes('<img')) {
image = encoded.split("src=")[1].split(" class=")[0].replace("\"", '').replace('\"','')
} else if (encoded.includes('https://www.youtube.com/embed/')) {

Loading…
Cancel
Save