Skip to content

Commit

Permalink
fix: handle html escape symbols in segment urls
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalygashkov committed Apr 22, 2024
1 parent 30eed95 commit 6964304
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6964304

Please sign in to comment.