Skip to content

Commit 3d6be17

Browse files
author
Rob Walch
committed
Cleanup manifest and playlist RegExp
1 parent 4873445 commit 3d6be17

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/loader/m3u8-parser.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,34 @@ import { LevelAttributes } from '../types/level';
1717
*/
1818

1919
// https://regex101.com is your friend
20-
const MASTER_PLAYLIST_REGEX = /(?:#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)|#EXT-X-SESSION-DATA:([^\n\r]*)[\r\n]+)/g;
20+
const MASTER_PLAYLIST_REGEX = /#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)|#EXT-X-SESSION-DATA:([^\n\r]*)[\r\n]+/g;
2121
const MASTER_PLAYLIST_MEDIA_REGEX = /#EXT-X-MEDIA:(.*)/g;
2222

2323
const LEVEL_PLAYLIST_REGEX_FAST = new RegExp([
2424
/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source, // duration (#EXTINF:<duration>,<title>), group 1 => duration, group 2 => title
25-
/|(?!#)([\S+ ?]+)/.source, // segment URI, group 3 => the URI (note newline is not eaten)
26-
/|#EXT-X-BYTERANGE:*(.+)/.source, // next segment's byterange, group 4 => range spec (x@y)
27-
/|#EXT-X-PROGRAM-DATE-TIME:(.+)/.source, // next segment's program date/time group 5 => the datetime spec
28-
/|#.*/.source // All other non-segment oriented tags will match with all groups empty
29-
].join(''), 'g');
30-
31-
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-(PREFETCH-DIS)CONTINUITY)|(?:#EXT-X-(PREFETCH):(.+))|(?:#EXT-X-(VERSION):(\d+))|(?:#EXT-X-(MAP):(.+))|(?:(#)([^:]*):(.*))|(?:(#)(.*))(?:.*)\r?\n?/;
25+
/(?!#)([\S+ ?]+)/.source, // segment URI, group 3 => the URI (note newline is not eaten)
26+
/#EXT-X-BYTERANGE:*(.+)/.source, // next segment's byterange, group 4 => range spec (x@y)
27+
/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source, // next segment's program date/time group 5 => the datetime spec
28+
/#.*/.source // All other non-segment oriented tags will match with all groups empty
29+
].join('|'), 'g');
30+
31+
const LEVEL_PLAYLIST_REGEX_SLOW = new RegExp([
32+
/#(EXTM3U)/.source,
33+
/#EXT-X-(PLAYLIST-TYPE):(.+)/.source,
34+
/#EXT-X-(MEDIA-SEQUENCE): *(\d+)/.source,
35+
/#EXT-X-(TARGETDURATION): *(\d+)/.source,
36+
/#EXT-X-(KEY):(.+)/.source,
37+
/#EXT-X-(START):(.+)/.source,
38+
/#EXT-X-(ENDLIST)/.source,
39+
/#EXT-X-(DISCONTINUITY-SEQ)UENCE: *(\d+)/.source,
40+
/#EXT-X-(DIS)CONTINUITY/.source,
41+
/#EXT-X-(PREFETCH-DIS)CONTINUITY/.source, // TODO: deprecate LHLS
42+
/#EXT-X-(PREFETCH):(.+)/.source, // TODO: deprecate LHLS
43+
/#EXT-X-(VERSION):(\d+)/.source,
44+
/#EXT-X-(MAP):(.+)/.source,
45+
/(#)([^:]*):(.*)/.source,
46+
/(#)(.*)(?:.*)\r?\n?/.source
47+
].join('|'));
3248

3349
const MP4_REGEX_SUFFIX = /\.(mp4|m4s|m4v|m4a)$/i;
3450

0 commit comments

Comments
 (0)