diff --git a/src/modules/stream/internal-hls.js b/src/modules/stream/internal-hls.js index c6a11455..9fa37e6e 100644 --- a/src/modules/stream/internal-hls.js +++ b/src/modules/stream/internal-hls.js @@ -1,16 +1,27 @@ import { createInternalStream } from './manage.js'; import HLS from 'hls-parser'; -import path from "node:path"; + +function getURL(url) { + try { + return new URL(url); + } catch { + return null; + } +} function transformObject(streamInfo, hlsObject) { if (hlsObject === undefined) { return (object) => transformObject(streamInfo, object); } - const fullUrl = hlsObject.uri.startsWith("/") - ? new URL(hlsObject.uri, streamInfo.url).toString() - : new URL(path.join(streamInfo.url, "/../", hlsObject.uri)).toString(); - hlsObject.uri = createInternalStream(fullUrl, streamInfo); + let fullUrl; + if (getURL(hlsObject.uri)) { + fullUrl = hlsObject.uri; + } else { + fullUrl = new URL(hlsObject.uri, streamInfo.url); + } + + hlsObject.uri = createInternalStream(fullUrl.toString(), streamInfo); return hlsObject; }