From f52066c76129fb546c725a7979b4cf2f5e02b916 Mon Sep 17 00:00:00 2001 From: Benjamin Wallberg Date: Thu, 22 Feb 2024 13:10:21 +0100 Subject: [PATCH] fixup! wip: variable handling --- src/manifests/handlers/dash/segment.test.ts | 2 +- src/manifests/handlers/dash/segment.ts | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/manifests/handlers/dash/segment.test.ts b/src/manifests/handlers/dash/segment.test.ts index a341744..8e5ac98 100644 --- a/src/manifests/handlers/dash/segment.test.ts +++ b/src/manifests/handlers/dash/segment.test.ts @@ -6,7 +6,7 @@ describe('dashSegmentHandler', () => { queryStringParameters: { url: 'https://stream.with.underscore/hello_world_live-$RepresentationID$-$Time$.dash' }, - path: '/segment_82008145102133_audio_track_0_0_nor=128000_128000', + path: '/segment_82008145102133_bitrate_audio_track_0_0_nor=128000_128000', requestContext: { elb: { targetGroupArn: '' } }, diff --git a/src/manifests/handlers/dash/segment.ts b/src/manifests/handlers/dash/segment.ts index b68cecb..c91eb54 100644 --- a/src/manifests/handlers/dash/segment.ts +++ b/src/manifests/handlers/dash/segment.ts @@ -37,18 +37,17 @@ 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_" - // 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 + const representationIdStr = representationIdStrList.join('_'); let segmentUrl = url; + // Build correct Source Segment url if (segmentUrl.includes('$Time$')) { segmentUrl = segmentUrl.replace('$Time$', reqSegmentIndexOrTimeStr); } else { + // segment templates may contain a width parameter "$Number%0[width]d$", and then we need to zero-pad them to that length segmentUrl = segmentUrl .replace(/\$Number%0(\d+)d\$/, (_, width) => reqSegmentIndexOrTimeStr.padStart(Number(width), '0') @@ -57,12 +56,6 @@ 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(