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) => { 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);
} }
}; };
@ -483,7 +488,7 @@ 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)

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

@ -28,11 +28,12 @@ async function videoServersJK(id) {
const serverNames = []; const serverNames = [];
let servers = []; 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++) { for (let i = 0; i < scripts.length; i++) {
try { try {
const contents = $(scripts[i]).html(); const contents = $(scripts[i]).html();
if ((contents || '').includes('var video = [];')) { if ((contents || '').includes('var video = [];')) {
Array.from({ length: episodes.length }, (v, k) => { Array.from({ length: episodes.length }, (v, k) => {
let index = Number(k + 1); let index = Number(k + 1);
@ -123,7 +124,8 @@ const jkanimeInfo = async (id) => {
}; };
const animeflvGenres = 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) => { $('main.Main section.WdgtCn nav.Nvgnrs a').each((index, element) => {
return $(element).attr('href').split('=')[1] || null; return $(element).attr('href').split('=')[1] || null;
}); });
@ -131,43 +133,49 @@ 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();
const anime_info_ids = []; const anime_info_ids = [];
const anime_eps_data = []; const anime_eps_data = [];
Array.from({ length: scripts.length }, (v, k) => { for (let script of scripts) {
const contents = $(scripts[k]).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);
anime_info_ids.push(dat_anime_info); anime_info_ids.push(dat_anime_info);
} }
if ((contents || '').includes('var episodes = [')) { if ((contents || '').includes('var episodes = [')) {
let episodes = contents.split('var episodes = ')[1].split(';')[0]; 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); anime_eps_data.push(eps_data);
} }
}); }
const animeId = id; const animeId = id;
let nextEpisodeDate let nextEpisodeDate;
if (anime_info_ids.length > 0) { if (anime_info_ids.length > 0) {
if (anime_info_ids[0].length === 4) { if (anime_info_ids[0].length === 4) {
nextEpisodeDate = anime_info_ids[0][3] nextEpisodeDate = anime_info_ids[0][3];
} else { } else {
nextEpisodeDate = null nextEpisodeDate = null;
} }
} }
const amimeTempList = []; const amimeTempList = [];
for (const [key] of Object.entries(anime_eps_data)) { for (const [key] of Object.entries(anime_eps_data)) {
let episode = anime_eps_data[key].map(x => x[0]); let episode = anime_eps_data[key].map(x => x[0]);
let episodeId = anime_eps_data[key].map(x => x[1]); let episodeId = anime_eps_data[key].map(x => x[1]);
amimeTempList.push(episode, episodeId); amimeTempList.push(episode, episodeId);
} }
const animeListEps = [{ nextEpisodeDate: nextEpisodeDate }]; 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 data = amimeTempList.map(x => x[i]);
let episode = data[0]; let episode = data[0];
@ -177,65 +185,68 @@ const animeflvInfo = async (id) => {
animeListEps.push({ animeListEps.push({
episode: episode, episode: episode,
id: link, 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 { try {
if(matchAnime !== null) { if(matchAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/characters_staff`, { parse: true });
return data.characters.map(doc => ({ return dataAnime.characters.map(item=> ({
id: doc.mal_id, id: item.mal_id,
name: doc.name, name: item.name,
image: doc.image_url, image: item.image_url,
role: doc.role role: item.role
})); }));
} }
} catch (err) { } 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 { try {
if(matchAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}/videos`, {parse: true}) if(dataAnime !== null) {
return data.promo.map(doc => ({
return dataAnime.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) { } catch (err) {
console.log(err) console.log(err)
} }
}; };
const animeExtraInfo = async (title) => { const animeExtraInfo = async (mal_id) => {
const matchAnime = await getMALid(title)
//@TESTING
const dataAnime = await homgot(`${BASE_JIKAN}/anime/${mal_id}`, { parse: true });
console.log(dataAnime);
try { try {
if(matchAnime !== null) { if(dataAnime !== null) {
const data = await homgot(`${BASE_JIKAN}anime/${matchAnime.mal_id}`, {parse: true})
const promises = []; const promises = [];
let broadcast = '' let broadcast = '';
Array(data).map(doc => { Array(dataAnime).map(doc => {
let airDay = { let airDay = {
'mondays': 'Lunes', 'mondays': 'Lunes',
@ -256,9 +267,9 @@ const animeExtraInfo = async (title) => {
}; };
if (doc.broadcast === null) { if (doc.broadcast === null) {
broadcast = null broadcast = null;
} else { } else {
broadcast = airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()] broadcast = airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()];
} }
promises.push({ promises.push({
@ -279,7 +290,7 @@ const animeExtraInfo = async (title) => {
endingThemes: doc.ending_themes || null endingThemes: doc.ending_themes || null
}); });
}); });
return Promise.all(promises); return data;
} }
} catch (err) { } 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) => { const imageUrlToBase64 = async (url) => {
let img = await homgot(url) let img = await homgot(url)
@ -384,44 +373,63 @@ const obtainPreviewNews = (encoded) => {
return image; 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 structureThemes = async (body, indv) => {
const promises = []
if (indv === true) { if (indv === true) {
promises.push({
return {
title: body.title, title: body.title,
year: body.year, year: body.year,
themes: await getThemesData(body.themes), themes: await getThemesData(body.themes)
}); };
} else { } else {
for (let i = 0; i <= body.length - 1; i++) { for (let i = 0; i <= body.length - 1; i++) {
promises.push({
const themes = [];
themes.push({
title: body[i].title, title: body[i].title,
year: body[i].year, year: body[i].year,
themes: await getThemesData(body[i].themes), 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) => { const getThemesData = async (themes) => {
let promises = [] let items = [];
for (let i = 0; i <= themes.length - 1; i++) { for (let i = 0; i <= themes.length - 1; i++) {
promises.push({ items.push({
title: themes[i].name.split('"')[1] || 'Remasterización', title: themes[i].name.split('"')[1] || 'Remasterización',
type: themes[i].name.split('"')[0] || 'OP/ED', type: themes[i].type,
episodes: themes[i].episodes || null, episodes: themes[i].episodes !== "" ? themes[i].episodes : null,
notes: themes[i].notes !== "" ? themes[i].notes : null,
video: themes[i].link 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, getAnimeCharacters,
getAnimeVideoPromo, getAnimeVideoPromo,
animeExtraInfo, animeExtraInfo,
getMALid,
imageUrlToBase64, imageUrlToBase64,
searchAnime, searchAnime,
transformUrlServer, transformUrlServer,

Loading…
Cancel
Save