Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for #EXT-X-PART #127

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add support for #EXT-X-PART
  • Loading branch information
brandonocasey committed Jan 20, 2021
commit 1429dd9f514f7a4893c398ab8fdf7cd0f1a6065b
34 changes: 34 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
@@ -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', {
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -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);
},
116 changes: 116 additions & 0 deletions test/fixtures/m3u8/llhls.json
Original file line number Diff line number Diff line change
@@ -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"),
4 changes: 2 additions & 2 deletions test/fixtures/m3u8/llhls.m3u8
Original file line number Diff line number Diff line change
@@ -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"
120 changes: 120 additions & 0 deletions test/fixtures/m3u8/llhlsDelta.json
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 2 additions & 2 deletions test/fixtures/m3u8/llhlsDelta.m3u8
Original file line number Diff line number Diff line change
@@ -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"