From 696430468134c291a5753f1eddba6bb3aeb06e55 Mon Sep 17 00:00:00 2001 From: Vitaly Gashkov Date: Mon, 22 Apr 2024 19:07:53 +0500 Subject: [PATCH] fix: handle html escape symbols in segment urls --- lib/dash.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/dash.js b/lib/dash.js index be6408a..ce6c3a2 100644 --- a/lib/dash.js +++ b/lib/dash.js @@ -236,6 +236,21 @@ const parseSegmentFromBase = async (segmentBase, baseUrl) => { return { url: baseUrl, range: mediaRange }; }; +const transformSegmentUrls = (segments) => { + for (const segment of segments) { + const hasHtmlEscapeCode = segment.url.includes('&'); + if (hasHtmlEscapeCode) { + const url = new URL(segment.url); + const entries = new URLSearchParams(url.searchParams.toString()).entries(); + for (const [key, value] of entries) { + url.searchParams.delete(key); + url.searchParams.append(key.replaceAll('amp;', ''), value); + } + segment.url = url.toString(); + } + } +}; + const protectionSchemas = { 'urn:mpeg:dash:mp4protection:2011': 'common', 'urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95': 'playready', @@ -298,6 +313,7 @@ const parseManifest = async (text, url, fallbackLanguage) => { } else { throw new Error('Could not find a way to get segments from this MPD manifest.'); } + transformSegmentUrls(segments); const label = get('label'); const fps = get('frameRate') ?? segmentBase?.attributes.timescale;