Skip to content

Commit

Permalink
Merge pull request #18 from Eltik/chaycee-patch-1
Browse files Browse the repository at this point in the history
Update sources.ts to use cached sub spoofing
  • Loading branch information
vynxc authored Jan 10, 2024
2 parents e8a6173 + 377dcc2 commit b5d1431
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions anify-backend/src/server/impl/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cacheTime, redis } from "..";
import content from "../../content";
import { env } from "../../env";
import { StreamingServers, SubType } from "../../types/enums";
import { Source } from "../../types/types";
import queues from "../../worker";
import { createResponse } from "../lib/response";
import crypto from "crypto";
Expand Down Expand Up @@ -49,6 +50,13 @@ export const handler = async (req: Request): Promise<Response> => {

const cached = await redis.get(`sources:${id}:${episodeNumber}:${providerId}:${watchId}:${subType}:${server}`);
if (cached) {
const cachedData = JSON.parse(cached) as Source;
if(env.USE_SUBTITLE_SPOOFING){
cachedData?.subtitles?.forEach((sub) => {
if(sub.lang != "Thumbnails"&&sub.url.endsWith(".vtt")&&!sub.url.startsWith(env.API_URL))
sub.url = env.API_URL+"/subtitles/" + encodeUrl(sub.url)+".vtt";
});
}
return createResponse(cached);
}

Expand All @@ -72,7 +80,6 @@ export const handler = async (req: Request): Promise<Response> => {
return createResponse(JSON.stringify({ error: "An error occurred." }), 500);
}
};

const route = {
method: "GET",
path: "/sources",
Expand All @@ -95,4 +102,4 @@ function encodeUrl(url:string) {
let encrypted = cipher.update(url, 'utf-8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
}

0 comments on commit b5d1431

Please sign in to comment.