Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalygashkov committed Dec 6, 2024
2 parents 9681678 + f57a646 commit 4e9b8b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
28 changes: 15 additions & 13 deletions lib/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,20 @@ const parseLanguage = (representation, adaptationSet, fallbackLanguage) => {
return language;
};

const identifierPattern = /\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g;
const identifierReplacement =
(values) => (match, identifier, format, width) => {
if (match === '$$') return '$';
if (typeof values[identifier] === 'undefined') return match;
const value = '' + values[identifier];
if (identifier === 'RepresentationID') return value;
if (!format) width = 1;
else width = parseInt(width, 10);
if (value.length >= width) return value;
return value.padStart(width, '0');
};
const buildSegmentUrl = (template, fields) => {
let result = template;
for (const [key, value] of Object.entries(fields))
result = result.replace('$' + key + '$', value);
return result;
return template.replace(identifierPattern, identifierReplacement(fields));
};

const resolveSegmentTemplateUrls = (segmentTemplate, baseUrl, manifestUrl) => {
Expand Down Expand Up @@ -215,10 +224,6 @@ const parseSegmentsFromTemplate = (
: DEFAULT_SEGMENTS_COUNT;
const bandwidth = representation.get('bandwidth');
const id = representation.get('id');

const sanitizeTemplate = (template) =>
template?.replace(/\$.*?(RepresentationID|Number|Time).*?\$/g, '$$$1$$');

const segments = [];
if (segmentTimeline) {
segments.push(
Expand All @@ -230,9 +235,8 @@ const parseSegmentsFromTemplate = (
),
);
} else {
const template = sanitizeTemplate(segmentTemplate.get('media'));
for (let i = startNumber; i < startNumber + segmentsCount; i++) {
const url = buildSegmentUrl(template, {
const url = buildSegmentUrl(segmentTemplate.get('media'), {
Bandwidth: bandwidth,
RepresentationID: id,
Number: i,
Expand All @@ -241,9 +245,7 @@ const parseSegmentsFromTemplate = (
segments.push({ url });
}
}
const initialization = sanitizeTemplate(
segmentTemplate.get('initialization'),
);
const initialization = segmentTemplate.get('initialization');
if (initialization) {
const url = buildSegmentUrl(initialization, {
Bandwidth: bandwidth,
Expand Down
38 changes: 25 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/axinom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('axinom manifest parsing', async () => {
const firstVideoSegment = firstVideoTrack.segments[1]; // Skip init
strictEqual(
firstVideoSegment.url,
'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/5/1.m4s',
'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/5/0001.m4s',
);

const firstSubtitleTrack = manifest.tracks.subtitles[0];
Expand Down
3 changes: 1 addition & 2 deletions types/dasha.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ export type SubtitleCodec =
| 'TTML'
| 'VTT'
| 'STPP'
| 'fTTML'
| 'fVTT';
| 'WVTT';

export interface SubtitleTrack extends Track {
type: 'text';
Expand Down

0 comments on commit 4e9b8b5

Please sign in to comment.