From 4ef044656c77bc6f7bb7fee6a421c8eaa79e5dfc Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 5 Apr 2021 18:47:28 -0500 Subject: [PATCH] =?UTF-8?q?A=C3=B1adiendo=20modulo=20getAnime()=20y=20geEp?= =?UTF-8?q?isode()=20mas=20sus=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/controller.ts | 92 +++++++++++++++++++++++++++++++++-- src/models/interfaces.ts | 34 ++++++++++--- src/routes/api.routes.ts | 15 +++--- 3 files changed, 123 insertions(+), 18 deletions(-) diff --git a/src/controllers/controller.ts b/src/controllers/controller.ts index 59833f3..ab65287 100644 --- a/src/controllers/controller.ts +++ b/src/controllers/controller.ts @@ -1,7 +1,7 @@ import cheerio from 'cheerio'; import axios from 'axios'; import { urls } from '../config'; -import { LastestAnimeI, AnimeI, SuggestionI, GenderI, AnimeSearchI } from "../models/interfaces"; +import { LastestAnimeI, AnimeI, SuggestionI, GenderI, AnimeSearchI, VideosI } from "../models/interfaces"; async function getLastest(req: any, res: any) { @@ -51,7 +51,6 @@ async function getLastest(req: any, res: any) { }) } } - async function getEmision(req: any, res: any) { try { let { page } = req.query; @@ -100,7 +99,6 @@ async function getEmision(req: any, res: any) { }) } } - async function getAnime(req:any, res:any) { try { let {id} = req.params; @@ -202,7 +200,6 @@ async function getAnime(req:any, res:any) { }); }; }; - async function searchAnime(req:any, res:any) { try { let { id } = req.params; @@ -239,6 +236,92 @@ async function searchAnime(req:any, res:any) { success: false }) } +}; +async function getEpisode(req:any, res:any) { + try { + let { id } = req.params; + const response = await axios.get(`${urls.episode}/${id}`); + const $ = cheerio.load(response.data); + let epnum = $('.Episode .Title-epi').text(); + let title = $('.Episode .Title-epi').text().replace('Sub EspaƱol', '') + let animeId = id.split('-'); + if (animeId.includes('episodio')) { + animeId = animeId.splice(0, animeId.length - 2).join('-'); + } else { + animeId = animeId.splice(0, animeId.length - 1) + } + animeId = `${animeId}-sub-espanol`; + let number:any = epnum.split(' '); + number = parseInt(number[number.length - 3]); + + let videos = []; + let videosContainer = $('.Episode .content .row .TPlayer').text(); + $(videosContainer).each((i, e) => { + let el = $(e); + let url = el.attr('src'); + if (url) { + url = url.split('url=')[1] + url = decodeURIComponent(url) + url = url.split('&id')[0] + let videolinks = new URL(url) + let { host } = videolinks; + let name = host + .replace('.com', '') + .replace('www.', '') + .replace('.ru', '') + .replace('repro.', '') + .replace('.co', '') + .replace('.nz', '') + name = `${name.slice(0,1).toUpperCase()}${name.slice(1)}` + let servers = { + url, + name + } + videos.push(servers); + }; + }); + let downloads = []; + let downloadsContainer = $('#downloads table tbody tr'); + + $(downloadsContainer).each((i, e) => { + let el = $(e); + + let link = el.find('a').attr('href') + let sn = link.replace('.com', '') + .replace('www.', '') + .replace('.ru', '') + .replace('repro.', '') + .replace('.co', '') + .replace('.nz', '') + let servername = sn.slice(8) + let svn = servername.indexOf("/") + let server = servername.slice(0, svn) + server = `${server.slice(0,1).toUpperCase()}${server.slice(1)}` + let down = { + server, + link + } + if (down) { + downloads.push(down) + } + + }) + + res.json({ + title, + animeId, + number, + videos, + downloads, + }) + + } catch (err) { + res.status(500) + .json({ + message: err.message, + success: false + }) + } } export { @@ -246,4 +329,5 @@ export { getEmision, getAnime, searchAnime, + getEpisode, } \ No newline at end of file diff --git a/src/models/interfaces.ts b/src/models/interfaces.ts index 9ac27e8..1b9b3e8 100644 --- a/src/models/interfaces.ts +++ b/src/models/interfaces.ts @@ -4,7 +4,7 @@ export interface EmisionResponse{ } export interface EmisionI{ - id:string; + id?:string; title:string; cover:string; category:string; @@ -14,7 +14,7 @@ export interface EmisionI{ export interface LastestAnimeI { title: string cover: string - id: string + id?: string episode: string type: string } @@ -29,11 +29,11 @@ export interface AnimeI{ date?: string; genders?: Array; sugestions?: Array; - episodes?: Array; + episodes?: Array; } export interface GenderI{ - id:string; + id?:string; title:string; } @@ -43,15 +43,35 @@ export interface SuggestionI{ cover?:string; year?:number; } -export interface EpisodeI{ +export interface EpI{ id?:string; number?:string; } export interface AnimeSearchI { - id: string; + id?: string; title: string; cover: string category: string; year: number; -} \ No newline at end of file +} + + +export interface EpisodeI { + id?: string; + title: string; + number: string + videos: Array; + downloads: Array; +} + +export interface VideosI { + url: string; + title: string; +} +export interface DownloadsI { + url: string; + server: string; +} + + diff --git a/src/routes/api.routes.ts b/src/routes/api.routes.ts index 74ece8a..d63f1a7 100644 --- a/src/routes/api.routes.ts +++ b/src/routes/api.routes.ts @@ -1,23 +1,24 @@ import { Router } from 'express'; - - const routes = Router(); - -import { getEmision, getLastest, getAnime, searchAnime } from '../controllers/controller' - +import { getEmision, getLastest, getAnime, searchAnime, getEpisode } from '../controllers/controller' routes.get('/lastest', (req, res) => { getLastest(req, res); }) + routes.get('/emision', (req, res) => { - getEmision(req, res); + getEmision(req, res); }); routes.get('/anime/:id', (req, res) => { getAnime(req, res); }); +routes.get('/ver/:id', (req, res) => { + getEpisode(req, res); +}); routes.get('/search/:id', (req, res) => { searchAnime(req, res); -}) +}); + export default routes \ No newline at end of file