@ -1,5 +1,5 @@
import { NextFunction , Request , Response } from 'express' ;
import { requestGot } from '../utils/requestCall' ;
import { NextFunction , Request , Response } from 'express' ;
import { requestGot } from '../utils/requestCall' ;
import {
imageUrlToBase64 ,
jkanimeInfo ,
@ -9,10 +9,10 @@ import {
videoServersMonosChinos ,
videoServersTioAnime ,
} from '../utils/util' ;
import { transformUrlServer } from '../utils/transformerUrl' ;
import AnimeModel , { Anime as ModelA } from '../database/models/anime.model' ;
import { transformUrlServer } from '../utils/transformerUrl' ;
import AnimeModel , { Anime as ModelA } from '../database/models/anime.model' ;
import util from 'util' ;
import { hashStringMd5 } from '../utils/util' ;
import { hashStringMd5 } from '../utils/util' ;
import {
animeExtraInfo ,
getAnimeVideoPromo ,
@ -20,7 +20,7 @@ import {
getRelatedAnimesMAL ,
} from '../utils/util' ;
import urls from '../utils/urls' ;
import { redisClient } from '../database/connection' ;
import { redisClient } from '../database/connection' ;
// @ts-ignore
redisClient . get = util . promisify ( redisClient . get ) ;
@ -80,8 +80,8 @@ interface Movie {
export default class AnimeController {
async schedule ( req : Request , res : Response , next : NextFunction ) {
const { day } = req . params ;
let data : any ;
const { day } = req . params ;
let info : any ;
try {
if ( redisClient . connected ) {
@ -96,7 +96,7 @@ export default class AnimeController {
}
}
data = await requestGot ( ` ${ urls . BASE_JIKAN } schedule / ${ day } ` , {
info = await requestGot ( ` ${ urls . BASE_JIKAN } schedule s?filter= ${ day } ` , {
parse : true ,
scrapy : false ,
} ) ;
@ -104,10 +104,10 @@ export default class AnimeController {
return next ( err ) ;
}
const animeList : Schedule [ ] = data[ day ] . map ( ( item : Schedule ) = > ( {
title : item.title ,
const animeList : Schedule [ ] = info. data . map ( ( item : any ) = > ( {
title : item.title s.find( ( x : { type : string ; } ) = > x . type === "Default" ) . title ,
malid : item.mal_id ,
image : item.image _url,
image : item.image s.jpg.image _url,
} ) ) ;
if ( animeList . length > 0 ) {
@ -116,14 +116,14 @@ export default class AnimeController {
redisClient . set (
` schedule_ ${ hashStringMd5 ( day ) } ` ,
JSON . stringify ( { day : animeList } ) ,
JSON . stringify ( { day : animeList } ) ,
) ;
/* After 24 hrs expire the key. */
/* After 6 hrs expire the key. */
redisClient . expire at (
redisClient . expire (
` schedule_ ${ hashStringMd5 ( day ) } ` ,
parseInt ( ` ${ + new Date ( ) / 1000 } ` , 10 ) + 7 200,
+ 216 00,
) ;
}
@ -131,13 +131,13 @@ export default class AnimeController {
day : animeList ,
} ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async top ( req : Request , res : Response , next : NextFunction ) {
const { type , subtype , page } = req . params ;
let data : any ;
const { type , subtype , page } = req . params ;
let info : any ;
try {
if ( redisClient . connected ) {
@ -161,12 +161,12 @@ export default class AnimeController {
}
if ( subtype !== undefined ) {
data = await requestGot (
` ${ urls . BASE_JIKAN } top/ ${ type } /${ page } / ${ subtyp e} ` ,
{ parse : true , scrapy : false } ,
info = await requestGot (
` ${ urls . BASE_JIKAN } top/ ${ type } ?filter=${ subtype } &page= ${ pag e} ` ,
{ parse : true , scrapy : false } ,
) ;
} else {
data = await requestGot ( ` ${ urls . BASE_JIKAN } top/ ${ type } / ${ page } ` , {
info = await requestGot ( ` ${ urls . BASE_JIKAN } top/ ${ type } ?page= ${ page } ` , {
parse : true ,
scrapy : false ,
} ) ;
@ -175,11 +175,12 @@ export default class AnimeController {
return next ( err ) ;
}
const top : Top [ ] = data . top . map ( ( item : Top ) = > ( {
rank : item.rank ,
title : item.title ,
const top : Top [ ] = info . data . map ( ( item : any , index : number ) = > ( {
// A little hacky way to fix null ranks
rank : item.rank || index + 1 + ( info . pagination . current_page - 1 ) * info . pagination . items . per_page ,
title : item.titles.find ( ( x : { type : string ; } ) = > x . type === "Default" ) . title ,
url : item.url ,
image_url : item.image _url,
image_url : item.image s.jpg.image _url,
type : type ,
subtype : subtype ,
page : page ,
@ -192,12 +193,12 @@ export default class AnimeController {
if ( subtype ) {
redisClient . set (
` top_ ${ hashStringMd5 ( ` ${ type } : ${ subtype } : ${ page } ` ) } ` ,
JSON . stringify ( { top } ) ,
JSON . stringify ( { top } ) ,
) ;
} else {
redisClient . set (
` top_ ${ hashStringMd5 ( ` ${ type } : ${ page } ` ) } ` ,
JSON . stringify ( { top } ) ,
JSON . stringify ( { top } ) ,
) ;
}
@ -216,9 +217,9 @@ export default class AnimeController {
}
}
return res . status ( 200 ) . json ( { top } ) ;
return res . status ( 200 ) . json ( { top } ) ;
} else {
return res . status ( 400 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
return res . status ( 400 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
@ -229,6 +230,7 @@ export default class AnimeController {
data = await requestGot ( ` ${ urls . BASE_ANIMEFLV } api/animes/list ` , {
parse : true ,
scrapy : false ,
spoof : true ,
} ) ;
} catch ( err ) {
return next ( err ) ;
@ -243,14 +245,15 @@ export default class AnimeController {
} ) ) ;
if ( animes . length > 0 ) {
res . status ( 200 ) . send ( { animes } ) ;
res . status ( 200 ) . send ( { animes } ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getLastEpisodes ( req : Request , res : Response , next : NextFunction ) {
let $ : cheerio.Root ;
let lastEpisodes ;
let episodes : Episode [ ] = [ ] ;
let animeList : any [ ] = [ ] ;
@ -267,45 +270,23 @@ export default class AnimeController {
}
}
$ = await requestGot ( ` ${ urls . BASE_ MONOSCHINOS} ` , {
scrapy : tru e,
parse : fals e,
lastEpisodes = await requestGot ( ` ${ urls . BASE_ ARUPPI_ MONOSCHINOS} lastest ` , {
scrapy : fals e,
parse : tru e,
} ) ;
} catch ( err ) {
return next ( err ) ;
}
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 ,
} ;
animeList . push ( anime ) ;
for ( const anime of lastEpisodes ) {
animeList . push ( {
id : ` ver/ ${ anime . id } ` ,
title : anime.title ,
image : anime.image ,
episode : anime.no ,
} ) ;
}
for ( const anime of animeList ) {
episodes . push ( {
@ -323,7 +304,7 @@ export default class AnimeController {
redisClient . set (
` lastEpisodes_ ${ hashStringMd5 ( 'lastEpisodes' ) } ` ,
JSON . stringify ( { episodes } ) ,
JSON . stringify ( { episodes } ) ,
) ;
/* After 24hrs expire the key. */
@ -338,12 +319,12 @@ export default class AnimeController {
episodes ,
} ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getContentTv ( req : Request , res : Response , next : NextFunction ) {
const { type , page } = req . params ;
const { type , page } = req . params ;
const url = 'tv' ;
let data : any ;
@ -395,7 +376,7 @@ export default class AnimeController {
redisClient . set (
` contentTv_ ${ hashStringMd5 ( ` ${ type } : ${ page } ` ) } ` ,
JSON . stringify ( { animes } ) ,
JSON . stringify ( { animes } ) ,
) ;
/* After 24hrs expire the key. */
@ -410,12 +391,12 @@ export default class AnimeController {
animes ,
} ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getContentSpecial ( req : Request , res : Response , next : NextFunction ) {
const { type , page } = req . params ;
const { type , page } = req . params ;
const url = 'special' ;
let data : any ;
@ -467,7 +448,7 @@ export default class AnimeController {
redisClient . set (
` contentSpecial_ ${ hashStringMd5 ( ` ${ type } : ${ page } ` ) } ` ,
JSON . stringify ( { animes } ) ,
JSON . stringify ( { animes } ) ,
) ;
/* After 24hrs expire the key. */
@ -482,12 +463,12 @@ export default class AnimeController {
animes ,
} ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getContentOva ( req : Request , res : Response , next : NextFunction ) {
const { type , page } = req . params ;
const { type , page } = req . params ;
const url = 'ova' ;
let data : any ;
@ -539,7 +520,7 @@ export default class AnimeController {
redisClient . set (
` contentOva_ ${ hashStringMd5 ( ` ${ type } : ${ page } ` ) } ` ,
JSON . stringify ( { animes } ) ,
JSON . stringify ( { animes } ) ,
) ;
/* After 24hrs expire the key. */
@ -554,12 +535,12 @@ export default class AnimeController {
animes ,
} ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getContentMovie ( req : Request , res : Response , next : NextFunction ) {
const { type , page } = req . params ;
const { type , page } = req . params ;
const url = 'movies' ;
let data : any ;
@ -611,7 +592,7 @@ export default class AnimeController {
redisClient . set (
` contentMovie_ ${ hashStringMd5 ( ` ${ type } : ${ page } ` ) } ` ,
JSON . stringify ( { animes } ) ,
JSON . stringify ( { animes } ) ,
) ;
/* After 24hrs expire the key. */
@ -626,12 +607,12 @@ export default class AnimeController {
animes ,
} ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getEpisodes ( req : Request , res : Response , next : NextFunction ) {
const { title } = req . params ;
const { title } = req . params ;
let searchAnime : ModelA | null ;
let episodes : any ;
@ -649,7 +630,7 @@ export default class AnimeController {
}
searchAnime = await AnimeModel . findOne ( {
$or : [ { title : { $eq : title } } , { title : { $eq : ` ${ title } (TV) ` } } ] ,
$or : [ { title : { $eq : title } } , { title : { $eq : ` ${ title } (TV) ` } } ] ,
} ) ;
} catch ( err ) {
return next ( err ) ;
@ -676,7 +657,7 @@ export default class AnimeController {
redisClient . set (
` episodes_ ${ hashStringMd5 ( title ) } ` ,
JSON . stringify ( { episodes } ) ,
JSON . stringify ( { episodes } ) ,
) ;
/* After 24hrs expire the key. */
@ -687,14 +668,14 @@ export default class AnimeController {
) ;
}
res . status ( 200 ) . json ( { episodes } ) ;
res . status ( 200 ) . json ( { episodes } ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
async getServers ( req : Request , res : Response , next : NextFunction ) {
const { id } = req . params ;
const { id } = req . params ;
let data : any ;
try {
@ -710,15 +691,36 @@ export default class AnimeController {
}
}
if (
id . split ( '/' ) [ 0 ] === 'ver' &&
id . split ( '-' ) . indexOf ( 'espanol' ) !== - 1
) {
data = await videoServersMonosChinos ( id ) ;
} else if ( id . split ( '/' ) [ 0 ] === 'ver' ) {
let indicator = false ;
if ( id . split ( '/' ) [ 0 ] === 'ver' && ! indicator ) {
data = await videoServersTioAnime ( id ) ;
} else {
data = await videoServersJK ( id ) ;
if ( ! data . name ) {
indicator = true ;
}
}
if ( id . split ( '/' ) [ 0 ] === 'ver' && ! indicator ) {
data = await videoServersMonosChinos ( id ) ;
if ( ! data . name ) {
console . log ( data . name ) ;
indicator = true ;
}
}
if ( ! indicator ) {
data = undefined ;
indicator = true ;
/ *
This part is just for handling the error
if the two above doesn ' t complete the operation
does not make sense to have the getServers from
JKAnime .
* /
}
if ( data ) {
@ -727,7 +729,7 @@ export default class AnimeController {
redisClient . set (
` servers_ ${ hashStringMd5 ( id ) } ` ,
JSON . stringify ( { servers : data } ) ,
JSON . stringify ( { servers : data } ) ,
) ;
/* After 24hrs expire the key. */
@ -738,9 +740,9 @@ export default class AnimeController {
) ;
}
res . status ( 200 ) . json ( { servers : data } ) ;
res . status ( 200 ) . json ( { servers : data } ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
} catch ( err ) {
return next ( err ) ;
@ -752,7 +754,7 @@ export default class AnimeController {
let animeResult : any ;
try {
animeQuery = await AnimeModel . aggregate ( [ { $sample : { size : 1 } } ] ) ;
animeQuery = await AnimeModel . aggregate ( [ { $sample : { size : 1 } } ] ) ;
} catch ( err ) {
return next ( err ) ;
}
@ -774,7 +776,7 @@ export default class AnimeController {
res . set ( 'Cache-Control' , 'no-store' ) ;
res . status ( 200 ) . json ( animeResult ) ;
} else {
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
res . status ( 500 ) . json ( { message : 'Aruppi lost in the shell' } ) ;
}
}
}