From 6b4562ea670152d3d0fa4caa687200046ce7fc49 Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Thu, 31 Jul 2025 13:10:26 -0600 Subject: [PATCH] add logic to skip proxied files --- src/utils/valid.ts | 48 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/utils/valid.ts b/src/utils/valid.ts index 3eeef1b..6724db7 100644 --- a/src/utils/valid.ts +++ b/src/utils/valid.ts @@ -31,10 +31,10 @@ export function isValidStream(stream: Stream | undefined): boolean { } /** - * Check if a URL is an M3U8 proxy URL that should be validated with normal fetch + * Check if a URL is a proxy URL that should be validated with normal fetch * instead of proxiedFetcher */ -function isM3U8ProxyUrl(url: string): boolean { +function isAlreadyProxyUrl(url: string): boolean { return url.includes('/m3u8-proxy?url='); } @@ -49,7 +49,7 @@ export async function validatePlayableStream( // dirty temp fix for base64 urls to prep for fmhy poll if (stream.playlist.startsWith('data:')) return stream; - const useNormalFetch = isM3U8ProxyUrl(stream.playlist); + const useNormalFetch = isAlreadyProxyUrl(stream.playlist); let result; if (useNormalFetch) { @@ -84,16 +84,38 @@ export async function validatePlayableStream( } if (stream.type === 'file') { const validQualitiesResults = await Promise.all( - Object.values(stream.qualities).map((quality) => - ops.proxiedFetcher.full(quality.url, { - method: 'GET', - headers: { - ...stream.preferredHeaders, - ...stream.headers, - Range: 'bytes=0-1', - }, - }), - ), + Object.values(stream.qualities).map(async (quality) => { + const useNormalFetch = isAlreadyProxyUrl(quality.url); + + if (useNormalFetch) { + try { + const response = await fetch(quality.url, { + method: 'GET', + headers: { + ...stream.preferredHeaders, + ...stream.headers, + Range: 'bytes=0-1', + }, + }); + return { + statusCode: response.status, + body: await response.text(), + finalUrl: response.url, + }; + } catch (error) { + return { statusCode: 500, body: '', finalUrl: quality.url }; + } + } else { + return ops.proxiedFetcher.full(quality.url, { + method: 'GET', + headers: { + ...stream.preferredHeaders, + ...stream.headers, + Range: 'bytes=0-1', + }, + }); + } + }), ); // remove invalid qualities from the stream const validQualities = stream.qualities;