Merge pull request #15 from aruppi/feature/improving

Feature/improving and solving some issues with the animeTheme.js
pull/25/head^2
Jesús María 5 years ago committed by GitHub
commit b26a0dbd35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -224,7 +224,8 @@ const getSpecials = async (data) =>{
return res[data.prop].map(doc =>({
id: doc.id,
title: doc.title,
type: doc.type,
type: data.url.toLowerCase(),
page: data.page,
banner: doc.banner,
image: doc.poster,
synopsis: doc.synopsis,
@ -241,7 +242,7 @@ const getMoreInfo = async (title) =>{
try {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
let result = data.filter(anime => anime.title === title)[0];
let result = data.filter(anime => anime.title === title || anime.mal_title === title)[0];
return {
title: result.title || null,
@ -264,9 +265,7 @@ const getMoreInfo = async (title) =>{
};
const getEpisodes = async (title) =>{
try {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
const result = data.filter(x => x.title === title || x.mal_title === title)[0];
@ -370,13 +369,13 @@ const getRadioStations = async () => require('../assets/radiostations.json');
const getOpAndEd = async (title) => await structureThemes(await parserThemes.serie(title), true);
const getThemesYear = async (year) => {
let data = [];
if (year === undefined) {
return await parserThemes.allYears();
} else {
data = await parserThemes.year(year)
return await structureThemes(data, false)
data = await parserThemes.year(year);
return await structureThemes(data, false);
}
};
@ -471,6 +470,25 @@ const getPlatforms = async (id) => {
cover: doc.cover
}));
} if (id === "producers" || id === "apps" || id === "publishers") {
data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, { parse: true });
return data.map(doc =>({
id: doc.id,
name: doc.name,
logo: doc.logo,
cover: doc.cover,
description: doc.description,
type: doc.type,
moreInfo: doc.moreInfo,
facebook: doc.facebook,
twitter: doc.twitter,
instagram: doc.instagram,
webInfo: doc.webInfo,
webpage: doc.webpage
}));
} else {
data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, { parse: true });
@ -481,7 +499,8 @@ const getPlatforms = async (id) => {
type: doc.type,
logo: doc.logo,
cover: doc.cover,
link: doc.link
webpage: doc.webpage,
}));
}
@ -513,6 +532,27 @@ const getProfilePlatform = async (id) => {
};
async function getRandomAnime() {
let directory = JSON.parse(JSON.stringify(require('../assets/directory.json')));
const randomNumber = Math.floor(Math.random() * directory.length);
let result = directory[randomNumber];
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)
};
}
module.exports = {
schedule,
top,
@ -542,5 +582,6 @@ module.exports = {
getPlatforms,
getSectionYoutubeVideos,
getProfilePlatform,
getRelatedAnimes
getRelatedAnimes,
getRandomAnime
};

@ -16,6 +16,7 @@ router.get('/', (req, res) => {
'Schedule': '/api/v3/schedule/:day',
'Top': '/api/v3/top/:type/:subtype/:page',
'AllAnimes': '/api/v3/allAnimes',
'RandomAnime': '/api/v3/randomAnime',
'Anitakume': '/api/v3/anitakume',
'News': '/api/v3/news',
'Season': '/api/v3/season/:year/:type',
@ -25,8 +26,8 @@ router.get('/', (req, res) => {
'Futures Seasons': '/api/v3/laterSeasons',
'LastEpisodes': '/api/v3/lastEpisodes',
'Movies': '/api/v3/movies/:type/:page',
'Ovas': '/api/v3/ovas/:type/:page',
'Specials': '/api/v3/specials/:type/:page',
'Ovas': '/api/v3/ova/:type/:page',
'Specials': '/api/v3/special/:type/:page',
'Tv': '/api/v3/tv/:type/:page',
'MoreInfo': '/api/v3/moreInfo/:title',
'GetEpisodes': '/api/v3/getEpisodes/:title',
@ -42,8 +43,7 @@ router.get('/', (req, res) => {
'Random Theme': '/api/v3/randomTheme',
'Artists Theme': '/api/v3/artists/:id?',
'Famous Platforms': '/api/v3/destAnimePlatforms',
'Legal Platforms': '/api/v3/platforms/:id?',
'Platforms Details': '/api/v3/profilePlatform/:id'
'Legal Platforms': '/api/v3/platforms/:id?'
}
]
});

@ -193,10 +193,10 @@ router.get('/movies/:type/:page' , (req, res) =>{
let data = {url: 'Movies', prop: 'movies', type: req.params.type, page: req.params.page }
api.getSpecials(data)
.then(movies =>{
if (movies.length > 0) {
.then(animes =>{
if (animes.length > 0) {
res.status(200).json({
movies
animes
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
@ -207,15 +207,15 @@ router.get('/movies/:type/:page' , (req, res) =>{
});
router.get('/ovas/:type/:page' , (req, res) =>{
router.get('/ova/:type/:page' , (req, res) =>{
let data = {url: 'Ova', prop: 'ova', type: req.params.type, page: req.params.page }
api.getSpecials(data)
.then(ovas =>{
if (ovas.length > 0) {
.then(animes =>{
if (animes.length > 0) {
res.status(200).json({
ovas
animes
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
@ -226,15 +226,15 @@ router.get('/ovas/:type/:page' , (req, res) =>{
});
router.get('/specials/:type/:page' , (req, res) =>{
router.get('/special/:type/:page' , (req, res) =>{
let data = {url: 'Special', prop: 'special', type: req.params.type, page: req.params.page }
api.getSpecials(data)
.then(specials =>{
if (specials.length > 0) {
.then(animes =>{
if (animes.length > 0) {
res.status(200).json({
specials
animes
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
@ -250,10 +250,10 @@ router.get('/tv/:type/:page' , (req, res) =>{
let data = {url: 'Tv', prop: 'tv', type: req.params.type, page: req.params.page }
api.getSpecials(data)
.then(tv =>{
if (tv.length > 0) {
.then(animes =>{
if (animes.length > 0) {
res.status(200).json({
tv
animes
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
@ -320,7 +320,6 @@ router.get('/getAnimeServers/:id([^/]+/[^/]+)' , (req, res) =>{
});
router.get('/search/:title' , (req, res) =>{
let title = req.params.title;
api.search(title)
@ -339,7 +338,6 @@ router.get('/search/:title' , (req, res) =>{
});
router.get('/images/:query' , (req, res) =>{
let query = { title: req.params.query, count: '51', type: 'images', safesearch: '1', country: 'es_ES', uiv: '4' };
api.getImages(query)
@ -358,7 +356,6 @@ router.get('/images/:query' , (req, res) =>{
});
router.get('/videos/:channelId' , (req, res) =>{
let channelId = { id: req.params.channelId, part: 'snippet,id', order: 'date', maxResults: '50', prop: 'items' };
api.getYoutubeVideos(channelId)
@ -377,7 +374,6 @@ router.get('/videos/:channelId' , (req, res) =>{
});
router.get('/sectionedVideos/:type' , (req, res) =>{
let type = req.params.type;
api.getSectionYoutubeVideos(type)
@ -396,7 +392,6 @@ router.get('/sectionedVideos/:type' , (req, res) =>{
});
router.get('/radio' , (req, res) =>{
api.getRadioStations()
.then(stations =>{
if (stations.length > 0) {
@ -431,10 +426,8 @@ router.get('/allThemes', (req, res) =>{
router.get('/themes/:title' , (req, res) =>{
let title = req.params.title;
api.getOpAndEd(title)
.then(themes => {
if (themes) {
@ -451,19 +444,17 @@ router.get('/themes/:title' , (req, res) =>{
});
router.get('/themesYear/:year?', (req, res) =>{
let year = req.params.year;
let season = req.params.season
api.getThemesYear(year, season)
api.getThemesYear(year)
.then(themes =>{
if (themes.length > 0) {
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);
});
@ -512,19 +503,33 @@ router.get('/getByGenres/:genre?/:order?/:page?' , (req , res) =>{
let genres = { genre: req.params.genre, order: req.params.order, page: req.params.page };
api.getAnimeGenres(genres)
.then(animes =>{
.then(animes => {
if (animes.length > 0) {
res.status(200).json({
animes
});
} 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);
});
});
router.get('/randomAnime', (req, res) => {
api.getRandomAnime()
.then(anime => {
if (anime) {
res.status(200).json(anime);
}else {
res.status(500).json({ message: 'Aruppi lost in the shell'});
}
})
.catch(error => {
console.log(error);
});
});
router.get('/destAnimePlatforms' , (req , res) =>{
api.getDestAnimePlatforms()
@ -548,25 +553,7 @@ router.get('/platforms/:id?' , (req , res) =>{
api.getPlatforms(id)
.then(platforms =>{
if (platforms.length > 0) {
res.status(200).json({
platforms
});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
)
}).catch((err) =>{
console.error(err);
});
});
router.get('/profilePlatform/:id' , (req , res) =>{
let id = req.params.id;
api.getProfilePlatform(id)
.then(info =>{
if (info.length > 0) {
res.status(200).json(info[0]);
res.status(200).json({platforms});
} else (
res.status(500).json({ message: 'Aruppi lost in the shell'})
)

@ -82,11 +82,11 @@ class ThemeParser {
let animes = [];
this.$ = await redditocall(date);
this.$('h3').each((i, el) => {
let parsed = this.parseAnime(el);
this.$('h3').each((index, element) => {
let parsed = this.parseAnime(this.$(element));
parsed.year = date;
animes.push(parsed);
})
});
return animes;
}
@ -106,25 +106,25 @@ class ThemeParser {
});
}
/* -ParseYears
Get the data from the year
get the name and the id to do the respective
scrapping.
*/
parseYears() {
return new Promise(async resolve => {
let years = [];
let promises = [];
let data = this.$('h3 a');
for (let i = 0; i < data.length; i++) {
promises.push({
id: data[i].children[0].parent.attribs.href.split('/')[4],
name: data[i].children[0].data
})
if (i === data.length - 1) {
resolve(promises);
}
this.$('h3 a').each((index, element) => {
years.push(
{
id: this.$(element).attr('href').split('/')[4],
name: this.$(element).text()
}
);
});
resolve(years);
});
}
@ -158,13 +158,12 @@ class ThemeParser {
for (let i = 0; i < data.length; i++) {
let parsed = await this.parseAnime(data[i])
let parsed = await this.parseAnime(data[i]);
promises.push(parsed)
if (i === data.length - 1) {
resolve(promises)
resolve(promises);
}
}
})
@ -226,10 +225,16 @@ class ThemeParser {
})
}
/* - ParseAnime
Parse the h3 tag and get the table
for the next function to parse the table
and get the information about the ending and
openings.
*/
parseAnime(element) {
let el = this.$(element).children('a');
let title = el.text();
let mal_id = el.attr('href').split('/')[4];
let el = this.$(element).find('a');
let title = this.$(el).text();
let mal_id = this.$(el).attr('href').split('/')[4];
let next = this.$(element).next();
let theme = {
@ -237,18 +242,12 @@ class ThemeParser {
title
};
if (next.prop("tagName") === "TABLE") {
theme.themes = this.parseTable(next);
}else if (next.prop("tagName") === "P") {
theme.themes = this.parseTable(next.next());
if (this.$(next).prop("tagName") === "TABLE") {
theme.themes = this.parseTable(this.$(next));
}else if (this.$(next).prop("tagName") === "P") {
theme.themes = this.parseTable(this.$(next).next());
}
return theme;
}
@ -257,25 +256,22 @@ class ThemeParser {
and returns a object with all the
information.
*/
parseTable(element) {
if (element.prop('tagName') !== "TABLE") {
return this.parseTable(element.next());
if (this.$(element).prop('tagName') !== "TABLE") {
return this.parseTable(this.$(element).next());
}
let themes = [];
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 : "";
this.$(element).find('tbody').find('tr').each((i, elem) => {
let name = replaceAll(this.$(elem).find('td').eq(0).text(), '&quot;', '"');
let link = this.$(elem).find('td').eq(1).find('a').attr('href');
let linkDesc = this.$(elem).find('td').eq(1).find('a').text();
let episodes = this.$(elem).find('td').eq(2).text().length > 0 ? this.$(elem).find('td').eq(2).text() : "";
let notes = this.$(elem).find('td').eq(3).text().length > 0 ? this.$(elem).find('td').eq(3).text() : "";
themes.push({
name,
@ -286,8 +282,8 @@ class ThemeParser {
notes
});
});
return themes;
return themes;
}
}

@ -138,13 +138,16 @@ const jkanimeInfo = async (id) => {
};
function getPoster(id) {
function getPosterAndType(id) {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
for (let anime of data) {
if (anime.id === id) {
return anime.poster;
return [
anime.poster,
anime.type
];
}
}
@ -152,7 +155,6 @@ function getPoster(id) {
};
async function getRelatedAnimes(id) {
const $ = await homgot(`${BASE_ANIMEFLV}/anime/${id}`, { scrapy: true });
let listRelated = {};
let relatedAnimes = [];
@ -163,13 +165,14 @@ async function getRelatedAnimes(id) {
});
for (related in listRelated) {
let posterUrl = getPoster(listRelated[related].split('/')[2]);
let posterUrl = getPosterAndType(listRelated[related].split('/')[2]);
relatedAnimes.push(
{
id: listRelated[related].split('/')[2],
title: related,
poster: posterUrl
type: posterUrl[1],
poster: posterUrl[0]
}
);
}
@ -190,7 +193,6 @@ const animeflvGenres = async (id) => {
}
const animeflvInfo = async (id) => {
let $ = await homgot(`${BASE_ANIMEFLV}/anime/${id}`, { scrapy: true });
let scripts = $('script').toArray();
@ -456,6 +458,7 @@ const obtainPreviewNews = (encoded) => {
then returns a array with the themes selected.
*/
const structureThemes = async (body, indv) => {
let themes = [];
if (indv === true) {
@ -468,8 +471,6 @@ const structureThemes = async (body, indv) => {
} else {
for (let i = 0; i <= body.length - 1; i++) {
const themes = [];
themes.push({
title: body[i].title,
year: body[i].year,
@ -509,13 +510,11 @@ const getThemesData = async (themes) => {
};
const getThemes = async (themes) => {
return themes.map(doc => ({
name: doc.themeName,
type: doc.themeType,
video: doc.mirror.mirrorURL
}));
};
module.exports = {

Loading…
Cancel
Save