refactor vidsrccx.ts: remove URL signing logic and update CDN hostname

This commit is contained in:
Mapler 2025-08-06 01:19:33 +10:00
parent 678f105e87
commit 5cd501103c

View file

@ -1,61 +1,9 @@
import CryptoJS from 'crypto-js';
import { flags } from '@/entrypoint/utils/targets';
import { SourcererOutput, makeSourcerer } from '@/providers/base';
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
const CDN_HOSTNAME = 'vidsrccx.b-cdn.net';
const SECURITY_KEY = '83f1da34-e937-4735-a51c-c544700168da';
function signUrl(
url: string,
securityKey: string,
expirationTime = 3600,
userIp: string | null = null,
isDirectory = false,
pathAllowed: string | null = null,
) {
const urlObj = new URL(url);
const protocol = urlObj.protocol;
const host = urlObj.host;
const path = urlObj.pathname;
const queryParams = urlObj.searchParams;
let pathForSigning = path;
if (pathAllowed) {
pathForSigning = pathAllowed;
queryParams.set('token_path', pathForSigning);
}
const expires = Math.floor(Date.now() / 1000) + expirationTime;
const sortedParams = Array.from(queryParams.keys()).sort();
let queryParamString = '';
let queryParamStringUrl = '';
sortedParams.forEach((key) => {
if (queryParamString.length > 0) {
queryParamString += '&';
queryParamStringUrl += '&';
}
queryParamString += `${key}=${queryParams.get(key)}`;
queryParamStringUrl += `${key}=${encodeURIComponent(queryParams.get(key) || '')}`;
});
let stringToSign = securityKey + pathForSigning + expires;
if (userIp) {
stringToSign += userIp;
}
stringToSign += queryParamString;
const hash = CryptoJS.SHA256(stringToSign);
const token = CryptoJS.enc.Base64.stringify(hash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
if (isDirectory) {
return `${protocol}//${host}/bcdn_token=${token}&expires=${expires}${queryParamStringUrl ? `&${queryParamStringUrl}` : ''}${path}`;
}
return `${protocol}//${host}${path}?token=${token}${queryParamStringUrl ? `&${queryParamStringUrl}` : ''}&expires=${expires}`;
}
const CDN_HOSTNAME = 'download.fedsr.us';
async function comboScraper(ctx: MovieScrapeContext | ShowScrapeContext): Promise<SourcererOutput> {
const media = ctx.media;
@ -69,17 +17,13 @@ async function comboScraper(ctx: MovieScrapeContext | ShowScrapeContext): Promis
throw new NotFoundError('Unsupported media type');
}
const signedUrl = signUrl(
`https://${CDN_HOSTNAME}${path}`,
SECURITY_KEY,
3600,
null,
true,
`/media/${media.tmdbId}/`,
);
const url = `https://${CDN_HOSTNAME}${path}`;
const res = await ctx.proxiedFetcher.full(signedUrl, {
const res = await ctx.proxiedFetcher.full(url, {
method: 'HEAD',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
},
});
if (res.statusCode !== 200) throw new NotFoundError('stream not found');
@ -89,7 +33,7 @@ async function comboScraper(ctx: MovieScrapeContext | ShowScrapeContext): Promis
{
id: 'primary',
type: 'hls',
playlist: signedUrl,
playlist: url,
flags: [flags.CORS_ALLOWED],
captions: [],
},