Skip to content

Commit

Permalink
fixup! wip: variable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bwallberg committed Feb 22, 2024
1 parent 6974dc4 commit f52066c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/manifests/handlers/dash/segment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' }
},
Expand Down
13 changes: 3 additions & 10 deletions src/manifests/handlers/dash/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(
Expand Down

0 comments on commit f52066c

Please sign in to comment.