Skip to content

Commit

Permalink
Fix a stringify failure found in EXT-X-DATERANGE's END-DATE attr (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuu authored Oct 9, 2023
1 parent 72f0d3a commit 2e84a35
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ function checkDateRange(segments: Segment[]) {
}
}
range.push({start, end});
} else {
} else if (dateRange.classId) {
rangeList.set(dateRange.classId, [{start, end}]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function buildDateRange(dateRange: DateRange) {
attrs.push(`START-DATE="${utils.formatDate(dateRange.start)}"`);
}
if (dateRange.end) {
attrs.push(`END-DATE="${dateRange.end}"`);
attrs.push(`END-DATE="${utils.formatDate(dateRange.end)}"`);
}
if (dateRange.duration) {
attrs.push(`DURATION=${dateRange.duration}`);
Expand Down
23 changes: 23 additions & 0 deletions test/fixtures/m3u8/SCTE-35_07.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This example shows two EXT-X-DATERANGE tags that describe a single
# Date Range, with a SCTE-35 "out" splice_insert() command that is
# subsequently updated with an SCTE-35 "in" splice_insert() command.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:30

#EXT-X-PROGRAM-DATE-TIME:2014-03-05T11:14:00.000Z
#EXTINF:30,
http://media.example.com/01.ts
#EXTINF:30,
http://media.example.com/02.ts
#EXT-X-DATERANGE:ID="splice-6FFFFFF0",START-DATE="2023-10-09T06:16:00.820Z",PLANNED-DURATION=59.993,SCTE35-OUT=0xFC30250001D1F7E25300FFF0140565239AA07FEFFE015C3F90FE00526362000101010000A7C1792D
#EXTINF:30,
http://ads.example.com/ad-01.ts
#EXTINF:30,
http://ads.example.com/ad-02.ts
#EXT-X-DATERANGE:ID="splice-6FFFFFF0",START-DATE="2023-10-09T06:16:00.820Z",END-DATE="2023-10-09T06:17:01.514Z",DURATION=60.694
#EXTINF:30,
http://media.example.com/03.ts
#EXTINF:3.003,
http://media.example.com/04.ts
72 changes: 72 additions & 0 deletions test/fixtures/objects/SCTE-35_07.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const {MediaPlaylist, Segment, DateRange} = require('../../../types');
const utils = require('../../../utils');

const playlist = new MediaPlaylist({
version: 3,
targetDuration: 30,
segments: createSegments()
});

function createSegments() {
const segments = [];
segments.push(new Segment({
uri: 'http://media.example.com/01.ts',
duration: 30,
title: '',
mediaSequenceNumber: 0,
discontinuitySequence: 0,
programDateTime: new Date('2014-03-05T11:14:00Z')
}));
segments.push(new Segment({
uri: 'http://media.example.com/02.ts',
duration: 30,
title: '',
mediaSequenceNumber: 1,
discontinuitySequence: 0
}));
segments.push(new Segment({
uri: 'http://ads.example.com/ad-01.ts',
duration: 30,
title: '',
mediaSequenceNumber: 2,
discontinuitySequence: 0,
dateRange: new DateRange({
id: 'splice-6FFFFFF0',
start: new Date('2023-10-09T06:16:00.820Z'),
plannedDuration: 59.993,
attributes: {
'SCTE35-OUT': utils.hexToByteSequence('0xFC30250001D1F7E25300FFF0140565239AA07FEFFE015C3F90FE00526362000101010000A7C1792D')
}
})
}));
segments.push(new Segment({
uri: 'http://ads.example.com/ad-02.ts',
duration: 30,
title: '',
mediaSequenceNumber: 3,
discontinuitySequence: 0
}));
segments.push(new Segment({
uri: 'http://media.example.com/03.ts',
duration: 30,
title: '',
mediaSequenceNumber: 4,
discontinuitySequence: 0,
dateRange: new DateRange({
id: 'splice-6FFFFFF0',
start: new Date('2023-10-09T06:16:00.820Z'),
end: new Date('2023-10-09T06:17:01.514Z'),
duration: 60.694
})
}));
segments.push(new Segment({
uri: 'http://media.example.com/04.ts',
duration: 3.003,
title: '',
mediaSequenceNumber: 5,
discontinuitySequence: 0
}));
return segments;
}

module.exports = playlist;

0 comments on commit 2e84a35

Please sign in to comment.