Adding the new propertie mal_id to the directory and the deleting the mal_title, and adapting the app to the new property

pull/18/head
capitanwesler 5 years ago
parent 355f38b1dc
commit e7136dba71

@ -1,4 +1,5 @@
const rss = require('rss-to-json'); const rss = require('rss-to-json');
const fuzzball = require('fuzzball');
const { const {
homgot homgot
@ -27,7 +28,6 @@ const {
} = require('./urls'); } = require('./urls');
const schedule = async (day) =>{ const schedule = async (day) =>{
const data = await homgot(`${BASE_JIKAN}schedule/${day.current}`, { parse: true }); const data = await homgot(`${BASE_JIKAN}schedule/${day.current}`, { parse: true });
return data[day.current].map(doc =>({ return data[day.current].map(doc =>({
@ -35,12 +35,10 @@ const schedule = async (day) =>{
malid: doc.mal_id, malid: doc.mal_id,
image: doc.image_url image: doc.image_url
})); }));
}; };
const top = async (top) =>{ const top = async (top) =>{
let data;
let data
if (top.subtype !== undefined) { if (top.subtype !== undefined) {
data = await homgot(`${BASE_JIKAN}top/${top.type}/${top.page}/${top.subtype}`, { parse: true }); data = await homgot(`${BASE_JIKAN}top/${top.type}/${top.page}/${top.subtype}`, { parse: true });
@ -58,11 +56,9 @@ const top = async (top) =>{
page: top.page, page: top.page,
score: doc.score score: doc.score
})); }));
}; };
const getAllAnimes = async () =>{ const getAllAnimes = async () =>{
let data = await homgot(`${BASE_ANIMEFLV}api/animes/list`, { parse: true }) let data = await homgot(`${BASE_ANIMEFLV}api/animes/list`, { parse: true })
return data.map(item => ({ return data.map(item => ({
@ -72,11 +68,9 @@ const getAllAnimes = async () =>{
id: item[2], id: item[2],
type: item[4] type: item[4]
})); }));
}; };
const getAllDirectory = async (genres) => { const getAllDirectory = async (genres) => {
let data; let data;
if (genres === 'sfw') { if (genres === 'sfw') {
@ -87,7 +81,6 @@ const getAllDirectory = async (genres) => {
data = JSON.parse(JSON.stringify(require('../assets/directory.json'))); data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
} }
return data.map(doc => ({ return data.map(doc => ({
id: doc.id, id: doc.id,
title: doc.title, title: doc.title,
@ -100,12 +93,11 @@ const getAllDirectory = async (genres) => {
jkanime: false, jkanime: false,
description: doc.description description: doc.description
})); }));
}; };
const getAnitakume = async () => { const getAnitakume = async () => {
const promises = [] const promises = [];
await rss.load(BASE_IVOOX).then(rss => { await rss.load(BASE_IVOOX).then(rss => {
@ -141,8 +133,7 @@ const getAnitakume = async () => {
}; };
const getNews = async (pageRss) =>{ const getNews = async (pageRss) =>{
let promises = [];
let promises = []
for(let i = 0; i <= pageRss.length -1; i++) { for(let i = 0; i <= pageRss.length -1; i++) {
@ -166,11 +157,9 @@ const getNews = async (pageRss) =>{
} }
return promises; return promises;
}; };
const season = async (season) =>{ const season = async (season) =>{
const data = await homgot(`${BASE_JIKAN}season/${season.year}/${season.type}`, { parse: true }); const data = await homgot(`${BASE_JIKAN}season/${season.year}/${season.type}`, { parse: true });
return data.anime.map(doc =>({ return data.anime.map(doc =>({
@ -178,22 +167,18 @@ const season = async (season) =>{
image: doc.image_url, image: doc.image_url,
genres: doc.genres.map(x => x.name) genres: doc.genres.map(x => x.name)
})); }));
}; };
const allSeasons = async () =>{ const allSeasons = async () =>{
const data = await homgot(`${BASE_JIKAN}season/archive`, { parse: true }); const data = await homgot(`${BASE_JIKAN}season/archive`, { parse: true });
return data.archive.map(doc =>({ return data.archive.map(doc =>({
year: doc.year, year: doc.year,
seasons: doc.seasons, seasons: doc.seasons,
})); }));
}; };
const laterSeasons = async () =>{ const laterSeasons = async () =>{
const data = await homgot(`${BASE_JIKAN}season/later`, { parse: true }); const data = await homgot(`${BASE_JIKAN}season/later`, { parse: true });
return data.anime.map(doc =>({ return data.anime.map(doc =>({
@ -201,12 +186,11 @@ const laterSeasons = async () =>{
image: doc.image_url, image: doc.image_url,
malink: doc.url malink: doc.url
})); }));
}; };
const getLastEpisodes = async () =>{ const getLastEpisodes = async () =>{
const data = await homgot(`${BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, { parse: true }); const data = await homgot(`${BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, { parse: true });
return await Promise.all(data.episodes.map(async (item) => ({ return await Promise.all(data.episodes.map(async (item) => ({
id: item.id, id: item.id,
title: item.title, title: item.title,
@ -214,11 +198,9 @@ const getLastEpisodes = async () =>{
episode: item.episode, episode: item.episode,
servers: await transformUrlServer(JSON.parse(JSON.stringify(item.servers))) servers: await transformUrlServer(JSON.parse(JSON.stringify(item.servers)))
}))); })));
}; };
const getSpecials = async (data) =>{ const getSpecials = async (data) =>{
const res = await homgot(`${BASE_ANIMEFLV_JELU}${data.url}/${data.type}/${data.page}`, { parse: true }); const res = await homgot(`${BASE_ANIMEFLV_JELU}${data.url}/${data.type}/${data.page}`, { parse: true });
return res[data.prop].map(doc =>({ return res[data.prop].map(doc =>({
@ -238,11 +220,9 @@ const getSpecials = async (data) =>{
}; };
const getMoreInfo = async (title) =>{ const getMoreInfo = async (title) =>{
try { try {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json'))); let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
let result = data.filter(anime => anime.title === title || anime.mal_title === title)[0]; let result = data.filter(anime => fuzzball.ratio(anime.title, title) > 90)[0];
return { return {
title: result.title || null, title: result.title || null,
@ -252,16 +232,14 @@ const getMoreInfo = async (title) =>{
type: result.type || null, type: result.type || null,
rating: result.score || null, rating: result.score || null,
genres: result.genres || null, genres: result.genres || null,
moreInfo: await animeExtraInfo(result.mal_title).then(info => info || null), moreInfo: await animeExtraInfo(result.mal_id).then(info => info || null),
promo: await getAnimeVideoPromo(result.mal_title).then(promo => promo || null), promo: await getAnimeVideoPromo(result.mal_id).then(promo => promo || null),
characters: await getAnimeCharacters(result.mal_title).then(characters => characters || null), characters: await getAnimeCharacters(result.mal_id).then(characters => characters || null),
related: await getRelatedAnimes(result.id) related: await getRelatedAnimes(result.id)
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
}; };
const getEpisodes = async (title) =>{ const getEpisodes = async (title) =>{
@ -282,25 +260,18 @@ const getEpisodes = async (title) =>{
}; };
const getAnimeServers = async (id) => { const getAnimeServers = async (id) => {
if (isNaN(id.split('/')[0])) { if (isNaN(id.split('/')[0])) {
return await videoServersJK(id); return await videoServersJK(id);
} else { } else {
const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true }); const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true });
return await transformUrlServer(data.servers); return await transformUrlServer(data.servers);
} }
}; };
const search = async (title) =>{ return await searchAnime(title); }; const search = async (title) =>{ return await searchAnime(title); };
const getImages = async (query) => { const getImages = async (query) => {
try { try {
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`, { parse: true });
return data.data.result.items.map(doc =>({ return data.data.result.items.map(doc =>({
@ -311,11 +282,9 @@ const getImages = async (query) => {
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
}; };
const getYoutubeVideos = async (channelId) => { const getYoutubeVideos = async (channelId) => {
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}`, { parse: true });
return data[channelId.prop].map(doc =>({ return data[channelId.prop].map(doc =>({
@ -325,7 +294,6 @@ const getYoutubeVideos = async (channelId) => {
thumbMedium: doc.snippet.thumbnails.medium.url, thumbMedium: doc.snippet.thumbnails.medium.url,
thumbHigh: doc.snippet.thumbnails.high.url thumbHigh: doc.snippet.thumbnails.high.url
})); }));
}; };
const getSectionYoutubeVideos = async (type) => { const getSectionYoutubeVideos = async (type) => {
@ -377,11 +345,9 @@ const getThemesYear = async (year) => {
data = await parserThemes.year(year); data = await parserThemes.year(year);
return await structureThemes(data, false); return await structureThemes(data, false);
} }
}; };
const getRandomTheme = async () => { const getRandomTheme = async () => {
let data = await homgot(`${BASE_THEMEMOE}roulette`, { parse: true }); let data = await homgot(`${BASE_THEMEMOE}roulette`, { parse: true });
let themes = await getThemes(data.themes) let themes = await getThemes(data.themes)
@ -390,23 +356,19 @@ const getRandomTheme = async () => {
title: doc.name, title: doc.name,
link: doc.video link: doc.video
})); }));
}; };
const getArtist = async (id) => { const getArtist = async (id) => {
if (id === undefined) { if (id === undefined) {
return await parserThemes.artists(); return await parserThemes.artists();
} else { } else {
return await structureThemes(await parserThemes.artist(id), false) return await structureThemes(await parserThemes.artist(id), false)
} }
}; };
const getAnimeGenres = async(genres) => { const getAnimeGenres = async(genres) => {
let res;
let res let promises = [];
let promises = []
if (genres.genre === undefined && genres.page === undefined && genres.order === undefined) { if (genres.genre === undefined && genres.page === undefined && genres.order === undefined) {
return require('../assets/genres.json'); return require('../assets/genres.json');
@ -436,15 +398,12 @@ const getAnimeGenres = async(genres) => {
} }
return promises; return promises;
} }
}; };
const getAllThemes = async () => require('../assets/themes.json'); const getAllThemes = async () => require('../assets/themes.json');
const getDestAnimePlatforms = async () => { const getDestAnimePlatforms = async () => {
let data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/top.json`, { parse: true }); let data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/top.json`, { parse: true });
return data.map(doc =>({ return data.map(doc =>({
@ -452,12 +411,10 @@ const getDestAnimePlatforms = async () => {
name: doc.name, name: doc.name,
logo: doc.logo logo: doc.logo
})); }));
}; };
const getPlatforms = async (id) => { const getPlatforms = async (id) => {
let data;
let data
if (id === undefined) { if (id === undefined) {
@ -503,11 +460,9 @@ const getPlatforms = async (id) => {
})); }));
} }
}; };
const getProfilePlatform = 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 channelId = { id: data[0].youtubeId, part: 'snippet,id', order: 'date', maxResults: '50', prop: 'items' };
let videos = await getYoutubeVideos(channelId) let videos = await getYoutubeVideos(channelId)
@ -529,7 +484,6 @@ const getProfilePlatform = async (id) => {
faq: doc.faq, faq: doc.faq,
videos: videos videos: videos
})); }));
}; };
async function getRandomAnime() { async function getRandomAnime() {

@ -499,7 +499,6 @@ router.get('/artists/:id?', (req, res) =>{
}); });
router.get('/getByGenres/:genre?/:order?/:page?' , (req , res) =>{ router.get('/getByGenres/:genre?/:order?/:page?' , (req , res) =>{
let genres = { genre: req.params.genre, order: req.params.order, page: req.params.page }; let genres = { genre: req.params.genre, order: req.params.order, page: req.params.page };
api.getAnimeGenres(genres) api.getAnimeGenres(genres)

File diff suppressed because it is too large Load Diff

@ -20,10 +20,10 @@ function btoa(str) {
global.btoa = btoa; global.btoa = btoa;
async function videoServersJK(id) { async function videoServersJK(id) {
const $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true }); const $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true });
let servers = {}; let servers = {};
let script; let script;
const serverNames = $('div#reproductor-box li').map((index, element) => { const serverNames = $('div#reproductor-box li').map((index, element) => {
return $(element).find('a').text(); return $(element).find('a').text();
}).get(); }).get();
@ -71,7 +71,6 @@ async function videoServersJK(id) {
} }
async function desuServerUrl(url) { async function desuServerUrl(url) {
const $ = await homgot(url, { scrapy: true}); const $ = await homgot(url, { scrapy: true});
let script; let script;
@ -94,7 +93,6 @@ async function desuServerUrl(url) {
const jkanimeInfo = async (id) => { const jkanimeInfo = async (id) => {
let $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true }); let $ = await homgot(`${BASE_JKANIME}${id}`, { scrapy: true });
let nextEpisodeDate; let nextEpisodeDate;
@ -141,7 +139,6 @@ const jkanimeInfo = async (id) => {
function getPosterAndType(id) { function getPosterAndType(id) {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json'))); let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
for (let anime of data) { for (let anime of data) {
if (anime.id === id) { if (anime.id === id) {
return [ return [
@ -178,7 +175,6 @@ async function getRelatedAnimes(id) {
} }
return relatedAnimes; return relatedAnimes;
}else { }else {
return []; return [];
} }
@ -252,13 +248,16 @@ const animeflvInfo = async (id) => {
}; };
const getAnimeCharacters = async(title) =>{ const getAnimeCharacters = async(mal_id) =>{
let data;
const matchAnime = await getMALid(title);
try { try {
if(matchAnime !== null) { data = await homgot(`${BASE_JIKAN}anime/${mal_id}/characters_staff`, { parse: true });
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/characters_staff`, { parse: true }); }catch(error) {
console.log(error);
}
if(data !== null) {
return data.characters.map(doc => ({ return data.characters.map(doc => ({
id: doc.mal_id, id: doc.mal_id,
name: doc.name, name: doc.name,
@ -266,43 +265,33 @@ const getAnimeCharacters = async(title) =>{
role: doc.role role: doc.role
})); }));
} }
} catch (err) {
console.log(err);
}
}; };
const getAnimeVideoPromo = async(title) =>{ const getAnimeVideoPromo = async(mal_id) =>{
let data;
const matchAnime = await getMALid(title);
try { try {
if(matchAnime !== null) { data = await homgot(`${BASE_JIKAN}anime/${mal_id}/videos`, {parse: true});
}catch(error) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/videos`, {parse: true}); console.log(error);
}
if(data !== null) {
return data.promo.map(doc => ({ return data.promo.map(doc => ({
title: doc.title, title: doc.title,
previewImage: doc.image_url, previewImage: doc.image_url,
videoURL: doc.video_url videoURL: doc.video_url
})); }));
} }
} catch (err) {
console.log(err);
}
}; };
const animeExtraInfo = async (title) => { const animeExtraInfo = async (mal_id) => {
const data = await homgot(`${BASE_JIKAN}anime/${mal_id}`, {parse: true});
const matchAnime = await getMALid(title);
try { try {
if(matchAnime !== null) { if(data !== null) {
let promises = [];
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}`, {parse: true});
const promises = [];
let broadcast = ''; let broadcast = '';
Array(data).map(doc => { Array(data).map(doc => {
@ -358,32 +347,12 @@ const animeExtraInfo = async (title) => {
}; };
const getMALid = async (title) =>{
if (title === undefined || title === null) {
return 1;
} else {
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) => { const imageUrlToBase64 = async (url) => {
let img = await homgot(url) let img = await homgot(url)
return img.rawBody.toString('base64'); return img.rawBody.toString('base64');
}; };
const searchAnime = async (query) => { const searchAnime = async (query) => {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json'))); 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)); const res = data.filter(x => x.title.toLowerCase().includes(queryLowerCase));
@ -394,7 +363,6 @@ const searchAnime = async (query) => {
type: doc.type || null, type: doc.type || null,
image: doc.poster || null image: doc.poster || null
})); }));
}; };
const transformUrlServer = async (urlReal) => { const transformUrlServer = async (urlReal) => {
@ -531,6 +499,5 @@ module.exports = {
obtainPreviewNews, obtainPreviewNews,
structureThemes, structureThemes,
getThemes, getThemes,
getMALid,
videoServersJK videoServersJK
} }

Loading…
Cancel
Save