diff --git a/src/manifests/handlers/dash/segment.ts b/src/manifests/handlers/dash/segment.ts index 87c2ec8..b68cecb 100644 --- a/src/manifests/handlers/dash/segment.ts +++ b/src/manifests/handlers/dash/segment.ts @@ -37,10 +37,13 @@ export default async function dashSegmentHandler( const urlSearchParams = new URLSearchParams(event.queryStringParameters); const pathStem = path.basename(event.path).replace('.mp4', ''); // Get the number part after "segment_" - const [, reqSegmentIndexOrTimeStr, representationIdStr, bitrateStr] = + // eslint-disable-next-line prefer-const + const [, reqSegmentIndexOrTimeStr, bitrateStr, ...representationIdStrList] = pathStem.split('_'); + let representationIdStr = representationIdStrList.join('-'); // Build correct Source Segment url // segment templates may contain a width parameter "$Number%0[width]d$", and then we need to zero-pad them to that length + let segmentUrl = url; if (segmentUrl.includes('$Time$')) { @@ -54,6 +57,12 @@ export default async function dashSegmentHandler( } const reqSegmentIndexInt = parseInt(reqSegmentIndexOrTimeStr); + const possibleId = pathStem.match( + /(audio|video)_track_\d+_\d+_[a-zA-Z]{3}=\d+_\d+/ + ); + if (possibleId) { + representationIdStr = possibleId[0]; + } // Replace RepresentationID in url if present if (representationIdStr) { segmentUrl = segmentUrl.replace( diff --git a/src/manifests/utils/dashManifestUtils.ts b/src/manifests/utils/dashManifestUtils.ts index ae7e56f..8dee572 100644 --- a/src/manifests/utils/dashManifestUtils.ts +++ b/src/manifests/utils/dashManifestUtils.ts @@ -103,8 +103,8 @@ export default function (): DASHManifestTools { mediaUrl.match(/^http/) ? mediaUrl : baseUrl + mediaUrl, urlQuery, hasTime - ? 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$' - : 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$' + ? 'proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$' + : 'proxy-segment/segment_$Number$_$Bandwidth$_$RepresentationID$' ); segmentTemplate.$.media = proxy; // Initialization attr. diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 9e99c8d..923d8ef 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -188,8 +188,10 @@ type ProxyBasenames = | '../../segments/proxy-segment' | 'proxy-segment/segment_$Number$.mp4' | 'proxy-segment/segment_$Time$.mp4' - | 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$' - | 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$'; + | 'proxy-segment/segment_$Number$_$RepresentationID$' + | 'proxy-segment/segment_$Time$_$RepresentationID$' + | 'proxy-segment/segment_$Number$_$Bandwidth$_$RepresentationID$' + | 'proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$'; /** * Adjust paths based on directory navigation @@ -225,7 +227,6 @@ export function proxyPathBuilder( if (!urlSearchParams) { return ''; } - itemUri.replace('-', '/'); const allQueries = new URLSearchParams(urlSearchParams); let sourceItemURL = ''; // Do not build an absolute source url If ItemUri is already an absolut url. diff --git a/src/testvectors/dash/dash1_compressed/proxy-manifest.xml b/src/testvectors/dash/dash1_compressed/proxy-manifest.xml index 54cb16a..632f172 100644 --- a/src/testvectors/dash/dash1_compressed/proxy-manifest.xml +++ b/src/testvectors/dash/dash1_compressed/proxy-manifest.xml @@ -34,7 +34,7 @@ + media="proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$?url=https%3A%2F%2Fmock.mock.com%2Fstream%2Frelative_base%2Faudiotrack%2F%24RepresentationID%24%2F%24Time%24.m4s&statusCode=%5B%7Bi%3A0%2Ccode%3A404%7D%2C%7Bi%3A2%2Ccode%3A401%7D%5D&timeout=%5B%7Bi%3A3%7D%5D&delay=%5B%7Bi%3A2%2Cms%3A2000%7D%5D"> @@ -62,7 +62,7 @@ + media="proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$?url=https%3A%2F%2Fmock.mock.com%2Fstream%2Frelative_base%2Fvideotrack%2F%24RepresentationID%24%2F%24Time%24.m4s&statusCode=%5B%7Bi%3A0%2Ccode%3A404%7D%2C%7Bi%3A2%2Ccode%3A401%7D%5D&timeout=%5B%7Bi%3A3%7D%5D&delay=%5B%7Bi%3A2%2Cms%3A2000%7D%5D"> diff --git a/src/testvectors/dash/dash_period_baseurl/proxy-manifest.xml b/src/testvectors/dash/dash_period_baseurl/proxy-manifest.xml index 29c7c95..c8081de 100644 --- a/src/testvectors/dash/dash_period_baseurl/proxy-manifest.xml +++ b/src/testvectors/dash/dash_period_baseurl/proxy-manifest.xml @@ -1,7 +1,7 @@ - + @@ -17,7 +17,7 @@ - +