Skip to content

Commit

Permalink
Merge pull request #1180 from stevemayhew/fix-playlist-parse-issue
Browse files Browse the repository at this point in the history
Fix issue #1179 with playlist parse
  • Loading branch information
mangui committed Jun 3, 2017
2 parents 1c89388 + 8ca06da commit 3a3dd20
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"watch": "watchify --debug -s Hls src/index.js -t [babelify] -o dist/hls.js",
"pretest": "npm run lint",
"test": "mocha --compilers js:babel-register --recursive tests/unit",
"testfunc": "mocha --compilers js:babel-register tests/functional/auto/hlsjs.js --timeout 40000",
"testfunc": "mocha --compilers js:babel-register tests/functional/auto/hlsjs.js --timeout 80000",
"lint": "jshint src/",
"serve": "http-server -p 8000 .",
"open": "opener http://localhost:8000/demo/",
Expand Down
10 changes: 9 additions & 1 deletion src/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import {logger} from '../utils/logger';
// https://regex101.com is your friend
const MASTER_PLAYLIST_REGEX = /#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)/g;
const MASTER_PLAYLIST_MEDIA_REGEX = /#EXT-X-MEDIA:(.*)/g;
const LEVEL_PLAYLIST_REGEX_FAST = /#EXTINF:(\d*(?:\.\d+)?)(?:,(.*))?|(?!#)(\S.+)|#EXT-X-BYTERANGE: *(.+)|#EXT-X-PROGRAM-DATE-TIME:(.+)|#.*/g;

const LEVEL_PLAYLIST_REGEX_FAST = new RegExp([
/#EXTINF:(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source, // duration (#EXTINF:<duration>,<title>), group 1 => duration, group 2 => title
/|(?!#)(\S+)/.source, // segment URI, group 3 => the URI (note newline is not eaten)
/|#EXT-X-BYTERANGE:*(.+)/.source, // next segment's byterange, group 4 => range spec (x@y)
/|#EXT-X-PROGRAM-DATE-TIME:(.+)/.source, // next segment's program date/time group 5 => the datetime spec
/|#.*/.source // All other non-segment oriented tags will match with all groups empty
].join(''), 'g');

const LEVEL_PLAYLIST_REGEX_SLOW = /(?:(?:#(EXTM3U))|(?:#EXT-X-(PLAYLIST-TYPE):(.+))|(?:#EXT-X-(MEDIA-SEQUENCE): *(\d+))|(?:#EXT-X-(TARGETDURATION): *(\d+))|(?:#EXT-X-(KEY):(.+))|(?:#EXT-X-(START):(.+))|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DISCONTINUITY-SEQ)UENCE:(\d+))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(VERSION):(\d+))|(?:#EXT-X-(MAP):(.+))|(?:(#)(.*):(.*))|(?:(#)(.*))(?:.*)\r?\n?/;

class LevelKey {
Expand Down
28 changes: 26 additions & 2 deletions tests/unit/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ http://proxy-21.dailymotion.com/sec(2a991e17f08fcd94f95637a6dd718ddd)/video/107/
var level = `#EXTM3U
#EXT-X-VERSION:3
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:14
#EXTINF:11.360,`;
#EXT-X-TARGETDURATION:14`;
var result = new PlaylistLoader({on : function() { }}).parseLevelPlaylist(level, 'http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/video/107/282/158282701_mp4_h264_aac_hq.m3u8#cell=core',0);
assert.strictEqual(result.fragments.length, 0);
assert.strictEqual(result.totalduration,0);
Expand Down Expand Up @@ -182,6 +181,31 @@ http://proxy-21.dailymotion.com/sec(2a991e17f08fcd94f95637a6dd718ddd)/video/107/
assert.strictEqual(result.fragments[4].url, 'http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/frag(5)/video/107/282/158282701_mp4_h264_aac_hq.ts');
});

it('parse level with single char fragment URI', () => {
var level = `#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:2
#EXTINF:2,
0
#EXTINF:2,
1
#EXT-X-ENDLIST`;
var result = new PlaylistLoader({on : function() { }}).parseLevelPlaylist(level, 'http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/frag(5)/video/107/282/158282701_mp4_h264_aac_hq.m3u8#cell=core',0);
assert.strictEqual(result.totalduration, 4);
assert.strictEqual(result.startSN, 0);
assert.strictEqual(result.targetduration, 2);
assert.strictEqual(result.live, false);
assert.strictEqual(result.fragments.length, 2);
assert.strictEqual(result.fragments[0].cc, 0);
assert.strictEqual(result.fragments[0].duration, 2);
assert.strictEqual(result.fragments[0].sn, 0);
assert.strictEqual(result.fragments[0].relurl, '0');
assert.strictEqual(result.fragments[1].cc, 0);
assert.strictEqual(result.fragments[1].duration, 2);
assert.strictEqual(result.fragments[1].sn, 1);
assert.strictEqual(result.fragments[1].relurl, '1');
});

it('parse level with EXTINF line without comma', () => {
var level = `#EXTM3U
#EXT-X-VERSION:3
Expand Down

0 comments on commit 3a3dd20

Please sign in to comment.