From cda086a5835c34ec71d65925eedae98042e265a1 Mon Sep 17 00:00:00 2001 From: capitanwesler Date: Sun, 11 Apr 2021 17:57:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=80=20Adding=20monoschinos=20lastest?= =?UTF-8?q?=20episodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AnimeController.ts | 84 ++++++++++++++++++++++++------ src/utils/requestCall.ts | 2 +- src/utils/util.ts | 6 ++- 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/src/controllers/AnimeController.ts b/src/controllers/AnimeController.ts index 20657b5..243ac15 100644 --- a/src/controllers/AnimeController.ts +++ b/src/controllers/AnimeController.ts @@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from 'express'; import { requestGot } from '../utils/requestCall'; import { animeFlvInfo, + imageUrlToBase64, jkanimeInfo, monoschinosInfo, videoServersJK, @@ -241,8 +242,10 @@ export default class AnimeController { } async getLastEpisodes(req: Request, res: Response, next: NextFunction) { - let data: any; + // let data: any; + let $: cheerio.Root; let episodes: Episode[] = []; + let animeList: any[] = []; try { const resultQueryRedis: any = await redisClient.get( @@ -254,28 +257,75 @@ export default class AnimeController { return res.status(200).json(resultRedis); } else { - data = await requestGot( - `${urls.BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, - { - parse: true, - scrapy: false, - }, - ); + // @ANIMEFLV + // data = await requestGot( + // `${urls.BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, + // { + // parse: true, + // scrapy: false, + // }, + // ); + + $ = await requestGot(`${urls.BASE_MONOSCHINOS}`, { + scrapy: true, + parse: false, + }); } } catch (err) { return next(err); } + // @ANIMEFLV + // for (const episode of data.episodes) { + // const formattedEpisode: Episode = { + // id: '12345/' + episode.id, + // title: episode.title, + // image: episode.poster, + // episode: episode.episode, + // servers: await transformUrlServer(episode.servers), + // }; + + // episodes.push(formattedEpisode); + // } + + let getLastest: any = $('.container .caps .container')[0]; + + $(getLastest) + .find('.row article') + .each((index: number, element: cheerio.Element) => { + let el: cheerio.Cheerio = $(element); + let title: string | undefined = el + .find('.Title') + .html() + ?.split('\t')[0]; + let img: any = el.find('.Image img').attr('src'); + let type: any = el.find('.Image figure span').text(); + type = type.substring(1, type.length); + let nEpisode: any = el.find('.dataEpi .episode').text(); + nEpisode = parseInt(nEpisode.split('\n')[1]); + let id: any = el.find('a').attr('href'); + id = id.split('/')[4]; + id = id.split('-'); + id.splice(id.length - 2, 2); + id = `${id.join('-')}-episodio-${nEpisode}`; + + let anime = { + id: `ver/${id}`, + title, + image: img, + episode: nEpisode, + }; - for (const episode of data.episodes) { - const formattedEpisode: Episode = { - id: '12345/' + episode.id, - title: episode.title, - image: episode.poster, - episode: episode.episode, - servers: await transformUrlServer(episode.servers), - }; + animeList.push(anime); + }); - episodes.push(formattedEpisode); + for (const anime of animeList) { + episodes.push({ + id: anime.id, + title: anime.title, + image: await imageUrlToBase64(anime.image), + episode: anime.episode, + servers: await videoServersMonosChinos(anime.id), + }); } if (episodes.length > 0) { diff --git a/src/utils/requestCall.ts b/src/utils/requestCall.ts index 9f99336..1f005c4 100644 --- a/src/utils/requestCall.ts +++ b/src/utils/requestCall.ts @@ -11,7 +11,7 @@ interface Options { export const requestGot = async ( url: string, - options: Options, + options?: Options, ): Promise => { if (options !== undefined) { if (options.scrapy) { diff --git a/src/utils/util.ts b/src/utils/util.ts index b04f991..0c4e74a 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -597,7 +597,6 @@ export const monoschinosInfo = async (id: string | undefined) => { export const videoServersMonosChinos = async (id: string) => { let $: cheerio.Root; let videoServers: any[] = []; - let nameServers: any[] = []; try { const resultQueryRedis: any = await redisClient.get( @@ -872,6 +871,11 @@ export function getThemes(themes: any[]) { })); } +export const imageUrlToBase64 = async (url: string) => { + let img: any = await requestGot(url); + return img.rawBody.toString('base64'); +}; + export function hashStringMd5(string: string) { return crypto.createHash('md5').update(string).digest('hex'); }