Fixing the animeTheme.js and refactoring in some files

pull/12/head
capitanwesler 5 years ago
parent 3c505cf54e
commit b8374812e7

@ -284,10 +284,15 @@ const getEpisodes = async (title) =>{
const getAnimeServers = async (id) => {
if (isNaN(id.split('/')[0])) {
return await videoServersJK(id)
return await videoServersJK(id);
} else {
const data = await homgot(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`, { parse: true });
return await transformUrlServer(data.servers);
}
};
@ -483,7 +488,7 @@ const getPlatforms = 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 videos = await getYoutubeVideos(channelId)

@ -209,10 +209,11 @@ class ThemeParser {
return new Promise(async resolve => {
let years = this.$('h3 a');
this.$('h3 a')[0].children[0].data
for (let i = 0; i < years.length; i++) {
let yearElement = years[i];
await this.year(this.$(yearElement).attr('href').split('/')[4])
.then(async animes => {
this.animes = this.animes.concat(animes);

@ -28,11 +28,12 @@ async function videoServersJK(id) {
const serverNames = [];
let servers = [];
episodes.each((index, element) => serverNames.push($(element).find('a').text()))
episodes.each((index, element) => serverNames.push($(element).find('a').text()));
for (let i = 0; i < scripts.length; i++) {
try {
const contents = $(scripts[i]).html();
if ((contents || '').includes('var video = [];')) {
Array.from({ length: episodes.length }, (v, k) => {
let index = Number(k + 1);
@ -123,7 +124,8 @@ const jkanimeInfo = async (id) => {
};
const animeflvGenres = async (id) => {
let $ = await homgot(`${BASE_ANIMEFLV}${id}`, { scrapy: true });
let $ = await homgot(`${BASE_ANIMEFLV}/${id}`, { scrapy: true });
$('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => {
return $(element).attr('href').split('=')[1] || null;
});
@ -131,44 +133,50 @@ const animeflvGenres = 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();
const anime_info_ids = [];
const anime_eps_data = [];
Array.from({ length: scripts.length }, (v, k) => {
const contents = $(scripts[k]).html();
for (let script of scripts) {
const contents = $(script).html();
if ((contents || '').includes('var anime_info = [')) {
let anime_info = contents.split('var anime_info = ')[1].split(';\n')[0];
let dat_anime_info = JSON.parse(anime_info);
anime_info_ids.push(dat_anime_info);
}
if ((contents || '').includes('var episodes = [')) {
let episodes = contents.split('var episodes = ')[1].split(';')[0];
let eps_data = JSON.parse(episodes)
let eps_data = JSON.parse(episodes);
anime_eps_data.push(eps_data);
}
});
}
const animeId = id;
let nextEpisodeDate
let nextEpisodeDate;
if (anime_info_ids.length > 0) {
if (anime_info_ids[0].length === 4) {
nextEpisodeDate = anime_info_ids[0][3]
nextEpisodeDate = anime_info_ids[0][3];
} else {
nextEpisodeDate = null
nextEpisodeDate = null;
}
}
const amimeTempList = [];
for (const [key] 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 }];
for (let i = 0; i < amimeTempList[1].length; i++){
for (let i = 0; i < amimeTempList[1].length; i++) {
let data = amimeTempList.map(x => x[i]);
let episode = data[0];
let id = data[1];
@ -177,65 +185,68 @@ const animeflvInfo = async (id) => {
animeListEps.push({
episode: episode,
id: link,
})
});
}
return animeListEps
return animeListEps;
};
const getAnimeCharacters = async(title) =>{
const matchAnime = await getMALid(title)
const getAnimeCharacters = async (mal_id) =>{
const dataAnime = await homgot(`${BASE_JIKAN}/anime/${mal_id}/characters_staff`, { parse: true });
try {
if(matchAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/characters_staff`, { parse: true });
return data.characters.map(doc => ({
id: doc.mal_id,
name: doc.name,
image: doc.image_url,
role: doc.role
return dataAnime.characters.map(item=> ({
id: item.mal_id,
name: item.name,
image: item.image_url,
role: item.role
}));
}
} catch (err) {
console.log(err)
console.log(err);
}
};
const getAnimeVideoPromo = async(title) =>{
const getAnimeVideoPromo = async(mal_id) =>{
const matchAnime = await getMALid(title)
const dataAnime = await homgot(`${BASE_JIKAN}/anime/${mal_id}`);
try {
if(matchAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/videos`, {parse: true})
return data.promo.map(doc => ({
if(dataAnime !== null) {
return dataAnime.promo.map(doc => ({
title: doc.title,
previewImage: doc.image_url,
videoURL: doc.video_url
}));
}
} catch (err) {
console.log(err)
}
};
const animeExtraInfo = async (title) => {
const matchAnime = await getMALid(title)
const animeExtraInfo = async (mal_id) => {
//@TESTING
const dataAnime = await homgot(`${BASE_JIKAN}/anime/${mal_id}`, { parse: true });
console.log(dataAnime);
try {
if(matchAnime !== null) {
if(dataAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}`, {parse: true})
const promises = [];
let broadcast = ''
let broadcast = '';
Array(data).map(doc => {
Array(dataAnime).map(doc => {
let airDay = {
'mondays': 'Lunes',
@ -256,9 +267,9 @@ const animeExtraInfo = async (title) => {
};
if (doc.broadcast === null) {
broadcast = null
broadcast = null;
} else {
broadcast = airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()]
broadcast = airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()];
}
promises.push({
@ -279,7 +290,7 @@ const animeExtraInfo = async (title) => {
endingThemes: doc.ending_themes || null
});
});
return Promise.all(promises);
return data;
}
} catch (err) {
@ -288,28 +299,6 @@ 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) => {
let img = await homgot(url)
@ -384,44 +373,63 @@ const obtainPreviewNews = (encoded) => {
return image;
}
/* - StructureThemes
This function only parses the theme/themes
if indv is true, then only return a object, if it's false
then returns a array with the themes selected.
*/
const structureThemes = async (body, indv) => {
const promises = []
if (indv === true) {
promises.push({
return {
title: body.title,
year: body.year,
themes: await getThemesData(body.themes),
});
themes: await getThemesData(body.themes)
};
} else {
for (let i = 0; i <= body.length - 1; i++) {
promises.push({
const themes = [];
themes.push({
title: body[i].title,
year: body[i].year,
themes: await getThemesData(body[i].themes),
});
}
return themes;
}
return promises;
};
/* - GetThemesData
Get the themes from the object and
format to a new array of items where
these items are formatted better.
*/
const getThemesData = async (themes) => {
let promises = []
let items = [];
for (let i = 0; i <= themes.length - 1; i++) {
promises.push({
items.push({
title: themes[i].name.split('"')[1] || 'Remasterización',
type: themes[i].name.split('"')[0] || 'OP/ED',
episodes: themes[i].episodes || null,
type: themes[i].type,
episodes: themes[i].episodes !== "" ? themes[i].episodes : null,
notes: themes[i].notes !== "" ? themes[i].notes : null,
video: themes[i].link
});
}
return promises.filter(x => x.title !== 'Remasterización');
return items.filter(x => x.title !== 'Remasterización');
};
@ -442,7 +450,6 @@ module.exports = {
getAnimeCharacters,
getAnimeVideoPromo,
animeExtraInfo,
getMALid,
imageUrlToBase64,
searchAnime,
transformUrlServer,

Loading…
Cancel
Save