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 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,
}

@ -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<GenderI>;
sugestions?: Array<SuggestionI>;
episodes?: Array<EpisodeI>;
episodes?: Array<EpI>;
}
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;
}
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';
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);
});
@ -17,7 +14,11 @@ routes.get('/emision', (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
Loading…
Cancel
Save