Skip to content

Commit

Permalink
fix m3u8 files with relative endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Gratenes committed Aug 12, 2024
1 parent 0b3739b commit 51e8a0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/logic/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const M3u8ProxyV2 = async (request: Request<unknown>): Promise<Response>
continue;
}

const url = getUrl(line, scrapeUrl.protocol + "//" + scrapeUrl.hostname)
const url = getUrl(line, scrapeUrl)
const searchParams = new URLSearchParams()

searchParams.set('url', url.toString())
Expand Down
12 changes: 10 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 51e8a0d

Please sign in to comment.