Skip to content

Commit

Permalink
feat: add support for #EXT-X-PART (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Jan 20, 2021
1 parent 9cebc86 commit 9f5a224
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,40 @@ export default class ParseStream extends Stream {
this.trigger('data', event);
return;
}
match = (/^#EXT-X-PART:(.*)$/).exec(newLine);
if (match && match[1]) {
event = {
type: 'tag',
tagType: 'part'
};
event.attributes = parseAttributes(match[1]);
['DURATION'].forEach(function(key) {
if (event.attributes.hasOwnProperty(key)) {
event.attributes[key] = parseFloat(event.attributes[key]);
}
});

['INDEPENDENT', 'GAP'].forEach(function(key) {
if (event.attributes.hasOwnProperty(key)) {
event.attributes[key] = (/YES/).test(event.attributes[key]);
}
});

if (event.attributes.hasOwnProperty('BYTERANGE')) {
const [length, offset] = event.attributes.BYTERANGE.split('@');

event.byterange = {};
if (length) {
event.byterange.length = parseInt(length, 10);
}
if (offset) {
event.byterange.offset = parseInt(offset, 10);
}
}

this.trigger('data', event);
return;
}

// unknown tag type
this.trigger('data', {
Expand Down
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ export default class Parser extends Stream {
},
'skip'() {
this.manifest.skip = entry.attributes;
},
'part'() {
this.manifest.parts = this.manifest.parts || [];
this.manifest.parts.push(entry.attributes);
}
})[entry.tagType] || noop).call(self);
},
Expand Down
116 changes: 116 additions & 0 deletions test/fixtures/m3u8/llhls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,122 @@
"discontinuitySequence": 0,
"discontinuityStarts": [],
"mediaSequence": 266,
"parts": [
{
"DURATION": 0.33334,
"URI": "filePart271.0.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.1.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.2.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.3.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart271.4.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.5.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.6.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.7.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart271.8.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.9.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.10.mp4"
},
{
"BYTERANGE": "587500@522828",
"DURATION": 0.33334,
"URI": "filePart271.11.mp4"
},
{
"DURATION": 0.33334,
"GAP": true,
"URI": "filePart272.a.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.b.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.c.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.d.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.e.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart272.f.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.g.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.h.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.i.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.j.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.k.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.l.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart273.0.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart273.1.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart273.2.mp4"
}
],
"segments": [
{
"dateTimeObject": new Date("2019-02-14T02:13:36.106Z"),
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/m3u8/llhls.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ fileSequence270.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart271.8.mp4",INDEPENDENT=YES
#EXT-X-PART:DURATION=0.33334,URI="filePart271.9.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.10.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.11.mp4"
#EXT-X-PART:BYTERANGE=587500@522828,DURATION=0.33334,URI="filePart271.11.mp4"
#EXTINF:4.00008,
fileSequence271.mp4
#EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z
#EXT-X-PART:DURATION=0.33334,URI="filePart272.a.mp4"
#EXT-X-PART:GAP=YES,DURATION=0.33334,URI="filePart272.a.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.b.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.c.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.d.mp4"
Expand Down
120 changes: 120 additions & 0 deletions test/fixtures/m3u8/llhlsDelta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,126 @@
"discontinuitySequence": 0,
"discontinuityStarts": [],
"mediaSequence": 266,
"parts": [
{
"DURATION": 0.33334,
"URI": "filePart271.0.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.1.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.2.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.3.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart271.4.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.5.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.6.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.7.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart271.8.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.9.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart271.10.mp4"
},
{
"BYTERANGE": "587500@522828",
"DURATION": 0.33334,
"URI": "filePart271.11.mp4"
},
{
"DURATION": 0.33334,
"GAP": true,
"URI": "filePart272.a.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.b.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.c.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.d.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.e.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart272.f.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.g.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.h.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.i.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.j.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.k.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart272.l.mp4"
},
{
"DURATION": 0.33334,
"INDEPENDENT": true,
"URI": "filePart273.0.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart273.1.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart273.2.mp4"
},
{
"DURATION": 0.33334,
"URI": "filePart273.3.mp4"
}
],
"segments": [
{
"duration": 4.00008,
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/m3u8/llhlsDelta.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ fileSequence270.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart271.8.mp4",INDEPENDENT=YES
#EXT-X-PART:DURATION=0.33334,URI="filePart271.9.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.10.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.11.mp4"
#EXT-X-PART:BYTERANGE=587500@522828,DURATION=0.33334,URI="filePart271.11.mp4"
#EXTINF:4.00008,
fileSequence271.mp4
#EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z
#EXT-X-PART:DURATION=0.33334,URI="filePart272.a.mp4"
#EXT-X-PART:GAP=YES,DURATION=0.33334,URI="filePart272.a.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.b.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.c.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.d.mp4"
Expand Down

0 comments on commit 9f5a224

Please sign in to comment.