Añadiendo modulo getAnime() y geEpisode() mas sus interfaces

pull/1/head
carlos-burelo 4 years ago
parent d397043231
commit 4ef044656c

@ -1,7 +1,7 @@
import cheerio from 'cheerio'; import cheerio from 'cheerio';
import axios from 'axios'; import axios from 'axios';
import { urls } from '../config'; 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) { 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) { async function getEmision(req: any, res: any) {
try { try {
let { page } = req.query; let { page } = req.query;
@ -100,7 +99,6 @@ async function getEmision(req: any, res: any) {
}) })
} }
} }
async function getAnime(req:any, res:any) { async function getAnime(req:any, res:any) {
try { try {
let {id} = req.params; let {id} = req.params;
@ -202,7 +200,6 @@ async function getAnime(req:any, res:any) {
}); });
}; };
}; };
async function searchAnime(req:any, res:any) { async function searchAnime(req:any, res:any) {
try { try {
let { id } = req.params; let { id } = req.params;
@ -239,6 +236,92 @@ async function searchAnime(req:any, res:any) {
success: false 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 { export {
@ -246,4 +329,5 @@ export {
getEmision, getEmision,
getAnime, getAnime,
searchAnime, searchAnime,
getEpisode,
} }

@ -4,7 +4,7 @@ export interface EmisionResponse{
} }
export interface EmisionI{ export interface EmisionI{
id:string; id?:string;
title:string; title:string;
cover:string; cover:string;
category:string; category:string;
@ -14,7 +14,7 @@ export interface EmisionI{
export interface LastestAnimeI { export interface LastestAnimeI {
title: string title: string
cover: string cover: string
id: string id?: string
episode: string episode: string
type: string type: string
} }
@ -29,11 +29,11 @@ export interface AnimeI{
date?: string; date?: string;
genders?: Array<GenderI>; genders?: Array<GenderI>;
sugestions?: Array<SuggestionI>; sugestions?: Array<SuggestionI>;
episodes?: Array<EpisodeI>; episodes?: Array<EpI>;
} }
export interface GenderI{ export interface GenderI{
id:string; id?:string;
title:string; title:string;
} }
@ -43,15 +43,35 @@ export interface SuggestionI{
cover?:string; cover?:string;
year?:number; year?:number;
} }
export interface EpisodeI{ export interface EpI{
id?:string; id?:string;
number?:string; number?:string;
} }
export interface AnimeSearchI { export interface AnimeSearchI {
id: string; id?: string;
title: string; title: string;
cover: string cover: string
category: string; category: string;
year: number; year: number;
} }
export interface EpisodeI {
id?: string;
title: string;
number: string
videos: Array<VideosI>;
downloads: Array<DownloadsI>;
}
export interface VideosI {
url: string;
title: string;
}
export interface DownloadsI {
url: string;
server: string;
}

@ -1,15 +1,12 @@
import { Router } from 'express'; import { Router } from 'express';
const routes = Router(); const routes = Router();
import { getEmision, getLastest, getAnime, searchAnime, getEpisode } from '../controllers/controller'
import { getEmision, getLastest, getAnime, searchAnime } from '../controllers/controller'
routes.get('/lastest', (req, res) => { routes.get('/lastest', (req, res) => {
getLastest(req, res); getLastest(req, res);
}) })
routes.get('/emision', (req, res) => { routes.get('/emision', (req, res) => {
getEmision(req, res); getEmision(req, res);
}); });
@ -17,7 +14,11 @@ routes.get('/emision', (req, res) => {
routes.get('/anime/:id', (req, res) => { routes.get('/anime/:id', (req, res) => {
getAnime(req, res); getAnime(req, res);
}); });
routes.get('/ver/:id', (req, res) => {
getEpisode(req, res);
});
routes.get('/search/:id', (req, res) => { routes.get('/search/:id', (req, res) => {
searchAnime(req, res); searchAnime(req, res);
}) });
export default routes export default routes
Loading…
Cancel
Save