1
1
import { Redis } from 'ioredis' ;
2
2
import { FastifyRequest , FastifyReply , FastifyInstance , RegisterOptions } from 'fastify' ;
3
3
import { ANIME , META , PROVIDERS_LIST } from '@consumet/extensions' ;
4
- import { Genres } from '@consumet/extensions/dist/models' ;
4
+ import { Genres , SubOrSub } from '@consumet/extensions/dist/models' ;
5
5
import Anilist from '@consumet/extensions/dist/providers/meta/anilist' ;
6
6
import { StreamingServers } from '@consumet/extensions/dist/models' ;
7
7
@@ -133,7 +133,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
133
133
const weekEnd = ( request . query as { weekEnd : number | string } ) . weekEnd ;
134
134
const notYetAired = ( request . query as { notYetAired : boolean } ) . notYetAired ;
135
135
136
- const anilist = generateAnilistMeta ( ) ;
136
+ const anilist = generateAnilistMeta ( ) ;
137
137
const _weekStart = Math . ceil ( Date . now ( ) / 1000 ) ;
138
138
139
139
const res = await anilist . fetchAiringSchedule (
@@ -313,10 +313,14 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
313
313
const episodeId = ( request . params as { episodeId : string } ) . episodeId ;
314
314
const provider = ( request . query as { provider ?: string } ) . provider ;
315
315
const server = ( request . query as { server ?: StreamingServers } ) . server ;
316
+ let isDub = ( request . query as { dub ?: string | boolean } ) . dub ;
316
317
317
318
if ( server && ! Object . values ( StreamingServers ) . includes ( server ) )
318
319
return reply . status ( 400 ) . send ( 'Invalid server' ) ;
319
320
321
+ if ( isDub === 'true' || isDub === '1' ) isDub = true ;
322
+ else isDub = false ;
323
+
320
324
let anilist = generateAnilistMeta ( provider ) ;
321
325
322
326
try {
@@ -326,12 +330,29 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
326
330
. send (
327
331
await cache . fetch (
328
332
redis ,
329
- `anilist:watch;${ episodeId } ;${ anilist . provider . name . toLowerCase ( ) } ;${ server } ` ,
330
- async ( ) => anilist . fetchEpisodeSources ( episodeId , server ) ,
333
+ `anilist:watch;${ episodeId } ;${ anilist . provider . name . toLowerCase ( ) } ;${ server } ;${ isDub ? 'dub' : 'sub' } ` ,
334
+ async ( ) =>
335
+ provider === 'zoro' || provider === 'animekai'
336
+ ? await anilist . fetchEpisodeSources (
337
+ episodeId ,
338
+ server ,
339
+ isDub ? SubOrSub . DUB : SubOrSub . SUB ,
340
+ )
341
+ : await anilist . fetchEpisodeSources ( episodeId , server ) ,
331
342
600 ,
332
343
) ,
333
344
)
334
- : reply . status ( 200 ) . send ( await anilist . fetchEpisodeSources ( episodeId , server ) ) ;
345
+ : reply
346
+ . status ( 200 )
347
+ . send (
348
+ provider === 'zoro' || provider === 'animekai'
349
+ ? await anilist . fetchEpisodeSources (
350
+ episodeId ,
351
+ server ,
352
+ isDub ? SubOrSub . DUB : SubOrSub . SUB ,
353
+ )
354
+ : await anilist . fetchEpisodeSources ( episodeId , server ) ,
355
+ ) ;
335
356
336
357
anilist = new META . Anilist ( undefined , {
337
358
url : process . env . PROXY as string | string [ ] ,
@@ -346,22 +367,23 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
346
367
347
368
//anilist staff info from character id (for example: voice actors)
348
369
//http://127.0.0.1:3000/meta/anilist/staff/95095 (gives info of sukuna's voice actor (Junichi Suwabe) )
349
- fastify . get ( " /staff/:id" , async ( request : FastifyRequest , reply : FastifyReply ) => {
370
+ fastify . get ( ' /staff/:id' , async ( request : FastifyRequest , reply : FastifyReply ) => {
350
371
const id = ( request . params as { id : string } ) . id ;
351
372
352
373
const anilist = generateAnilistMeta ( ) ;
353
374
try {
354
375
redis
355
- ? reply . status ( 200 ) . send (
356
- await cache . fetch (
357
- redis ,
358
- `anilist:staff;${ id } ` ,
359
- async ( ) => await anilist . fetchStaffById ( Number ( id ) ) ,
360
- 60 * 60 ,
361
- ) ,
362
- )
376
+ ? reply
377
+ . status ( 200 )
378
+ . send (
379
+ await cache . fetch (
380
+ redis ,
381
+ `anilist:staff;${ id } ` ,
382
+ async ( ) => await anilist . fetchStaffById ( Number ( id ) ) ,
383
+ 60 * 60 ,
384
+ ) ,
385
+ )
363
386
: reply . status ( 200 ) . send ( await anilist . fetchStaffById ( Number ( id ) ) ) ;
364
-
365
387
} catch ( err : any ) {
366
388
reply . status ( 404 ) . send ( { message : err . message } ) ;
367
389
}
0 commit comments