v2.7.0 - Optimizations, acceleration, and refactoring

v2 v2.7.0
Jéluchu 5 years ago
parent 78ada322f0
commit 2b88dfb7a1

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

3282
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
{ {
"name": "aruppi", "name": "aruppi",
"version": "2.6.8", "version": "2.7.0",
"description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app", "description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app",
"main": "./src/api/api.js", "main": "./src/api/api.js",
"scripts": { "scripts": {
@ -49,9 +49,9 @@
"express": "^4.16.4", "express": "^4.16.4",
"got": "^11.3.0", "got": "^11.3.0",
"helmet": "^3.23.3", "helmet": "^3.23.3",
"hooman": "^1.2.5", "hooman": "^1.2.6",
"node-fetch": "^2.6.0",
"rss-to-json": "^1.1.1", "rss-to-json": "^1.1.1",
"tough-cookie": "^4.0.0", "tough-cookie": "^4.0.0"
"node-fetch": "^2.6.0"
} }
} }

@ -16,8 +16,6 @@ const {
transformUrlServer, transformUrlServer,
obtainPreviewNews, obtainPreviewNews,
structureThemes, structureThemes,
getAnimes,
getDirectory,
helper, helper,
videoServersJK, videoServersJK,
getThemes getThemes
@ -27,39 +25,39 @@ const ThemeParser = require('../utils/animetheme');
const parserThemes = new ThemeParser() const parserThemes = new ThemeParser()
const { const {
BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE, GENRES_URL, BASE_THEMEMOE BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE, GENRES_URL, BASE_THEMEMOE, BASE_ANIMEFLV
} = require('./urls'); } = require('./urls');
const schedule = async (day) =>{ const schedule = async (day) =>{
let options = { parse: true } const data = await homgot(`${BASE_JIKAN}schedule/${day.current}`, { parse: true });
const data = await homgot(`${BASE_JIKAN}schedule/${day.current}`, options);
const body = data[day.current];
const promises = []
body.map(doc =>{
promises.push({ return data[day.current].map(doc =>({
title: doc.title, title: doc.title,
malid: doc.mal_id, malid: doc.mal_id,
image: doc.image_url image: doc.image_url
}); }));
}); };
return promises; const top = async (top) =>{
}; const data = await homgot(`${BASE_JIKAN}top/${top.type}/${top.page}/${top.subtype}`, { parse: true });
return data.top.map(doc => ({
rank: doc.rank,
title: doc.title,
image: doc.image_url,
type: doc.type,
startDate: doc.start_date,
endDate: doc.end_date
}));
const top = async (type, subtype, page) =>{
let options = { parse: true }
const data = await homgot(`${BASE_JIKAN}top/${type}/${page}/${subtype}`, options);
return data.top;
}; };
const getAllAnimes = async () =>{ const getAllAnimes = async () =>{
let data = await getAnimes() let data = await homgot(`${BASE_ANIMEFLV}api/animes/list`, { parse: true })
return data.map(item => ({ return data.map(item => ({
index: item[0], index: item[0],
@ -71,7 +69,24 @@ const getAllAnimes = async () =>{
}; };
const getAllDirectory = async () =>{ return await getDirectory(); }; const getAllDirectory = async () =>{
let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
return data.map(doc => ({
id: doc.id,
title: doc.title,
mal_title: doc.mal_title,
poster: doc.poster,
type: doc.type,
genres: doc.genres,
state: doc.state,
score: doc.score,
jkanime: false,
description: doc.description
}));
};
const getAnitakume = async () =>{ const getAnitakume = async () =>{
@ -112,7 +127,7 @@ const getAnitakume = async () =>{
const getNews = async (pageRss) =>{ const getNews = async (pageRss) =>{
const promises = [] let promises = []
for(let i = 0; i <= pageRss.length -1; i++) { for(let i = 0; i <= pageRss.length -1; i++) {
@ -139,70 +154,43 @@ const getNews = async (pageRss) =>{
}; };
const season = async (year, type) =>{ const season = async (season) =>{
let options = { parse: true } const data = await homgot(`${BASE_JIKAN}season/${season.year}/${season.type}`, { parse: true });
const data = await homgot(`${BASE_JIKAN}season/${year}/${type}`, options);
let body = data.anime;
const promises = []
body.map(doc =>{
promises.push({ return data.anime.map(doc =>({
title: doc.title, title: doc.title,
malid: doc.mal_id, image: doc.image_url,
image: doc.image_url, genres: doc.genres.map(x => x.name)
genres: doc.genres.map(x => x.name) }));
});
});
return promises;
}; };
const allSeasons = async () =>{ const allSeasons = async () =>{
let options = { parse: true } const data = await homgot(`${BASE_JIKAN}season/archive`, { parse: true });
const data = await homgot(`${BASE_JIKAN}season/archive`, options);
let body = data.archive;
const promises = []
body.map(doc =>{
promises.push({ return data.archive.map(doc =>({
year: doc.year, year: doc.year,
seasons: doc.seasons, seasons: doc.seasons,
}); }));
});
return promises;
}; };
const laterSeasons = async () =>{ const laterSeasons = async () =>{
let options = { parse: true } const data = await homgot(`${BASE_JIKAN}season/later`, { parse: true });
const data = await homgot(`${BASE_JIKAN}season/later`, options);
let body = data.anime;
const promises = []
body.map(doc =>{
promises.push({ return data.anime.map(doc =>({
malid: doc.mal_id,
title: doc.title, title: doc.title,
image: doc.image_url image: doc.image_url
}); }));
});
return promises;
}; };
const getLastEpisodes = async () =>{ const getLastEpisodes = async () =>{
let options = { parse: true } const data = await homgot(`${BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, { parse: true });
const data = await homgot(`${BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, options);
let body = data.episodes; let body = data.episodes;
const promises = [] const promises = []
@ -222,16 +210,11 @@ const getLastEpisodes = async () =>{
}; };
const getSpecials = async (type, subType, page) =>{ const getSpecials = async (data) =>{
let options = { parse: true }
const data = await homgot(`${BASE_ANIMEFLV_JELU}${type.url}/${subType}/${page}`, options);
let body = data[type.prop];
const promises = []
body.map(doc =>{ const res = await homgot(`${BASE_ANIMEFLV_JELU}${data.url}/${data.type}/${data.page}`, { parse: true });
promises.push({ return res[data.prop].map(doc =>({
id: doc.id, id: doc.id,
title: doc.title, title: doc.title,
type: doc.type, type: doc.type,
@ -242,163 +225,75 @@ const getSpecials = async (type, subType, page) =>{
rate: doc.rating, rate: doc.rating,
genres: doc.genres.map(x => x), genres: doc.genres.map(x => x),
episodes: doc.episodes.map(x => x) episodes: doc.episodes.map(x => x)
}); }));
});
return promises;
}; };
const getMoreInfo = async (title) =>{ const getMoreInfo = async (title) =>{
const promises = [] const promises = []
let animeTitle = ''
let animeId = ''
let animeType = ''
let animeIndex = ''
let seriesTitle
let position
const jkAnimeTitles = [
{ title: 'The God of High School', id: 'the-god-of-high-school' },
{ title: 'Kami no Tou', id: 'kami-no-tou' },
{ title: 'BNA', id: 'bna' },
{ title: 'Ansatsu Kyoushitsu (TV)', id: 'ansatsu-kyoushitsu-tv' },
{ title: 'Ansatsu Kyoushitsu (TV) 2nd Season', id: 'ansatsu-kyoushitsu-tv-2nd-season' }
];
const jkMyAnimetitles = [
{ jkanime: 'Ansatsu Kyoushitsu (TV)', myanimelist: 'Ansatsu Kyoushitsu'},
{ jkanime: 'Ansatsu Kyoushitsu (TV) 2nd Season', myanimelist: 'Ansatsu Kyoushitsu 2nd Season' }
];
let jkanime = false
let jkanimeID
let jkanimeName
for (let name in jkAnimeTitles) {
if (title === jkAnimeTitles[name].title) {
jkanime = true
jkanimeID = jkAnimeTitles[name].id
for (let name in jkMyAnimetitles) {
if (title === jkMyAnimetitles[name].jkanime || title === jkMyAnimetitles[name].myanimelist) {
jkanimeName = jkMyAnimetitles[name].myanimelist
position = name
}
}
if (jkanimeName === undefined) { let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
jkanimeName = jkAnimeTitles[name].title const res = data.filter(x => x.title === title || x.mal_title === title)[0];
}
}
}
if (jkanime === false) { if (!res.jkanime) {
const titles = [ if (res.type === 'Anime') {
{ animeflv: 'Kaguya-sama wa Kokurasetai: Tensai-tachi no Renai Zunousen 2nd Season', myanimelist: 'Kaguya-sama wa Kokurasetai?: Tensai-tachi no Renai Zunousen', alternative: 'Kaguya-sama wa Kokurasetai'},
{ animeflv: 'Naruto Shippuden', myanimelist: 'Naruto: Shippuuden' },
{ animeflv: 'Rock Lee no Seishun Full-Power Ninden', myanimelist: 'Naruto SD: Rock Lee no Seishun Full-Power Ninden' },
{ animeflv: 'BAKI: dai reitaisai-hen', myanimelist: 'Baki 2nd Season' },
{ animeflv: 'Hitoribocchi no ○○ Seikatsu', myanimelist: 'Hitoribocchi no Marumaru Seikatsu' },
{ animeflv: 'Nekopara (TV)', myanimelist: 'Nekopara' },
{ animeflv: 'Black Clover (TV)', myanimelist: 'Black Clover' }
];
for (let name in titles) {
if (title === titles[name].animeflv || title === titles[name].myanimelist || title === titles[name].alternative) {
seriesTitle = titles[name].animeflv
position = name
}
}
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)
});
if (seriesTitle === undefined) {
seriesTitle = title
} }
else {
await getAllAnimes().then(animes => { promises.push({
title: res.title || null,
for (const i in animes) { poster: res.poster || null,
if (animes[i].title.split('\t')[0] === seriesTitle.split('\t')[0] || synopsis: res.description || null,
animes[i].title === `${seriesTitle} (TV)` || status: res.state || null,
animes[i].title.includes(seriesTitle.split('○')[0]) type: res.type || null,
) { rating: res.score || null,
if (animes[i].title.includes('(TV)', 0)) { animeTitle = animes[i].title.split('\t')[0].replace(' (TV)', '') } genres: res.genres || null,
else { animeTitle = animes[i].title.split('\t')[0] } episodes: await animeflvInfo(res.id).then(episodes => episodes || null)
animeId = animes[i].id });
animeIndex = animes[i].index
animeType = animes[i].type.toLowerCase()
if (position !== undefined) {
seriesTitle = titles[position].myanimelist
}
break;
}
}
});
try{
if (animeType === 'tv') {
promises.push(await animeflvInfo(animeId, animeIndex).then(async extra => ({
title: animeTitle || null,
poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null,
synopsis: extra.animeExtraInfo[0].synopsis || null,
status: 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(seriesTitle).then(info =>{
return info || null
}),
promo: await getAnimeVideoPromo(seriesTitle).then(promo =>{
return promo || null
}),
characters: await getAnimeCharacters(seriesTitle).then(characters =>{
return characters || null
})
})));
} else {
promises.push(await animeflvInfo(animeId).then(async extra => ({
title: animeTitle || null,
poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null,
synopsis: extra.animeExtraInfo[0].synopsis || null,
status: 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,
})));
}
}catch(err){
console.log(err)
} }
} else { } else {
promises.push(await jkanimeInfo(jkanimeID).then(async extra => ({ if (res.type === 'Anime') {
title: jkanimeName || null, promises.push({
poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, title: res.title || null,
synopsis: extra.animeExtraInfo[0].synopsis || null, poster: res.poster || null,
status: extra.animeExtraInfo[0].debut || null, synopsis: res.description || null,
type: extra.animeExtraInfo[0].type || null, status: res.state || null,
rating: extra.animeExtraInfo[0].rating || null, type: res.type || null,
genres: extra.genres || null, rating: res.score || null,
episodes: extra.listByEps || null, genres: res.genres || null,
moreInfo: await animeExtraInfo(jkanimeName).then(info =>{ episodes: await jkanimeInfo(res.id).then(episodes => episodes || null),
return info || null moreInfo: await animeExtraInfo(res.mal_title).then(info => info || null),
}), promo: await getAnimeVideoPromo(res.mal_title).then(promo => promo || null),
promo: await getAnimeVideoPromo(jkanimeName).then(promo =>{ characters: await getAnimeCharacters(res.mal_title).then(characters => characters || null)
return promo || null });
}), }
characters: await getAnimeCharacters(jkanimeName).then(characters =>{ else {
return characters || null 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)
});
}
} }
return promises; return promises;
@ -407,33 +302,11 @@ const getMoreInfo = async (title) =>{
const getAnimeServers = async (id) => { const getAnimeServers = async (id) => {
const jkAnimeIDs = [ if (isNaN(id.split('/')[0])) {
{ id: 'the-god-of-high-school' }, return await videoServersJK(id)
{ id: 'kami-no-tou' },
{ id: 'bna' },
{ id: 'ansatsu-kyoushitsu-tv' },
{ id: 'ansatsu-kyoushitsu-tv-2nd-season' }
];
let jkanime = false
let jkanimeID
for (let name in jkAnimeIDs) {
if (id.includes(jkAnimeIDs[name].id)) {
jkanime = true
jkanimeID = id
}
}
if (jkanime === false) {
let options = { parse: true }
const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, options);
let body = data.servers;
return await transformUrlServer(body);
} else { } else {
return await videoServersJK(jkanimeID) const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true });
return await transformUrlServer(data.servers);
} }
}; };
@ -442,60 +315,37 @@ const search = async (title) =>{ return await searchAnime(title); };
const getImages = async (query) => { const getImages = async (query) => {
let options = { parse: true } const data = await homgot(`${BASE_QWANT}count=${query.count}&q=${query.title}&t=${query.type}&safesearch=${query.safesearch}&locale=${query.country}&uiv=4`, { parse: true });
const data = await homgot(`${BASE_QWANT}count=${query.count}&q=${query.title}&t=${query.type}&safesearch=${query.safesearch}&locale=${query.country}&uiv=4`, options);
const body = data.data.result.items;
const promises = []
body.map(doc =>{
promises.push({ return data.data.result.items.map(doc =>({
type: doc.thumb_type, type: doc.thumb_type,
thumbnail: `https:${doc.thumbnail}`, thumbnail: `https:${doc.thumbnail}`,
fullsize: `https:${doc.media_fullsize}` fullsize: `https:${doc.media_fullsize}`
}); }));
});
return promises;
}; };
const getYoutubeVideos = async (channelId) => { const getYoutubeVideos = async (channelId) => {
let options = { parse: true } const data = await homgot(`${BASE_YOUTUBE}${channelId.id}&part=${channelId.part}&order=${channelId.order}&maxResults=${channelId.maxResults}`, { parse: true });
const data = await homgot(`${BASE_YOUTUBE}${channelId.id}&part=${channelId.part}&order=${channelId.order}&maxResults=${channelId.maxResults}`, options);
const body = data[channelId.prop];
const promises = []
body.map(doc =>{
promises.push({
title: doc.snippet.title,
videoId: doc.id.videoId,
thumbDefault: doc.snippet.thumbnails.default.url,
thumbMedium: doc.snippet.thumbnails.medium.url,
thumbHigh: doc.snippet.thumbnails.high.url
});
}); return data[channelId.prop].map(doc =>({
title: doc.snippet.title,
return promises; videoId: doc.id.videoId,
thumbDefault: doc.snippet.thumbnails.default.url,
thumbMedium: doc.snippet.thumbnails.medium.url,
thumbHigh: doc.snippet.thumbnails.high.url
}));
}; };
const getRadioStations = async () => { const getRadioStations = async () => require('../assets/radiostations.json');
return require('../assets/radiostations.json');
}
const getOpAndEd = async (title) => { const getOpAndEd = async (title) => await structureThemes(await parserThemes.serie(title), true);
let data = await parserThemes.serie(title)
return await structureThemes(data, true)
};
const getThemesYear = async (year) => { const getThemesYear = async (year) => {
let data = []
let data = []
if (year === undefined) { if (year === undefined) {
return await parserThemes.allYears(); return await parserThemes.allYears();
} else { } else {
@ -507,29 +357,23 @@ const getThemesYear = async (year) => {
const getRandomTheme = async () => { const getRandomTheme = async () => {
let promise = [] let data = await homgot(`${BASE_THEMEMOE}roulette`, { parse: true });
let options = { parse: true }
const data = await homgot(`${BASE_THEMEMOE}roulette`, options);
let themes = await getThemes(data.themes) let themes = await getThemes(data.themes)
promise.push({ return themes.map(doc =>({
name: data.name, name: data.name,
title: themes[0].name, title: doc.name,
link: themes[0].video link: doc.video
}) }));
return promise;
}; };
const getArtist = async (id) => { const getArtist = async (id) => {
let data
if (id === undefined) { if (id === undefined) {
return await parserThemes.artists(); return await parserThemes.artists();
} else { } else {
data = await parserThemes.artist(id) return await structureThemes(await parserThemes.artist(id), false)
return await structureThemes(data, false)
} }
}; };
@ -538,15 +382,13 @@ const getAnimeGenres = async(genre, order, page) => {
let $ let $
let promises = [] let promises = []
let options = { scrapy: true }
if (page !== undefined) { if (page !== undefined) {
$ = await homgot(`${GENRES_URL}genre%5B%5D=${genre}&order=${order}&page=${page}`,options) $ = await homgot(`${GENRES_URL}genre%5B%5D=${genre}&order=${order}&page=${page}`,{ scrapy: true })
} else { } else {
$ = await homgot(`${GENRES_URL}genre%5B%5D=${genre}&order=${order}`,options) $ = await homgot(`${GENRES_URL}genre%5B%5D=${genre}&order=${order}`,{ scrapy: true })
} }
$('div.Container ul.ListAnimes li article').each((index , element) =>{ $('div.Container ul.ListAnimes li article').each((index , element) =>{
const $element = $(element); const $element = $(element);
const id = $element.find('div.Description a.Button').attr('href').slice(1); const id = $element.find('div.Description a.Button').attr('href').slice(1);
@ -574,10 +416,7 @@ const getAnimeGenres = async(genre, order, page) => {
}; };
const getAllThemes = async () => { const getAllThemes = async () => await structureThemes(await parserThemes.all(), false);
let data = await parserThemes.all()
return await structureThemes(data, false)
};
module.exports = { module.exports = {
schedule, schedule,

@ -25,11 +25,9 @@ router.get('/schedule/:day' , (req, res) =>{
router.get('/top/:type/:subtype/:page' , (req, res) =>{ router.get('/top/:type/:subtype/:page' , (req, res) =>{
let type = req.params.type; let top = {type: req.params.type, subtype: req.params.subtype, page: req.params.page}
let subtype = req.params.subtype;
let page = req.params.page;
api.top(type, subtype, page) api.top(top)
.then(top =>{ .then(top =>{
if (top.length > 0) { if (top.length > 0) {
res.status(200).json({ res.status(200).json({
@ -121,10 +119,9 @@ router.get('/news' , (req, res) =>{
router.get('/season/:year/:type' , (req, res) =>{ router.get('/season/:year/:type' , (req, res) =>{
let year = req.params.year; let season = {year: req.params.year, type: req.params.type}
let type = req.params.type;
api.season(year, type) api.season(season)
.then(season =>{ .then(season =>{
if (season.length > 0) { if (season.length > 0) {
res.status(200).json({ res.status(200).json({
@ -192,11 +189,9 @@ router.get('/lastEpisodes' , (req, res) =>{
router.get('/movies/:type/:page' , (req, res) =>{ router.get('/movies/:type/:page' , (req, res) =>{
let type = {url: 'Movies', prop: 'movies'} let data = {url: 'Movies', prop: 'movies', type: req.params.type, page: req.params.page }
let subType = req.params.type;
let page = req.params.page;
api.getSpecials(type, subType, page) api.getSpecials(data)
.then(movies =>{ .then(movies =>{
if (movies.length > 0) { if (movies.length > 0) {
res.status(200).json({ res.status(200).json({
@ -213,11 +208,9 @@ router.get('/movies/:type/:page' , (req, res) =>{
router.get('/ovas/:type/:page' , (req, res) =>{ router.get('/ovas/:type/:page' , (req, res) =>{
let type = {url: 'Ova', prop: 'ova'} let data = {url: 'Ova', prop: 'ova', type: req.params.type, page: req.params.page }
let subType = req.params.type;
let page = req.params.page;
api.getSpecials(type, subType, page) api.getSpecials(data)
.then(ovas =>{ .then(ovas =>{
if (ovas.length > 0) { if (ovas.length > 0) {
res.status(200).json({ res.status(200).json({
@ -234,11 +227,9 @@ router.get('/ovas/:type/:page' , (req, res) =>{
router.get('/specials/:type/:page' , (req, res) =>{ router.get('/specials/:type/:page' , (req, res) =>{
let type = {url: 'Special', prop: 'special'} let data = {url: 'Special', prop: 'special', type: req.params.type, page: req.params.page }
let subType = req.params.type;
let page = req.params.page;
api.getSpecials(type, subType, page) api.getSpecials(data)
.then(specials =>{ .then(specials =>{
if (specials.length > 0) { if (specials.length > 0) {
res.status(200).json({ res.status(200).json({
@ -255,11 +246,9 @@ router.get('/specials/:type/:page' , (req, res) =>{
router.get('/tv/:type/:page' , (req, res) =>{ router.get('/tv/:type/:page' , (req, res) =>{
let type = {url: 'Tv', prop: 'tv'} let data = {url: 'Tv', prop: 'tv', type: req.params.type, page: req.params.page }
let subType = req.params.type;
let page = req.params.page;
api.getSpecials(type, subType, page) api.getSpecials(data)
.then(tv =>{ .then(tv =>{
if (tv.length > 0) { if (tv.length > 0) {
res.status(200).json({ res.status(200).json({

@ -14,8 +14,6 @@ app.use(cors());
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.set('Cache-Control', 'no-store'); res.set('Cache-Control', 'no-store');
res.redirect('/api/') res.redirect('/api/')

File diff suppressed because it is too large Load Diff

@ -1,8 +1,6 @@
const app = require('./app'); const app = require('./app');
const port = process.env.PORT || 5000; const port = process.env.PORT || 5000;
const addr = isNaN(port) ? const addr = isNaN(port) ? '' : (process.env.ADDR || '0.0.0.0');
'' :
(process.env.ADDR || '0.0.0.0');
server = app.listen(port, addr, () => { server = app.listen(port, addr, () => {
/* eslint-disable no-console */ /* eslint-disable no-console */
@ -11,7 +9,7 @@ server = app.listen(port, addr, () => {
}); });
function shutdown() { function shutdown() {
server.close(); // socket file is automatically removed here server.close();
process.exit(); process.exit();
} }

@ -1,5 +1,5 @@
const { const {
BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, SEARCH_URL, SEARCH_DIRECTORY, BASE_ARUPPI, BASE_JKANIME, JKANIME_URL BASE_ANIMEFLV, BASE_JIKAN, BASE_ARUPPI, BASE_JKANIME
} = require('../api/urls'); } = require('../api/urls');
const { const {
@ -21,23 +21,17 @@ global.btoa = btoa;
async function videoServersJK(id) { async function videoServersJK(id) {
let options = { scrapy: true } const $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true });
const $ = await homgot(`${BASE_JKANIME}${id}`, options);
const scripts = $('script'); const scripts = $('script');
const episodes = $('div#reproductor-box li'); const episodes = $('div#reproductor-box li');
const serverNames = []; const serverNames = [];
let servers = []; let servers = [];
episodes.each((index , element) =>{ episodes.each((index , element) => serverNames.push($(element).find('a').text()))
const $element = $(element);
const serverName = $element.find('a').text();
serverNames.push(serverName);
})
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const $script = $(scripts[i]); const contents = $(scripts[i]).html();
const contents = $script.html();
try{ try{
if ((contents || '').includes('var video = [];')) { if ((contents || '').includes('var video = [];')) {
Array.from({length: episodes.length} , (v , k) =>{ Array.from({length: episodes.length} , (v , k) =>{
@ -67,8 +61,7 @@ async function videoServersJK(id) {
async function getVideoURL(url) { async function getVideoURL(url) {
let options = { scrapy: true } const $ = await homgot(url, { scrapy: true });
const $ = await homgot(url, options);
const video = $('video'); const video = $('video');
if(video.length){ if(video.length){
@ -88,207 +81,76 @@ async function getVideoURL(url) {
const jkanimeInfo = async (id) => { const jkanimeInfo = async (id) => {
let poster = "" let $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true });
let banner = ""
let synopsis = ""
let rating = ""
let debut = ""
let type = ""
let $
try {
let options = { scrapy: true }
$ = await homgot(`${BASE_JKANIME}${id}`, options);
const animeExtraInfo = [];
const genres = [];
let listByEps;
poster = $('div[id="container"] div.serie-info div.cap-portada')[0].children[1].attribs.src;
banner = $('div[id="container"] div.serie-info div.cap-portada')[0].children[1].attribs.src;
synopsis = $('div[id="container"] div.serie-info div.sinopsis-box p')[0].children[1].data;
rating = "Sin calificación"
debut = $('div[id="container"] div.serie-info div.info-content div')[6].children[3].children[0].children[0].data;
type = $('div[id="container"] div.serie-info div.info-content div')[0].children[3].children[0].data
animeExtraInfo.push({
poster: poster,
banner: banner,
synopsis: synopsis,
rating: rating,
debut: debut,
type: type,
})
let rawGenres = $('div[id="container"] div.serie-info div.info-content div')[1].children[3].children
for (let i = 0; i <= rawGenres.length -1; i++) {
if (rawGenres[i].name === 'a') {
const genre = rawGenres[i].children[0].data
genres.push(genre)
}
}
let nextEpisodeDate let nextEpisodeDate
let rawNextEpisode = $('div[id="container"] div.left-container div[id="proxep"] p')[0] let rawNextEpisode = $('div[id="container"] div.left-container div[id="proxep"] p')[0]
if (rawNextEpisode === undefined) { if (rawNextEpisode === undefined) {
nextEpisodeDate = null
} else {
if (rawNextEpisode.children[1].data === ' ') {
nextEpisodeDate = null nextEpisodeDate = null
} else { } else {
if (rawNextEpisode.children[1].data === ' ') { nextEpisodeDate = rawNextEpisode.children[1].data.trim()
nextEpisodeDate = null
} else {
nextEpisodeDate = rawNextEpisode
}
}
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];
let imagePreview = $('div[id="container"] div.content-box div[id="episodes-content"]')[0].children[1].children[3].attribs.src
let link = `${animeId}/${episode}`
animeListEps.push({
episode: episode,
id: link,
imagePreview: imagePreview
})
} }
}
listByEps = animeListEps; 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){}
return {listByEps, genres, animeExtraInfo}; 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];
let link = `${animeId}/${episode}`
} catch (err) { animeListEps.push({
console.error(err) episode: episode,
id: link
})
} }
return animeListEps;
}; };
const animeflvGenres = async (id) => { const animeflvGenres = async (id) => {
const promises = []; let $ = await homgot(`${BASE_ANIMEFLV}${id}`, { scrapy: true });
let options = { scrapy: true }
let $ = await homgot(`${BASE_ANIMEFLV}${id}`, options);
$('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => { $('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => {
const $element = $(element); return $(element).attr('href').split('=')[1] || null;
const genre = $element.attr('href').split('=')[1] || null;
promises.push(genre);
}); });
return promises;
} }
const animeflvInfo = async (id, index) => { const animeflvInfo = async (id) => {
let poster = ""
let banner = ""
let synopsis = ""
let rating = ""
let debut = ""
let type = ""
let $
try {
let options = { scrapy: true }
$ = await homgot(`${BASE_ANIMEFLV}anime/${id}`, options);
const scripts = $('script'); let $ = await homgot(`${BASE_ANIMEFLV}anime/${id}`, { scrapy: true });
const anime_info_ids = []; let scripts = $('script').toArray();
const anime_eps_data = [];
const animeExtraInfo = [];
const genres = [];
let listByEps;
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,
banner: banner,
synopsis: synopsis,
rating: rating,
debut: debut,
type: type,
})
$('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => { for (const pata in scripts) {
const $element = $(element); if (scripts[pata].children.length > 0) {
const genre = $element.attr('href').split('=')[1] || null; if (scripts[pata].children[0].data.includes('var episodes')){
genres.push(genre);
});
let scriptInnerHTML = scripts[pata].children[0].data.trim()
const startIndex = scriptInnerHTML.indexOf('var episodes') + 'var episodes'.length
const endIndex = scriptInnerHTML.indexOf(';', startIndex)
Array.from({length: scripts.length}, (v, k) => { const episodesJSON = JSON.parse(scriptInnerHTML.substring(startIndex, endIndex).split('=')[1].trim())
const $script = $(scripts[k]); return episodesJSON.map(item => ({
const contents = $script.html(); index: item[0],
if ((contents || '').includes('var anime_info = [')) { id: `${item[1]}/${id}-${item[0]}`,
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)
anime_eps_data.push(eps_data);
}
});
const AnimeThumbnailsId = index;
const animeId = id;
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)) {
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]);
let episode = data[0];
let id = data[1];
let imagePreview = `${BASE_EPISODE_IMG_URL}${AnimeThumbnailsId}/${episode}/th_3.jpg`
let link = `${id}/${animeId}-${episode}`
animeListEps.push({
episode: episode,
id: link,
imagePreview: imagePreview
})
})
listByEps = animeListEps;
return {listByEps, genres, animeExtraInfo};
} catch (err) {
console.error(err)
} }
}; };
@ -296,28 +158,21 @@ const animeflvInfo = async (id, index) => {
const getAnimeCharacters = async (title) => { const getAnimeCharacters = async (title) => {
try { try {
let options = { parse: true }
const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`, options); const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`, { parse: true });
const matchAnime = res.results.filter(x => x.title === title); const matchAnime = res.results.filter(x => x.title === title);
const malId = matchAnime[0].mal_id; const malId = matchAnime[0].mal_id;
if (typeof matchAnime[0].mal_id === 'undefined') return null; if (typeof malId === 'undefined') return null;
const data = await homgot(`${BASE_JIKAN}anime/${malId}/characters_staff`, options); const data = await homgot(`${BASE_JIKAN}anime/${malId}/characters_staff`, { parse: true });
let body = data.characters; let body = data.characters;
if (typeof body === 'undefined') return null; if (typeof body === 'undefined') return null;
const charactersId = body.map(doc => { const charactersId = body.map(doc => doc.mal_id)
return doc.mal_id const charactersNames = body.map(doc => doc.name);
}) const charactersImages = body.map(doc => doc.image_url);
const charactersNames = body.map(doc => {
return doc.name;
});
const charactersImages = body.map(doc => {
return doc.image_url
});
let characters = []; let characters = [];
Array.from({length: charactersNames.length}, (v, k) => { Array.from({length: charactersNames.length}, (v, k) => {
@ -341,14 +196,14 @@ const getAnimeCharacters = async (title) => {
const getAnimeVideoPromo = async (title) => { const getAnimeVideoPromo = async (title) => {
try { try {
let options = { parse: true }
const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`, options); const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`, { parse: true });
const matchAnime = res.results.filter(x => x.title === title); const matchAnime = res.results.filter(x => x.title === title);
const malId = matchAnime[0].mal_id; const malId = matchAnime[0].mal_id;
if (typeof matchAnime[0].mal_id === 'undefined') return null; if (typeof malId === 'undefined') return null;
const data = await homgot(`${BASE_JIKAN}anime/${malId}/videos`, options); const data = await homgot(`${BASE_JIKAN}anime/${malId}/videos`, { parse: true });
const body = data.promo; const body = data.promo;
const promises = []; const promises = [];
@ -371,14 +226,13 @@ const animeExtraInfo = async (title) => {
try { try {
let options = { parse: true } const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`, { parse: true });
const res = await homgot(`${BASE_JIKAN}search/anime?q=${title}`, options);
const matchAnime = res.results.filter(x => x.title === title); const matchAnime = res.results.filter(x => x.title === title);
const malId = matchAnime[0].mal_id; const malId = matchAnime[0].mal_id;
if (typeof matchAnime[0].mal_id === 'undefined') return null; if (typeof malId === 'undefined') return null;
const data = await homgot(`${BASE_JIKAN}anime/${malId}`, options); const data = await homgot(`${BASE_JIKAN}anime/${malId}`, { parse: true });
const body = Array(data); const body = Array(data);
const promises = []; const promises = [];
@ -433,7 +287,6 @@ const animeExtraInfo = async (title) => {
console.log(e.message) console.log(e.message)
} }
}; };
const imageUrlToBase64 = async (url) => { const imageUrlToBase64 = async (url) => {
@ -445,93 +298,41 @@ const helper = async () => {}
const searchAnime = async (query) => { const searchAnime = async (query) => {
let $ let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
let promises = [] const res = data.filter(x => x.title.includes(query));
const jkAnimeTitles = [
{ title: 'BNA', search: 'BNA'},
{ title: 'The God of High School', search: 'The god' },
{ title: 'Ansatsu Kyoshitsu', search: 'Assassination Classroom' },
];
let jkanime = false
let jkanimeName
for (let name in jkAnimeTitles) {
if (query === jkAnimeTitles[name].title) {
jkanime = true
jkanimeName = jkAnimeTitles[name].search
}
}
if (jkanime === false) {
let options = { scrapy: true }
$ = await homgot(`${SEARCH_URL}${query}`, options);
$('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();
let poster = $element.find('a div.Image figure img').attr('src') || $element.find('a div.Image figure img').attr('data-cfsrc');
const type = $element.find('div.Description p span.Type').text();
promises.push(helper().then(async () => ({
id: id || null,
title: title || null,
type: type || null,
image: await imageUrlToBase64(poster) || null
})));
})
} else {
let options = { scrapy: true } return res.map(doc => ({
$ = await homgot(`${JKANIME_URL}${jkanimeName}`, options); id: doc.id || null,
title: doc.title || null,
$('.portada-box').each(function (index, element) { type: doc.type || null,
const $element = $(element); image: doc.poster || null
const title = $element.find('h2.portada-title a').attr('title'); }));
const id = $element.find('a.let-link').attr('href').split('/')[3];
const poster = $element.find('a').children('img').attr('src');
promises.push(helper().then(async () => ({
id: id || null,
title: title || null,
type: 'Anime',
image: await imageUrlToBase64(poster) || null
})))
});
}
return Promise.all(promises);
}; };
const transformUrlServer = async (urlReal) => { const transformUrlServer = async (urlReal) => {
let res for (const data of urlReal) {
const promises = [] if (data.server === 'amus' || data.server === 'natsuki') {
let res = await homgot(data.code.replace("embed", "check"), { parse: true });
for (const index in urlReal) { data.code = res.file || null
if (urlReal[index].server === 'amus' || urlReal[index].server === 'natsuki') { data.direct = true
} else if (data.server === 'gocdn' ) {
let options = { parse: true } if (data.code.split('/player_gocdn.html#')[1] === undefined) {
res = await homgot(urlReal[index].code.replace("embed", "check"), options); data.code = `https://s1.streamium.xyz/gocdn.php?v=${data.code.split('/gocdn.html#')[1]}`
} else {
urlReal[index].code = res.file || null data.code = `https://s1.streamium.xyz/gocdn.php?v=${data.code.split('/player_gocdn.html#')[1]}`
urlReal[index].direct = true }
} else if (urlReal[index].server === 'gocdn' ) { data.direct = true
urlReal[index].code = `https://s1.streamium.xyz/gocdn.php?v=${urlReal[index].code.split('/player_gocdn.html#')[1]}`
urlReal[index].direct = true
} }
} }
urlReal.map(doc => { return urlReal.map(doc =>({
promises.push({ id: doc.title.toLowerCase(),
id: doc.title.toLowerCase(), url: doc.code,
url: doc.code, direct: doc.direct || false
direct: doc.direct || false }));
});
});
return promises;
} }
const obtainPreviewNews = (encoded) => { const obtainPreviewNews = (encoded) => {
@ -539,7 +340,11 @@ const obtainPreviewNews = (encoded) => {
let image; let image;
if (encoded.includes('src="https://img1.ak.crunchyroll.com/')) { if (encoded.includes('src="https://img1.ak.crunchyroll.com/')) {
image = `https://img1.ak.crunchyroll.com/${encoded.split('https://img1.ak.crunchyroll.com/')[1].split('.jpg')[0]}.jpg` if (encoded.split('https://img1.ak.crunchyroll.com/')[1].includes('.jpg')) {
image = `https://img1.ak.crunchyroll.com/${encoded.split('https://img1.ak.crunchyroll.com/')[1].split('.jpg')[0]}.jpg`
} else {
image = `https://img1.ak.crunchyroll.com/${encoded.split('https://img1.ak.crunchyroll.com/')[1].split('.png')[0]}.png`
}
} else if (encoded.includes('<img title=')) { } else if (encoded.includes('<img title=')) {
image = encoded.substring(encoded.indexOf("<img title=\""), encoded.indexOf("\" alt")).split('src=\"')[1] image = encoded.substring(encoded.indexOf("<img title=\""), encoded.indexOf("\" alt")).split('src=\"')[1]
} else if (encoded.includes('<img src=')) { } else if (encoded.includes('<img src=')) {
@ -599,7 +404,6 @@ const structureThemes = async (body, indv) => {
}; };
const getThemesData = async (themes) => { const getThemesData = async (themes) => {
let promises = [] let promises = []
@ -621,61 +425,13 @@ const getThemesData = async (themes) => {
const getThemes = async (themes) => { const getThemes = async (themes) => {
let promises = [] return themes.map(doc =>({
name: doc.themeName,
themes.map(doc => { type: doc.themeType,
video: doc.mirror.mirrorURL
promises.push({ `${BASE_ANIMEFLV}anime/${id}`
name: doc.themeName, }));
type: doc.themeType,
video: doc.mirror.mirrorURL
});
});
return promises;
};
const getAnimes = async () => {
let options = { parse: true }
return await homgot(`${BASE_ANIMEFLV}api/animes/list`, options);
};
const getDirectory = async () => {
let $
let promises = []
let options = { scrapy: true }
$ = await homgot(`${SEARCH_URL}`, options);
const lastPage = $('body div.Wrapper div.Container main div.NvCnAnm ul li a')[11].children[0].data
for (let i = 1; i <= lastPage; i++) {
let options = { scrapy: true }
$ = await homgot(`${SEARCH_DIRECTORY}${i}`, options);
$('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();
let poster = $element.find('a div.Image figure img').attr('src') || $element.find('a div.Image figure img').attr('data-cfsrc');
const type = $element.find('div.Description p span.Type').text();
promises.push(helper().then(async () => ({
id: id || null,
title: title || null,
type: type || null,
image: await imageUrlToBase64(poster) || null
})));
})
}
return Promise.all(promises);
}; };
module.exports = { module.exports = {
@ -691,8 +447,6 @@ module.exports = {
obtainPreviewNews, obtainPreviewNews,
structureThemes, structureThemes,
getThemes, getThemes,
getAnimes,
getDirectory,
helper, helper,
videoServersJK videoServersJK
} }

Loading…
Cancel
Save