From 51e8a0d4bc3e14531da2a296042d32eb0dd27380 Mon Sep 17 00:00:00 2001 From: gratenes <69170374+Gratenes@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:14:25 -0400 Subject: [PATCH] fix m3u8 files with relative endpoints --- src/logic/v2.ts | 2 +- src/utils/index.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/logic/v2.ts b/src/logic/v2.ts index b7d9802..1180d2a 100644 --- a/src/logic/v2.ts +++ b/src/logic/v2.ts @@ -59,7 +59,7 @@ export const M3u8ProxyV2 = async (request: Request): Promise continue; } - const url = getUrl(line, scrapeUrl.protocol + "//" + scrapeUrl.hostname) + const url = getUrl(line, scrapeUrl) const searchParams = new URLSearchParams() searchParams.set('url', url.toString()) diff --git a/src/utils/index.ts b/src/utils/index.ts index d5a5d03..9a214f2 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,15 @@ -export function getUrl(input: string, fallbackUrl: string): URL { +export function getUrl(input: string, fallbackUrl: URL): URL { + // sense its an m3u8 remove the last pathname try { return new URL(input) } catch (e) { - return new URL(input, fallbackUrl); + const pathname = input.startsWith("/") + ? input.substring(1) + : input; + const pathnames = fallbackUrl.pathname.split("/") + pathnames[pathnames.length - 1] = pathname; + + fallbackUrl.pathname = pathnames.join("/") + return fallbackUrl } } \ No newline at end of file