Skip to content

Commit

Permalink
move checkMP4Suffix to global.
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmtn authored May 29, 2018
1 parent 2ce100f commit e45b6d1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/loader/m3u8-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ const LEVEL_PLAYLIST_REGEX_FAST = new RegExp([

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?/;

const MP4_SUFFIX = /\.(mp4|m4s|m4v|m4a)$/;

function checkMP4Suffix(str) {
let re = new RegExp(MP4_SUFFIX);
if (re.test(str.toLowerCase())) {
return true;
} else {
return false;
}
}

export default class M3U8Parser {
static findGroup (groups, mediaGroupId) {
if (!groups) {
Expand Down Expand Up @@ -314,7 +325,7 @@ export default class M3U8Parser {
// this is a bit lurky but HLS really has no other way to tell us
// if the fragments are TS or MP4, except if we download them :/
// but this is to be able to handle SIDX.
if (level.fragments.every((frag) => M3U8Parser.checkMP4Suffix(frag.relurl))) {
if (level.fragments.every((frag) => checkMP4Suffix(frag.relurl))) {
logger.warn('MP4 fragments found but no init segment (probably no MAP, incomplete M3U8), trying to fetch SIDX');

frag = new Fragment();
Expand All @@ -331,14 +342,4 @@ export default class M3U8Parser {

return level;
}

static checkMP4Suffix(str) {
let strRegex = '(.mp4|.m4s|.m4v|.m4a)$';
let re = new RegExp(strRegex);
if (re.test(str.toLowerCase())) {
return true;
} else {
return false;
}
}
}

0 comments on commit e45b6d1

Please sign in to comment.