-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix m3u8 files with relative endpoints
- Loading branch information
Showing
2 changed files
with
11 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |