Skip to content

Commit

Permalink
parse URLs separately to extinf line, parse extinf title field
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed Jul 8, 2016
1 parent 3459384 commit 4de8f65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
36 changes: 14 additions & 22 deletions src/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ class PlaylistLoader extends EventHandler {
frag = null,
result,
regexp,
byteRangeEndOffset,
byteRangeStartOffset,
duration = null,
title = null,
byteRangeEndOffset = null,
byteRangeStartOffset = null,
tagList = [];

regexp = /(?:#EXT-X-(PLAYLIST-TYPE):(.+))|(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT-X-(KEY):(.*)[\r\n]+([^#|\r\n]+)?)|(?:#EXT-X-(START):(.*))|(?:#EXT(INF):([\d\.]+)[^\r\n]*(?:(?:[\r\n]|#(?!EXT).*)+(?!#EXT)(.*))?)|(?:#EXT-X-(BYTERANGE):([\d]+[@[\d]*)]*[\r\n]+([^#|\r\n]+)?|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(PROGRAM-DATE-TIME):(.*)[\r\n]+([^#|\r\n]+)?)|(?:#EXT-X-(VERSION):(\d+))|(?:#(EXT(?:.*)):(.*))|(?:#(EXT(?:.*)))/g;
regexp = /(?:(?:#EXT-X-(PLAYLIST-TYPE):(.+))|(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT-X-(KEY):(.*)?)|(?:#EXT-X-(START):(.*))|(?:#EXT(INF):(\d+(?:\.\d+)?)(?:,(.*))?)|(?:(?!#)()(\S.+))|(?:#EXT-X-(BYTERANGE):(\d+(?:@\d+(?:\.\d+)?))|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(PROGRAM-DATE-TIME):(.*))|(?:#EXT-X-(VERSION):(\d+))|(?:#(.*):(.*))|(?:#(.*)))(?:.*)[\r\n]?/g;
while ((result = regexp.exec(string)) !== null) {
result.shift();
result = result.filter(function(n) { return (n !== undefined); });
Expand Down Expand Up @@ -227,23 +229,21 @@ class PlaylistLoader extends EventHandler {
byteRangeStartOffset = parseInt(params[1]);
}
byteRangeEndOffset = parseInt(params[0]) + byteRangeStartOffset;
if (frag && !frag.url) {
frag.byteRangeStartOffset = byteRangeStartOffset;
frag.byteRangeEndOffset = byteRangeEndOffset;
frag.url = this.resolve(result[2], baseurl);
tagList.push(result);
}
break;
case 'INF':
var duration = parseFloat(result[1]);
duration = parseFloat(result[1]);
title = result[2] ? result[2] : null;
tagList.push(result);
break;
case '': // url
if (!isNaN(duration)) {
var sn = currentSN++;
fragdecryptdata = this.fragmentDecryptdataFromLevelkey(levelkey, sn);
var url = result[2] ? this.resolve(result[2], baseurl) : null;
tagList.push(result);
var url = result[1] ? this.resolve(result[1], baseurl) : null;
frag = {url: url,
type : type,
duration: duration,
title: title,
start: totalduration,
sn: sn,
level: id,
Expand All @@ -255,6 +255,8 @@ class PlaylistLoader extends EventHandler {
tagList: tagList};
level.fragments.push(frag);
totalduration += duration;
duration = null;
title = null;
byteRangeStartOffset = null;
programDateTime = null;
tagList = [];
Expand All @@ -278,16 +280,6 @@ class PlaylistLoader extends EventHandler {
levelkey.iv = decryptiv;
}
}

//issue #425, applying url and decrypt data in instances where EXT-KEY immediately follow EXT-INF
if (frag && !frag.url && result.length >= 3) {
frag.url = this.resolve(result[2], baseurl);

//we have not moved onto another segment, we are still parsing one
fragdecryptdata = this.fragmentDecryptdataFromLevelkey(levelkey, currentSN - 1);
frag.decryptdata = fragdecryptdata;
tagList.push(result);
}
break;
case 'START':
let startParams = result[1];
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ http://proxy-21.dailymotion.com/sec(2a991e17f08fcd94f95637a6dd718ddd)/video/107/
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:11
#EXT-X-KEY:METHOD=AES-128,URI="oceans.key"
#EXTINF:11, no desc
#EXTINF:11,no desc
oceans_aes-audio=65000-video=236000-1.ts
#EXTINF:7, no desc
#EXTINF:7,no desc
oceans_aes-audio=65000-video=236000-2.ts
#EXTINF:7, no desc
#EXTINF:7,no desc
oceans_aes-audio=65000-video=236000-3.ts
#EXT-X-ENDLIST`;
var result = new PlaylistLoader({on : function() { }}).parseLevelPlaylist(level, 'http://foo.com/adaptive/oceans_aes/oceans_aes.m3u8',0);
Expand All @@ -231,6 +231,7 @@ oceans_aes-audio=65000-video=236000-3.ts
assert.strictEqual(result.fragments.length, 3);
assert.strictEqual(result.fragments[0].cc, 0);
assert.strictEqual(result.fragments[0].duration, 11);
assert.strictEqual(result.fragments[0].title, "no desc");
assert.strictEqual(result.fragments[0].level, 0);
assert.strictEqual(result.fragments[0].url, 'http://foo.com/adaptive/oceans_aes/oceans_aes-audio=65000-video=236000-1.ts');
assert.strictEqual(result.fragments[0].decryptdata.uri, 'http://foo.com/adaptive/oceans_aes/oceans.key');
Expand Down

0 comments on commit 4de8f65

Please sign in to comment.