/*! @name m3u8-parser @version 4.5.0 @license Apache-2.0 */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window")):"function"==typeof define&&define.amd?define(["exports","global/window"],e):e((t=t||self).m3u8Parser={},t.window)}(this,function(t,e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var i=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e},a=function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var i=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(i,1),i>-1},e.trigger=function(t){var e=this.listeners[t];if(e)if(2===arguments.length)for(var i=e.length,a=0;a-1;e=this.buffer.indexOf("\n"))this.trigger("data",this.buffer.substring(0,e)),this.buffer=this.buffer.substring(e+1)},e}(a),n=function(t){for(var e,i=t.split(new RegExp('(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))')),a={},r=i.length;r--;)""!==i[r]&&((e=/([^=]*)=(.*)/.exec(i[r]).slice(1))[0]=e[0].replace(/^\s+|\s+$/g,""),e[1]=e[1].replace(/^\s+|\s+$/g,""),e[1]=e[1].replace(/^['"](.*)['"]$/g,"$1"),a[e[0]]=e[1]);return a},s=function(t){function e(){var e;return(e=t.call(this)||this).customParsers=[],e.tagMappers=[],e}i(e,t);var a=e.prototype;return a.push=function(t){var e,i,a=this;0!==(t=t.trim()).length&&("#"===t[0]?this.tagMappers.reduce(function(e,i){var a=i(t);return a===t?e:e.concat([a])},[t]).forEach(function(t){for(var r=0;r0&&(d.duration=t.duration),0===t.duration&&(d.duration=.01,this.trigger("info",{message:"updating zero segment duration to a small value"})),this.manifest.segments=g},key:function(){if(t.attributes)if("NONE"!==t.attributes.METHOD)if(t.attributes.URI){if("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"===t.attributes.KEYFORMAT){return-1===["SAMPLE-AES","SAMPLE-AES-CTR","SAMPLE-AES-CENC"].indexOf(t.attributes.METHOD)?void this.trigger("warn",{message:"invalid key method provided for Widevine"}):("SAMPLE-AES-CENC"===t.attributes.METHOD&&this.trigger("warn",{message:"SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead"}),"data:text/plain;base64,"!==t.attributes.URI.substring(0,23)?void this.trigger("warn",{message:"invalid key URI provided for Widevine"}):t.attributes.KEYID&&"0x"===t.attributes.KEYID.substring(0,2)?void(this.manifest.contentProtection={"com.widevine.alpha":{attributes:{schemeIdUri:t.attributes.KEYFORMAT,keyId:t.attributes.KEYID.substring(2)},pssh:c(t.attributes.URI.split(",")[1])}}):void this.trigger("warn",{message:"invalid key ID provided for Widevine"}))}t.attributes.METHOD||this.trigger("warn",{message:"defaulting key method to AES-128"}),a={method:t.attributes.METHOD||"AES-128",uri:t.attributes.URI},void 0!==t.attributes.IV&&(a.iv=t.attributes.IV)}else this.trigger("warn",{message:"ignoring key declaration without URI"});else a=null;else this.trigger("warn",{message:"ignoring key declaration without attribute list"})},"media-sequence":function(){isFinite(t.number)?this.manifest.mediaSequence=t.number:this.trigger("warn",{message:"ignoring invalid media sequence: "+t.number})},"discontinuity-sequence":function(){isFinite(t.number)?(this.manifest.discontinuitySequence=t.number,l=t.number):this.trigger("warn",{message:"ignoring invalid discontinuity sequence: "+t.number})},"playlist-type":function(){/VOD|EVENT/.test(t.playlistType)?this.manifest.playlistType=t.playlistType:this.trigger("warn",{message:"ignoring unknown playlist type: "+t.playlist})},map:function(){i={},t.uri&&(i.uri=t.uri),t.byterange&&(i.byterange=t.byterange)},"stream-inf":function(){this.manifest.playlists=g,this.manifest.mediaGroups=this.manifest.mediaGroups||p,t.attributes?(d.attributes||(d.attributes={}),u(d.attributes,t.attributes)):this.trigger("warn",{message:"ignoring empty stream-inf attributes"})},media:function(){if(this.manifest.mediaGroups=this.manifest.mediaGroups||p,t.attributes&&t.attributes.TYPE&&t.attributes["GROUP-ID"]&&t.attributes.NAME){var i=this.manifest.mediaGroups[t.attributes.TYPE];i[t.attributes["GROUP-ID"]]=i[t.attributes["GROUP-ID"]]||{},e=i[t.attributes["GROUP-ID"]],(r={default:/yes/i.test(t.attributes.DEFAULT)}).default?r.autoselect=!0:r.autoselect=/yes/i.test(t.attributes.AUTOSELECT),t.attributes.LANGUAGE&&(r.language=t.attributes.LANGUAGE),t.attributes.URI&&(r.uri=t.attributes.URI),t.attributes["INSTREAM-ID"]&&(r.instreamId=t.attributes["INSTREAM-ID"]),t.attributes.CHARACTERISTICS&&(r.characteristics=t.attributes.CHARACTERISTICS),t.attributes.FORCED&&(r.forced=/yes/i.test(t.attributes.FORCED)),e[t.attributes.NAME]=r}else this.trigger("warn",{message:"ignoring incomplete or missing media group"})},discontinuity:function(){l+=1,d.discontinuity=!0,this.manifest.discontinuityStarts.push(g.length)},"program-date-time":function(){void 0===this.manifest.dateTimeString&&(this.manifest.dateTimeString=t.dateTimeString,this.manifest.dateTimeObject=t.dateTimeObject),d.dateTimeString=t.dateTimeString,d.dateTimeObject=t.dateTimeObject},targetduration:function(){!isFinite(t.duration)||t.duration<0?this.trigger("warn",{message:"ignoring invalid target duration: "+t.duration}):this.manifest.targetDuration=t.duration},totalduration:function(){!isFinite(t.duration)||t.duration<0?this.trigger("warn",{message:"ignoring invalid total duration: "+t.duration}):this.manifest.totalDuration=t.duration},start:function(){t.attributes&&!isNaN(t.attributes["TIME-OFFSET"])?this.manifest.start={timeOffset:t.attributes["TIME-OFFSET"],precise:t.attributes.PRECISE}:this.trigger("warn",{message:"ignoring start declaration without appropriate attribute list"})},"cue-out":function(){d.cueOut=t.data},"cue-out-cont":function(){d.cueOutCont=t.data},"cue-in":function(){d.cueIn=t.data}}[t.tagType]||f).call(n)},uri:function(){d.uri=t.uri,g.push(d),!this.manifest.targetDuration||"duration"in d||(this.trigger("warn",{message:"defaulting segment duration to the target duration"}),d.duration=this.manifest.targetDuration),a&&(d.key=a),d.timeline=l,i&&(d.map=i),d={}},comment:function(){},custom:function(){t.segment?(d.custom=d.custom||{},d.custom[t.customType]=t.data):(this.manifest.custom=this.manifest.custom||{},this.manifest.custom[t.customType]=t.data)}})[t.type].call(n)}),e}i(e,t);var a=e.prototype;return a.push=function(t){this.lineStream.push(t)},a.end=function(){this.lineStream.push("\n")},a.addParser=function(t){this.parseStream.addParser(t)},a.addTagMapper=function(t){this.parseStream.addTagMapper(t)},e}(a);t.LineStream=r,t.ParseStream=s,t.Parser=p,Object.defineProperty(t,"__esModule",{value:!0})});