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 =>({ return res[data.prop].map(doc =>({
id: doc.id, id: doc.id,
title: doc.title, title: doc.title,
type: doc.type, type: data.url.toLowerCase(),
page: data.page,
banner: doc.banner, banner: doc.banner,
image: doc.poster, image: doc.poster,
synopsis: doc.synopsis, synopsis: doc.synopsis,
@ -241,7 +242,7 @@ 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)[0]; let result = data.filter(anime => anime.title === title || anime.mal_title === title)[0];
return { return {
title: result.title || null, title: result.title || null,
@ -264,9 +265,7 @@ const getMoreInfo = async (title) =>{
}; };
const getEpisodes = async (title) =>{ const getEpisodes = async (title) =>{
try { try {
let data = JSON.parse(JSON.stringify(require('../assets/directory.json'))); let data = JSON.parse(JSON.stringify(require('../assets/directory.json')));
const result = data.filter(x => x.title === title || x.mal_title === title)[0]; 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 getOpAndEd = async (title) => await structureThemes(await parserThemes.serie(title), 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 {
data = await parserThemes.year(year) data = await parserThemes.year(year);
return await structureThemes(data, false) return await structureThemes(data, false);
} }
}; };
@ -471,6 +470,25 @@ const getPlatforms = async (id) => {
cover: doc.cover 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 { } else {
data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, { parse: true }); data = await homgot(`${BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, { parse: true });
@ -481,7 +499,8 @@ const getPlatforms = async (id) => {
type: doc.type, type: doc.type,
logo: doc.logo, logo: doc.logo,
cover: doc.cover, 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 = { module.exports = {
schedule, schedule,
top, top,
@ -542,5 +582,6 @@ module.exports = {
getPlatforms, getPlatforms,
getSectionYoutubeVideos, getSectionYoutubeVideos,
getProfilePlatform, getProfilePlatform,
getRelatedAnimes getRelatedAnimes,
getRandomAnime
}; };

@ -16,6 +16,7 @@ router.get('/', (req, res) => {
'Schedule': '/api/v3/schedule/:day', 'Schedule': '/api/v3/schedule/:day',
'Top': '/api/v3/top/:type/:subtype/:page', 'Top': '/api/v3/top/:type/:subtype/:page',
'AllAnimes': '/api/v3/allAnimes', 'AllAnimes': '/api/v3/allAnimes',
'RandomAnime': '/api/v3/randomAnime',
'Anitakume': '/api/v3/anitakume', 'Anitakume': '/api/v3/anitakume',
'News': '/api/v3/news', 'News': '/api/v3/news',
'Season': '/api/v3/season/:year/:type', 'Season': '/api/v3/season/:year/:type',
@ -25,8 +26,8 @@ router.get('/', (req, res) => {
'Futures Seasons': '/api/v3/laterSeasons', 'Futures Seasons': '/api/v3/laterSeasons',
'LastEpisodes': '/api/v3/lastEpisodes', 'LastEpisodes': '/api/v3/lastEpisodes',
'Movies': '/api/v3/movies/:type/:page', 'Movies': '/api/v3/movies/:type/:page',
'Ovas': '/api/v3/ovas/:type/:page', 'Ovas': '/api/v3/ova/:type/:page',
'Specials': '/api/v3/specials/:type/:page', 'Specials': '/api/v3/special/:type/:page',
'Tv': '/api/v3/tv/:type/:page', 'Tv': '/api/v3/tv/:type/:page',
'MoreInfo': '/api/v3/moreInfo/:title', 'MoreInfo': '/api/v3/moreInfo/:title',
'GetEpisodes': '/api/v3/getEpisodes/:title', 'GetEpisodes': '/api/v3/getEpisodes/:title',
@ -42,8 +43,7 @@ router.get('/', (req, res) => {
'Random Theme': '/api/v3/randomTheme', 'Random Theme': '/api/v3/randomTheme',
'Artists Theme': '/api/v3/artists/:id?', 'Artists Theme': '/api/v3/artists/:id?',
'Famous Platforms': '/api/v3/destAnimePlatforms', 'Famous Platforms': '/api/v3/destAnimePlatforms',
'Legal Platforms': '/api/v3/platforms/:id?', 'Legal Platforms': '/api/v3/platforms/:id?'
'Platforms Details': '/api/v3/profilePlatform/: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 } let data = {url: 'Movies', prop: 'movies', type: req.params.type, page: req.params.page }
api.getSpecials(data) api.getSpecials(data)
.then(movies =>{ .then(animes =>{
if (movies.length > 0) { if (animes.length > 0) {
res.status(200).json({ res.status(200).json({
movies animes
}); });
} else ( } else (
res.status(500).json({ message: 'Aruppi lost in the shell'}) 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 } let data = {url: 'Ova', prop: 'ova', type: req.params.type, page: req.params.page }
api.getSpecials(data) api.getSpecials(data)
.then(ovas =>{ .then(animes =>{
if (ovas.length > 0) { if (animes.length > 0) {
res.status(200).json({ res.status(200).json({
ovas animes
}); });
} else ( } else (
res.status(500).json({ message: 'Aruppi lost in the shell'}) 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 } let data = {url: 'Special', prop: 'special', type: req.params.type, page: req.params.page }
api.getSpecials(data) api.getSpecials(data)
.then(specials =>{ .then(animes =>{
if (specials.length > 0) { if (animes.length > 0) {
res.status(200).json({ res.status(200).json({
specials animes
}); });
} else ( } else (
res.status(500).json({ message: 'Aruppi lost in the shell'}) 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 } let data = {url: 'Tv', prop: 'tv', type: req.params.type, page: req.params.page }
api.getSpecials(data) api.getSpecials(data)
.then(tv =>{ .then(animes =>{
if (tv.length > 0) { if (animes.length > 0) {
res.status(200).json({ res.status(200).json({
tv animes
}); });
} else ( } else (
res.status(500).json({ message: 'Aruppi lost in the shell'}) 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) =>{ router.get('/search/:title' , (req, res) =>{
let title = req.params.title; let title = req.params.title;
api.search(title) api.search(title)
@ -339,7 +338,6 @@ router.get('/search/:title' , (req, res) =>{
}); });
router.get('/images/:query' , (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' }; let query = { title: req.params.query, count: '51', type: 'images', safesearch: '1', country: 'es_ES', uiv: '4' };
api.getImages(query) api.getImages(query)
@ -358,7 +356,6 @@ router.get('/images/:query' , (req, res) =>{
}); });
router.get('/videos/:channelId' , (req, res) =>{ router.get('/videos/:channelId' , (req, res) =>{
let channelId = { id: req.params.channelId, part: 'snippet,id', order: 'date', maxResults: '50', prop: 'items' }; let channelId = { id: req.params.channelId, part: 'snippet,id', order: 'date', maxResults: '50', prop: 'items' };
api.getYoutubeVideos(channelId) api.getYoutubeVideos(channelId)
@ -377,7 +374,6 @@ router.get('/videos/:channelId' , (req, res) =>{
}); });
router.get('/sectionedVideos/:type' , (req, res) =>{ router.get('/sectionedVideos/:type' , (req, res) =>{
let type = req.params.type; let type = req.params.type;
api.getSectionYoutubeVideos(type) api.getSectionYoutubeVideos(type)
@ -396,7 +392,6 @@ router.get('/sectionedVideos/:type' , (req, res) =>{
}); });
router.get('/radio' , (req, res) =>{ router.get('/radio' , (req, res) =>{
api.getRadioStations() api.getRadioStations()
.then(stations =>{ .then(stations =>{
if (stations.length > 0) { if (stations.length > 0) {
@ -431,9 +426,7 @@ router.get('/allThemes', (req, res) =>{
router.get('/themes/:title' , (req, res) =>{ router.get('/themes/:title' , (req, res) =>{
let title = req.params.title; let title = req.params.title;
api.getOpAndEd(title) api.getOpAndEd(title)
.then(themes => { .then(themes => {
@ -451,19 +444,17 @@ router.get('/themes/:title' , (req, res) =>{
}); });
router.get('/themesYear/:year?', (req, res) =>{ router.get('/themesYear/:year?', (req, res) =>{
let year = req.params.year; let year = req.params.year;
let season = req.params.season
api.getThemesYear(year, season) api.getThemesYear(year)
.then(themes =>{ .then(themes =>{
if (themes.length > 0) { if (themes.length > 0) {
res.status(200).json({ res.status(200).json({
themes themes
}); });
} else ( } else {
res.status(500).json({ message: 'Aruppi lost in the shell'}) res.status(500).json({ message: 'Aruppi lost in the shell'});
) }
}).catch((err) =>{ }).catch((err) =>{
console.error(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 }; let genres = { genre: req.params.genre, order: req.params.order, page: req.params.page };
api.getAnimeGenres(genres) api.getAnimeGenres(genres)
.then(animes =>{ .then(animes => {
if (animes.length > 0) { if (animes.length > 0) {
res.status(200).json({ res.status(200).json({
animes animes
}); });
} else ( } else {
res.status(500).json({ message: 'Aruppi lost in the shell'}) res.status(500).json({ message: 'Aruppi lost in the shell'});
) }
}).catch((err) =>{ }).catch((err) =>{
console.error(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) =>{ router.get('/destAnimePlatforms' , (req , res) =>{
api.getDestAnimePlatforms() api.getDestAnimePlatforms()
@ -548,25 +553,7 @@ router.get('/platforms/:id?' , (req , res) =>{
api.getPlatforms(id) api.getPlatforms(id)
.then(platforms =>{ .then(platforms =>{
if (platforms.length > 0) { if (platforms.length > 0) {
res.status(200).json({ res.status(200).json({platforms});
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]);
} else ( } else (
res.status(500).json({ message: 'Aruppi lost in the shell'}) res.status(500).json({ message: 'Aruppi lost in the shell'})
) )

@ -82,11 +82,11 @@ class ThemeParser {
let animes = []; let animes = [];
this.$ = await redditocall(date); this.$ = await redditocall(date);
this.$('h3').each((i, el) => { this.$('h3').each((index, element) => {
let parsed = this.parseAnime(el); let parsed = this.parseAnime(this.$(element));
parsed.year = date; parsed.year = date;
animes.push(parsed); animes.push(parsed);
}) });
return animes; 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() { parseYears() {
return new Promise(async resolve => { return new Promise(async resolve => {
let years = [];
let promises = []; this.$('h3 a').each((index, element) => {
let data = this.$('h3 a'); years.push(
{
for (let i = 0; i < data.length; i++) { id: this.$(element).attr('href').split('/')[4],
name: this.$(element).text()
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);
}
}
resolve(years);
}); });
} }
@ -158,13 +158,12 @@ class ThemeParser {
for (let i = 0; i < data.length; i++) { 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) promises.push(parsed)
if (i === data.length - 1) { 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) { parseAnime(element) {
let el = this.$(element).children('a'); let el = this.$(element).find('a');
let title = el.text(); let title = this.$(el).text();
let mal_id = el.attr('href').split('/')[4]; let mal_id = this.$(el).attr('href').split('/')[4];
let next = this.$(element).next(); let next = this.$(element).next();
let theme = { let theme = {
@ -237,18 +242,12 @@ class ThemeParser {
title title
}; };
if (this.$(next).prop("tagName") === "TABLE") {
if (next.prop("tagName") === "TABLE") { theme.themes = this.parseTable(this.$(next));
}else if (this.$(next).prop("tagName") === "P") {
theme.themes = this.parseTable(next); theme.themes = this.parseTable(this.$(next).next());
}else if (next.prop("tagName") === "P") {
theme.themes = this.parseTable(next.next());
} }
return theme; return theme;
} }
@ -257,25 +256,22 @@ class ThemeParser {
and returns a object with all the and returns a object with all the
information. information.
*/ */
parseTable(element) { parseTable(element) {
if (element.prop('tagName') !== "TABLE") { if (this.$(element).prop('tagName') !== "TABLE") {
return this.parseTable(element.next()); return this.parseTable(this.$(element).next());
} }
let themes = []; let themes = [];
element.find('tbody').find('tr').each((i, elem) => { this.$(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 : "";
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({ themes.push({
name, name,
@ -286,8 +282,8 @@ class ThemeParser {
notes notes
}); });
}); });
return themes;
return themes;
} }
} }

@ -33,10 +33,10 @@ async function videoServersJK(id) {
script = $(element).html(); script = $(element).html();
} }
}); });
try { try {
let videoUrls = script.match(/(?<=src=").*?(?=[\*"])/gi); let videoUrls = script.match(/(?<=src=").*?(?=[\*"])/gi);
for (let i = 0; i < serverNames.length; i++) { for (let i = 0; i < serverNames.length; i++) {
servers[serverNames[i]] = videoUrls[i]; servers[serverNames[i]] = videoUrls[i];
} }
@ -45,7 +45,7 @@ async function videoServersJK(id) {
console.log(err); console.log(err);
return null; return null;
} }
let serverList = []; let serverList = [];
for (let server in servers) { for (let server in servers) {
@ -62,7 +62,7 @@ async function videoServersJK(id) {
direct: true direct: true
}); });
} }
} }
serverList = serverList.filter(x => x.id !== 'xtreme s' && x.id !== 'desuka'); serverList = serverList.filter(x => x.id !== 'xtreme s' && x.id !== 'desuka');
@ -138,13 +138,16 @@ const jkanimeInfo = async (id) => {
}; };
function getPoster(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 anime.poster; return [
anime.poster,
anime.type
];
} }
} }
@ -152,24 +155,24 @@ function getPoster(id) {
}; };
async function getRelatedAnimes(id) { async function getRelatedAnimes(id) {
const $ = await homgot(`${BASE_ANIMEFLV}/anime/${id}`, { scrapy: true }); const $ = await homgot(`${BASE_ANIMEFLV}/anime/${id}`, { scrapy: true });
let listRelated = {}; let listRelated = {};
let relatedAnimes = []; let relatedAnimes = [];
if ($('ul.ListAnmRel').length) { if ($('ul.ListAnmRel').length) {
$('ul.ListAnmRel li a').each((index, element) => { $('ul.ListAnmRel li a').each((index, element) => {
listRelated[$(element).text()] = $(element).attr('href'); listRelated[$(element).text()] = $(element).attr('href');
}); });
for (related in listRelated) { for (related in listRelated) {
let posterUrl = getPoster(listRelated[related].split('/')[2]); let posterUrl = getPosterAndType(listRelated[related].split('/')[2]);
relatedAnimes.push( relatedAnimes.push(
{ {
id: listRelated[related].split('/')[2], id: listRelated[related].split('/')[2],
title: related, title: related,
poster: posterUrl type: posterUrl[1],
poster: posterUrl[0]
} }
); );
} }
@ -190,7 +193,6 @@ const animeflvGenres = async (id) => {
} }
const animeflvInfo = 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(); let scripts = $('script').toArray();
@ -199,7 +201,7 @@ const animeflvInfo = async (id) => {
for (let script of scripts) { for (let script of scripts) {
const contents = $(script).html(); 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 anime_info = contents.split('var anime_info = ')[1].split(';\n')[0];
let dat_anime_info = JSON.parse(anime_info); let dat_anime_info = JSON.parse(anime_info);
@ -328,7 +330,7 @@ const animeExtraInfo = async (title) => {
} else { } else {
broadcast = airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()] broadcast = airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()]
} }
promises.push({ promises.push({
titleJapanese: doc.title_japanese, titleJapanese: doc.title_japanese,
source: doc.source, source: doc.source,
@ -450,13 +452,14 @@ const obtainPreviewNews = (encoded) => {
/* - StructureThemes /* - StructureThemes
This function only parses the theme/themes This function only parses the theme/themes
if indv is true, then only return a object, if it's false if indv is true, then only return a object, if it's false
then returns a array with the themes selected. then returns a array with the themes selected.
*/ */
const structureThemes = async (body, indv) => { const structureThemes = async (body, indv) => {
let themes = [];
if (indv === true) { if (indv === true) {
return { return {
@ -468,8 +471,6 @@ const structureThemes = async (body, indv) => {
} else { } else {
for (let i = 0; i <= body.length - 1; i++) { for (let i = 0; i <= body.length - 1; i++) {
const themes = [];
themes.push({ themes.push({
title: body[i].title, title: body[i].title,
year: body[i].year, year: body[i].year,
@ -479,7 +480,7 @@ const structureThemes = async (body, indv) => {
return themes; return themes;
} }
}; };
/* - GetThemesData /* - GetThemesData
@ -503,19 +504,17 @@ const getThemesData = async (themes) => {
}); });
} }
return items.filter(x => x.title !== 'Remasterización'); return items.filter(x => x.title !== 'Remasterización');
}; };
const getThemes = async (themes) => { const getThemes = async (themes) => {
return themes.map(doc => ({ return themes.map(doc => ({
name: doc.themeName, name: doc.themeName,
type: doc.themeType, type: doc.themeType,
video: doc.mirror.mirrorURL video: doc.mirror.mirrorURL
})); }));
}; };
module.exports = { module.exports = {

Loading…
Cancel
Save