From 04b30632f8bb838039fe9206688f2a128e5a0147 Mon Sep 17 00:00:00 2001 From: capitanwesler Date: Fri, 16 Apr 2021 10:23:53 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=93=20Adding=20the=20changes=20to=20th?= =?UTF-8?q?e=20other=20fonts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AnimeController.ts | 4 +- src/utils/urls.ts | 2 +- src/utils/util.ts | 139 ++++++++++++++++++++++++----- 3 files changed, 122 insertions(+), 23 deletions(-) diff --git a/src/controllers/AnimeController.ts b/src/controllers/AnimeController.ts index 6e80de8..2b8d5b9 100644 --- a/src/controllers/AnimeController.ts +++ b/src/controllers/AnimeController.ts @@ -688,10 +688,10 @@ export default class AnimeController { switch (searchAnime?.source) { case 'animeflv': - episodes = await animeFlvInfo(searchAnime?.id); + episodes = await animeFlvInfo(searchAnime?.id, searchAnime?.mal_id); break; case 'jkanime': - episodes = await jkanimeInfo(searchAnime?.id); + episodes = await jkanimeInfo(searchAnime?.id, searchAnime?.mal_id); break; case 'monoschinos': episodes = await monoschinosInfo(searchAnime?.id, searchAnime?.mal_id); diff --git a/src/utils/urls.ts b/src/utils/urls.ts index 99c6bcc..94f7a7c 100644 --- a/src/utils/urls.ts +++ b/src/utils/urls.ts @@ -1,6 +1,6 @@ export default { BASE_ARUPPI: 'https://aruppi.jeluchu.xyz/', - BASE_ANIMEFLV: 'https://animeflv.net/', + BASE_ANIMEFLV: 'https://www3.animeflv.net/', BASE_MONOSCHINOS: 'https://monoschinos2.com/', BASE_JKANIME: 'https://jkanime.net/', BASE_ANIMEFLV_JELU: 'https://aruppi.jeluchu.xyz/apis/animeflv/v1/', diff --git a/src/utils/util.ts b/src/utils/util.ts index 8115108..dd7245b 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -406,14 +406,17 @@ export const getRelatedAnimesMAL = async (mal_id: number) => { } }; -export const animeFlvInfo = async (id: string | undefined) => { +export const animeFlvInfo = async (id: string | undefined, mal_id: number) => { let $: cheerio.Root; let anime_info: string[] = []; let anime_eps: string[] = []; - let nextEpisodeDate: string | null; - let episodes: any[] = []; + let episodesList: any[] = []; + let extraInfo: any; try { + /* Extra info of the anime */ + extraInfo = await animeExtraInfo(mal_id); + if (redisClient.connected) { const resultQueryRedis: any = await redisClient.get( `animeflvInfo_${hashStringMd5(id!)}`, @@ -430,10 +433,64 @@ export const animeFlvInfo = async (id: string | undefined) => { scrapy: true, parse: false, }); + + console.log($.html()); } catch (err) { return err; } + let broadCastDate = new Date(); + let dd: number, mm: string | number, yyyy: number; + + const airDay: any = { + Lunes: 1, + Martes: 2, + Miércoles: 3, + Jueves: 4, + Viernes: 5, + Sábados: 6, + Domingos: 7, + 'Sin emisión': 'default', + }; + + if (!extraInfo.aired.to) { + if (airDay.hasOwnProperty(extraInfo.broadcast)) { + if (broadCastDate.getDay() < airDay[extraInfo.broadcast]) { + for ( + let i = broadCastDate.getDay(); + i < airDay[extraInfo.broadcast]; + i++ + ) { + broadCastDate.setDate(broadCastDate.getDate() + 1); + } + } else { + let counter = broadCastDate.getDay() + 1; + + /* Adding one because of the day */ + broadCastDate.setDate(broadCastDate.getDate() + 1); + + while (counter !== airDay[extraInfo.broadcast]) { + if (counter === 7) { + counter = 0; + } + broadCastDate.setDate(broadCastDate.getDate() + 1); + counter++; + } + } + + dd = broadCastDate.getDate(); + mm = + broadCastDate.getMonth() + 1 < 10 + ? `0${broadCastDate.getMonth() + 1}` + : broadCastDate.getMonth() + 1; + yyyy = broadCastDate.getFullYear(); + + episodesList.push({ + nextEpisodeDate: `${yyyy}-${mm}-${dd}`, + }); + } + } + const scripts: cheerio.Element[] = $('script').toArray(); for (const script of scripts) { @@ -448,28 +505,20 @@ export const animeFlvInfo = async (id: string | undefined) => { } } - if (anime_info.length === 4) { - nextEpisodeDate = anime_info[3]; - } else { - nextEpisodeDate = null; - } - - episodes.push({ nextEpisodeDate }); - for (const episode of anime_eps) { - episodes.push({ + episodesList.push({ episode: episode[0], id: `${episode[1]}/${id}-${episode[0]}`, }); } - if (episodes.length > 0) { + if (episodesList.length > 0) { if (redisClient.connected) { /* Set the key in the redis cache. */ redisClient.set( `animeflvInfo_${hashStringMd5(id!)}`, - JSON.stringify(episodes), + JSON.stringify(episodesList), ); /* After 24hrs expire the key. */ @@ -480,20 +529,22 @@ export const animeFlvInfo = async (id: string | undefined) => { ); } - return episodes; + return episodesList; } else { return null; } }; -export const jkanimeInfo = async (id: string | undefined) => { +export const jkanimeInfo = async (id: string | undefined, mal_id: number) => { let $: cheerio.Root; - let nextEpisodeDate: string | null; - let imageLink: string | undefined; + let extraInfo: any; let episodesList: any[] = []; let countEpisodes: string[] = []; try { + /* Extra info of the anime */ + extraInfo = await animeExtraInfo(mal_id); + if (redisClient.connected) { const resultQueryRedis: any = await redisClient.get( `jkanimeInfo_${hashStringMd5(id!)}`, @@ -524,9 +575,57 @@ export const jkanimeInfo = async (id: string | undefined) => { '-', )[1]; - nextEpisodeDate = $('div.proxep p').text() || null; + let broadCastDate = new Date(); + let dd: number, mm: string | number, yyyy: number; + + const airDay: any = { + Lunes: 1, + Martes: 2, + Miércoles: 3, + Jueves: 4, + Viernes: 5, + Sábados: 6, + Domingos: 7, + 'Sin emisión': 'default', + }; - episodesList.push({ nextEpisodeDate }); + if (!extraInfo.aired.to) { + if (airDay.hasOwnProperty(extraInfo.broadcast)) { + if (broadCastDate.getDay() < airDay[extraInfo.broadcast]) { + for ( + let i = broadCastDate.getDay(); + i < airDay[extraInfo.broadcast]; + i++ + ) { + broadCastDate.setDate(broadCastDate.getDate() + 1); + } + } else { + let counter = broadCastDate.getDay() + 1; + + /* Adding one because of the day */ + broadCastDate.setDate(broadCastDate.getDate() + 1); + + while (counter !== airDay[extraInfo.broadcast]) { + if (counter === 7) { + counter = 0; + } + broadCastDate.setDate(broadCastDate.getDate() + 1); + counter++; + } + } + + dd = broadCastDate.getDate(); + mm = + broadCastDate.getMonth() + 1 < 10 + ? `0${broadCastDate.getMonth() + 1}` + : broadCastDate.getMonth() + 1; + yyyy = broadCastDate.getFullYear(); + + episodesList.push({ + nextEpisodeDate: `${yyyy}-${mm}-${dd}`, + }); + } + } for (let i = 1; i <= parseInt(episodesCount); i++) { episodesList.push({