-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix issue #1179 with playlist parse #1180
Conversation
src/loader/playlist-loader.js
Outdated
@@ -12,7 +12,17 @@ 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 = /#EXTINF:(\d*(?:\.\d+)?)(?:,(.*)\s+)?|(?!#)(\S+)|#EXT-X-BYTERANGE:*(.+)|#EXT-X-PROGRAM-DATE-TIME:(.+)|#.*/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left the original format for the RegEx commented out so the exact changes are easy to see
- The second capture group (the title) has an explicit match for the trailing space (line termination)
- Third capture group (the URI) matches one or more non whitespace
- Space removed on the BYTERANGE regex
src/loader/playlist-loader.js
Outdated
/|#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 | ||
]; | ||
const LEVEL_PLAYLIST_REGEX_FAST = new RegExp(LEVEL_PLAYLIST_REGEX_PARTS.join(''), 'g'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split the regex up by alternatives, IMHO makes it easier to read and maintain. You can load the code and print LEVEL_PLAYLIST_REGEX_PARTS.join('')
if one needs to paste the whole expression into something like regex101.
Otherwise the code is exactly the same as the commented out line 15 above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the regexp is complex and splitting it helps to read and maintain.
However in this case you are creating real Regexp
(that are never used) , then converting them to string using Regexp.prototype.source
, whereas you could directly join strings
@@ -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`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The #EXTINF without the required segment (or at least any space character or other tag) following it will not parse with the updated regex. If there is some real code that generates this invalid playlist then we can work on the regex to deal with this explicitly.
assert.strictEqual(result.fragments[1].sn, 1); | ||
assert.strictEqual(result.fragments[1].relurl, '1'); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new test case, that fails with the old code.
This dependency is causing travisci to fail... I'll look at fixing it tomorrow.
The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @stevemayhew !
you might optimize the regexp array using plain string
src/loader/playlist-loader.js
Outdated
/|#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 | ||
]; | ||
const LEVEL_PLAYLIST_REGEX_FAST = new RegExp(LEVEL_PLAYLIST_REGEX_PARTS.join(''), 'g'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the regexp is complex and splitting it helps to read and maintain.
However in this case you are creating real Regexp
(that are never used) , then converting them to string using Regexp.prototype.source
, whereas you could directly join strings
277fb1c should address the build issue. you should be able to revert your Travis related commits |
Thanks.. The Your call, I think it makes it clearer to split it up into multiple If you do the regex as a string and make it multi-line it's a real mess cause you need to escape all the So for example something nice like this:
Has to be:
And you can't paste that into RegEx101 ;-) Again, your call. If you like it split up I'll delete the commented out code in the final commit |
PS thanks for fixing live-reload.. I'll merge again with mainline and update the pull |
…issue Resolve conflict by taking remote package.json (Hopefully fixing the Shoe issue with Travis)
looks good, thanks ! |
Description of the Changes
This fixes issue #1179.
For encrypted playlist that use the SN as the initialization vector the content will not play at all. This is because the playlist regex skips the first N segments and sets the SN to 0 for the Nth segment.
For unencrypted content it simply skips segments.
The problem was with the regex, it does not deal with segment URL that is one character or less.
See checkin/pull comments for why.
CheckLists