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oD,EADE8C,EACSpC,YAAYxC,EAAMsF,GAAejH,QAAQ,IAEzCR,KAAK+C,MAAMkB,GAGjBA,EA7CcyD,CAAgBX,EAAS5E,EAAKgB,EAC7CyD,EACAC,GAEFxD,EAASI,KAAK,CAAEQ,SAAAA,EAAUtC,KAAAA,IAE1BkF,GAAyB5C,EACzB2C,EAAyB,EACzBjF,EAAO,QAEPyF,GAAc,EAGZA,IACFT,EAAY/E,MAITyB","sources":["webpack://goodkind-frontend/./node_modules/node-webvtt/index.js","webpack://goodkind-frontend/./node_modules/node-webvtt/lib/compiler.js","webpack://goodkind-frontend/./node_modules/node-webvtt/lib/hls.js","webpack://goodkind-frontend/./node_modules/node-webvtt/lib/parser.js","webpack://goodkind-frontend/./node_modules/node-webvtt/lib/segmenter.js"],"sourcesContent":["'use strict';\n\nconst parse = require('./lib/parser').parse;\nconst compile = require('./lib/compiler').compile;\nconst segment = require('./lib/segmenter').segment;\nconst hls = require('./lib/hls');\n\nmodule.exports = { parse, compile, segment, hls };\n","'use strict';\n\n/**\n * See spec: https://www.w3.org/TR/webvtt1/#file-structure\n */\n\nfunction CompilerError (message, error) {\n this.message = message;\n this.error = error;\n}\n\nCompilerError.prototype = Object.create(Error.prototype);\n\nfunction compile (input) {\n\n if (!input) {\n throw new CompilerError('Input must be non-null');\n }\n\n if (typeof input !== 'object') {\n throw new CompilerError('Input must be an object');\n }\n\n if (Array.isArray(input)) {\n throw new CompilerError('Input cannot be array');\n }\n\n if (!input.valid) {\n throw new CompilerError('Input must be valid');\n }\n\n let output = 'WEBVTT\\n';\n\n if (input.meta) {\n if (typeof input.meta !== 'object' || Array.isArray(input.meta)) {\n throw new CompilerError('Metadata must be an object');\n }\n\n Object.entries(input.meta).forEach((i) => {\n if (typeof i[1] !== 'string') {\n throw new CompilerError(`Metadata value for \"${i[0]}\" must be string`);\n }\n\n output += `${i[0]}: ${i[1]}\\n`;\n });\n }\n\n let lastTime = null;\n\n input.cues.forEach((cue, index) => {\n if (lastTime && lastTime > cue.start) {\n throw new CompilerError(`Cue number ${index} is not in chronological`\n + ' order');\n }\n\n lastTime = cue.start;\n\n output += '\\n';\n output += compileCue(cue);\n output += '\\n';\n });\n\n return output;\n}\n\n/**\n * Compile a single cue block.\n *\n * @param {array} cue Array of content for the cue\n *\n * @returns {object} cue Cue object with start, end, text and styles.\n * Null if it's a note\n */\nfunction compileCue (cue) {\n // TODO: check for malformed JSON\n if (typeof cue !== 'object') {\n throw new CompilerError('Cue malformed: not of type object');\n }\n\n if (typeof cue.identifier !== 'string' &&\n typeof cue.identifier !== 'number' &&\n cue.identifier !== null) {\n throw new CompilerError(`Cue malformed: identifier value is not a string.\n ${JSON.stringify(cue)}`);\n }\n\n if (isNaN(cue.start)) {\n throw new CompilerError(`Cue malformed: null start value.\n ${JSON.stringify(cue)}`);\n }\n\n if (isNaN(cue.end)) {\n throw new CompilerError(`Cue malformed: null end value.\n ${JSON.stringify(cue)}`);\n }\n\n if (cue.start >= cue.end) {\n throw new CompilerError(`Cue malformed: start timestamp greater than end\n ${JSON.stringify(cue)}`);\n }\n\n if (typeof cue.text !== 'string') {\n throw new CompilerError(`Cue malformed: null text value.\n ${JSON.stringify(cue)}`);\n }\n\n if (typeof cue.styles !== 'string') {\n throw new CompilerError(`Cue malformed: null styles value.\n ${JSON.stringify(cue)}`);\n }\n\n let output = '';\n\n if (cue.identifier.length > 0) {\n output += `${cue.identifier}\\n`;\n }\n\n const startTimestamp = convertTimestamp(cue.start);\n const endTimestamp = convertTimestamp(cue.end);\n\n output += `${startTimestamp} --> ${endTimestamp}`;\n output += cue.styles ? ` ${cue.styles}` : '';\n output += `\\n${cue.text}`;\n\n return output;\n}\n\nfunction convertTimestamp (time) {\n const hours = pad(calculateHours(time), 2);\n const minutes = pad(calculateMinutes(time), 2);\n const seconds = pad(calculateSeconds(time), 2);\n const milliseconds = pad(calculateMs(time), 3);\n return `${hours}:${minutes}:${seconds}.${milliseconds}`;\n}\n\nfunction pad (num, zeroes) {\n let output = `${num}`;\n\n while (output.length < zeroes) {\n output = `0${ output }`;\n }\n\n return output;\n}\n\nfunction calculateHours (time) {\n return Math.floor(time / 60 / 60);\n}\n\nfunction calculateMinutes (time) {\n return (Math.floor(time / 60) % 60);\n}\n\nfunction calculateSeconds (time) {\n return Math.floor((time) % 60);\n}\n\nfunction calculateMs (time) {\n return Math.floor((time % 1).toFixed(4) * 1000);\n}\n\nmodule.exports = { CompilerError, compile };\n","'use strict';\n\nconst segment = require('./segmenter').segment;\n\nfunction hlsSegment (input, segmentLength, startOffset) {\n\n if (typeof startOffset === 'undefined') {\n startOffset = '900000';\n }\n\n const segments = segment(input, segmentLength);\n\n const result = [];\n segments.forEach((seg, i) => {\n\n const content = `WEBVTT\nX-TIMESTAMP-MAP=MPEGTS:${startOffset},LOCAL:00:00:00.000\n\n${printableCues(seg.cues)}\n`;\n const filename = generateSegmentFilename(i);\n result.push({ filename, content });\n });\n return result;\n}\n\nfunction hlsSegmentPlaylist (input, segmentLength) {\n\n const segmented = segment(input, segmentLength);\n\n const printable = printableSegments(segmented);\n const longestSegment = Math.round(findLongestSegment(segmented));\n\n const template = `#EXTM3U\n#EXT-X-TARGETDURATION:${longestSegment}\n#EXT-X-VERSION:3\n#EXT-X-MEDIA-SEQUENCE:0\n#EXT-X-PLAYLIST-TYPE:VOD\n${printable}\n#EXT-X-ENDLIST\n`;\n return template;\n}\n\nfunction pad (num, n) {\n const padding = '0'.repeat(Math.max(0, n - num.toString().length));\n\n return `${padding}${num}`;\n}\n\nfunction generateSegmentFilename (index) {\n return `${index}.vtt`;\n}\n\nfunction printableSegments (segments) {\n const result = [];\n segments.forEach((seg, i) => {\n result.push(`#EXTINF:${seg.duration.toFixed(5)},\n${generateSegmentFilename(i)}`);\n });\n\n return result.join('\\n');\n}\n\nfunction findLongestSegment (segments) {\n let max = 0;\n segments.forEach((seg) => {\n if (seg.duration > max) {\n max = seg.duration;\n }\n });\n\n return max;\n}\n\nfunction printableCues (cues) {\n const result = [];\n cues.forEach((cue) => {\n result.push(printableCue(cue));\n });\n\n return result.join('\\n\\n');\n}\n\nfunction printableCue (cue) {\n const printable = [];\n\n if (cue.identifier) {\n printable.push(cue.identifier);\n }\n\n const start = printableTimestamp(cue.start);\n const end = printableTimestamp(cue.end);\n\n const styles = cue.styles ? `${cue.styles}` : '';\n\n // always add a space after end timestamp, otherwise JWPlayer will not\n // handle cues correctly\n printable.push(`${start} --> ${end} ${styles}`);\n\n printable.push(cue.text);\n\n return printable.join('\\n');\n}\n\nfunction printableTimestamp (timestamp) {\n const ms = (timestamp % 1).toFixed(3);\n timestamp = Math.round(timestamp - ms);\n const hours = Math.floor(timestamp / 3600);\n const mins = Math.floor((timestamp - (hours * 3600)) / 60);\n const secs = timestamp - (hours * 3600) - (mins * 60);\n\n // TODO hours aren't required by spec, but we include them, should be config\n const hourString = `${pad(hours, 2)}:`;\n return `${hourString}${pad(mins, 2)}:${pad(secs, 2)}.${pad(ms * 1000, 3)}`;\n}\n\nmodule.exports = { hlsSegment, hlsSegmentPlaylist };\n","'use strict';\n\n/**\n * See spec: https://www.w3.org/TR/webvtt1/#file-structure\n */\n\nfunction ParserError (message, error) {\n this.message = message;\n this.error = error;\n}\n\nParserError.prototype = Object.create(Error.prototype);\n\nconst TIMESTAMP_REGEXP = /([0-9]{1,2})?:?([0-9]{2}):([0-9]{2}\\.[0-9]{2,3})/;\n\nfunction parse (input, options) {\n if (!options) {\n options = {};\n }\n\n const { meta = false, strict = true } = options;\n\n if (typeof input !== 'string') {\n throw new ParserError('Input must be a string');\n }\n\n input = input.trim();\n input = input.replace(/\\r\\n/g, '\\n');\n input = input.replace(/\\r/g, '\\n');\n\n const parts = input.split('\\n\\n');\n const header = parts.shift();\n\n if (!header.startsWith('WEBVTT')) {\n throw new ParserError('Must start with \"WEBVTT\"');\n }\n\n const headerParts = header.split('\\n');\n\n const headerComments = headerParts[0].replace('WEBVTT', '');\n\n if (headerComments.length > 0\n && (headerComments[0] !== ' ' && headerComments[0] !== '\\t')\n ) {\n throw new ParserError('Header comment must start with space or tab');\n }\n\n // nothing of interests, return early\n if (parts.length === 0 && headerParts.length === 1) {\n return { valid: true, strict, cues: [], errors: [] };\n }\n\n if (!meta && headerParts.length > 1 && headerParts[1] !== '') {\n throw new ParserError('Missing blank line after signature');\n }\n\n const { cues, errors } = parseCues(parts, strict);\n\n if (strict && errors.length > 0) {\n throw errors[0];\n }\n\n const headerMeta = meta ? parseMeta(headerParts) : null;\n\n const result = { valid: errors.length === 0, strict, cues, errors };\n\n if (meta) {\n result.meta = headerMeta;\n }\n\n return result;\n}\n\nfunction parseMeta (headerParts) {\n const meta = {};\n headerParts.slice(1).forEach(header => {\n const splitIdx = header.indexOf(':');\n const key = header.slice(0, splitIdx).trim();\n const value = header.slice(splitIdx + 1).trim();\n meta[key] = value;\n });\n return Object.keys(meta).length > 0 ? meta : null;\n}\n\nfunction parseCues (cues, strict) {\n const errors = [];\n\n const parsedCues = cues\n .map((cue, i) => {\n try {\n return parseCue(cue, i, strict);\n } catch (e) {\n errors.push(e);\n return null;\n }\n })\n .filter(Boolean);\n\n return {\n cues: parsedCues,\n errors\n };\n}\n\n/**\n * Parse a single cue block.\n *\n * @param {array} cue Array of content for the cue\n * @param {number} i Index of cue in array\n *\n * @returns {object} cue Cue object with start, end, text and styles.\n * Null if it's a note\n */\nfunction parseCue (cue, i, strict) {\n let identifier = '';\n let start = 0;\n let end = 0.01;\n let text = '';\n let styles = '';\n\n // split and remove empty lines\n const lines = cue.split('\\n').filter(Boolean);\n\n if (lines.length > 0 && lines[0].trim().startsWith('NOTE')) {\n return null;\n }\n\n if (lines.length === 1 && !lines[0].includes('-->')) {\n throw new ParserError(`Cue identifier cannot be standalone (cue #${i})`);\n }\n\n if (lines.length > 1 &&\n !(lines[0].includes('-->') || lines[1].includes('-->'))) {\n const msg = `Cue identifier needs to be followed by timestamp (cue #${i})`;\n throw new ParserError(msg);\n }\n\n if (lines.length > 1 && lines[1].includes('-->')) {\n identifier = lines.shift();\n }\n\n const times = typeof lines[0] === 'string' && lines[0].split(' --> ');\n\n if (times.length !== 2 ||\n !validTimestamp(times[0]) ||\n !validTimestamp(times[1])) {\n\n throw new ParserError(`Invalid cue timestamp (cue #${i})`);\n }\n\n start = parseTimestamp(times[0]);\n end = parseTimestamp(times[1]);\n\n if (strict) {\n if (start > end) {\n throw new ParserError(`Start timestamp greater than end (cue #${i})`);\n }\n\n if (end <= start) {\n throw new ParserError(`End must be greater than start (cue #${i})`);\n }\n }\n\n if (!strict && end < start) {\n throw new ParserError(\n `End must be greater or equal to start when not strict (cue #${i})`\n );\n }\n\n // TODO better style validation\n styles = times[1].replace(TIMESTAMP_REGEXP, '').trim();\n\n lines.shift();\n\n text = lines.join('\\n');\n\n if (!text) {\n return false;\n }\n\n return { identifier, start, end, text, styles };\n}\n\nfunction validTimestamp (timestamp) {\n return TIMESTAMP_REGEXP.test(timestamp);\n}\n\nfunction parseTimestamp (timestamp) {\n const matches = timestamp.match(TIMESTAMP_REGEXP);\n let secs = parseFloat(matches[1] || 0) * 60 * 60; // hours\n secs += parseFloat(matches[2]) * 60; // mins\n secs += parseFloat(matches[3]);\n // secs += parseFloat(matches[4]);\n return secs;\n}\n\nmodule.exports = { ParserError, parse };\n","'use strict';\n\nconst parse = require('./parser').parse;\n\nfunction segment (input, segmentLength) {\n segmentLength = segmentLength || 10;\n\n const parsed = parse(input);\n const segments = [];\n\n let cues = [];\n let queuedCue = null;\n let currentSegmentDuration = 0;\n let totalSegmentsDuration = 0;\n\n /**\n * One pass segmenting of cues\n */\n parsed.cues.forEach((cue, i) => {\n const firstCue = i === 0;\n const lastCue = i === parsed.cues.length - 1;\n const start = cue.start;\n const end = cue.end;\n const nextStart = lastCue ? Infinity : parsed.cues[i + 1].start;\n const cueLength = firstCue ? end : end - start;\n const silence = firstCue ? 0 : (start - parsed.cues[i - 1].end);\n\n currentSegmentDuration = currentSegmentDuration + cueLength + silence;\n\n debug('------------');\n debug(`Cue #${i}, segment #${segments.length + 1}`);\n debug(`Start ${start}`);\n debug(`End ${end}`);\n debug(`Length ${cueLength}`);\n debug(`Total segment duration = ${totalSegmentsDuration}`);\n debug(`Current segment duration = ${currentSegmentDuration}`);\n debug(`Start of next = ${nextStart}`);\n\n // if there's a boundary cue queued, push and clear queue\n if (queuedCue) {\n cues.push(queuedCue);\n currentSegmentDuration += queuedCue.end - totalSegmentsDuration;\n queuedCue = null;\n }\n\n cues.push(cue);\n\n // if a cue passes a segment boundary, it appears in both\n let shouldQueue = nextStart - end < segmentLength &&\n silence < segmentLength &&\n currentSegmentDuration > segmentLength;\n\n if (shouldSegment(totalSegmentsDuration, segmentLength, nextStart,\n silence)) {\n\n const duration = segmentDuration(lastCue, end, segmentLength,\n currentSegmentDuration,\n totalSegmentsDuration);\n\n segments.push({ duration, cues });\n\n totalSegmentsDuration += duration;\n currentSegmentDuration = 0;\n cues = [];\n } else {\n shouldQueue = false;\n }\n\n if (shouldQueue) {\n queuedCue = cue;\n }\n });\n\n return segments;\n}\n\nfunction shouldSegment (total, length, nextStart, silence) {\n\n // this is stupid, but gets one case fixed...\n const x = alignToSegmentLength(silence, length);\n const nextCueIsInNextSegment = silence <= length ||\n x + total < nextStart;\n\n return nextCueIsInNextSegment && nextStart - total >= length;\n}\n\nfunction segmentDuration (lastCue, end, length, currentSegment, totalSegments) {\n let duration = length;\n\n if (currentSegment > length) {\n duration = alignToSegmentLength(currentSegment - length, length);\n }\n\n // make sure the last cue covers the whole time of the cues\n if (lastCue) {\n duration = parseFloat((end - totalSegments).toFixed(2));\n } else {\n duration = Math.round(duration);\n }\n\n return duration;\n}\n\nfunction alignToSegmentLength (n, segmentLength) {\n n += segmentLength - n % segmentLength;\n return n;\n}\n\nconst debugging = false;\n\n/* istanbul ignore next */\nfunction debug (m) {\n if (debugging) {\n console.log(m);\n }\n}\n\nmodule.exports = { segment };\n"],"names":["parse","compile","segment","hls","module","exports","CompilerError","message","error","this","convertTimestamp","time","hours","pad","Math","floor","calculateHours","minutes","calculateMinutes","seconds","calculateSeconds","milliseconds","toFixed","calculateMs","num","zeroes","output","length","prototype","Object","create","Error","input","Array","isArray","valid","meta","entries","forEach","i","lastTime","cues","cue","index","start","identifier","JSON","stringify","isNaN","end","text","styles","compileCue","n","repeat","max","toString","generateSegmentFilename","printableTimestamp","timestamp","ms","round","mins","secs","hlsSegment","segmentLength","startOffset","segments","result","seg","content","push","printable","join","printableCue","printableCues","filename","hlsSegmentPlaylist","segmented","duration","printableSegments","findLongestSegment","ParserError","TIMESTAMP_REGEXP","validTimestamp","test","parseTimestamp","matches","match","parseFloat","options","strict","parts","trim","replace","split","header","shift","startsWith","headerParts","headerComments","errors","map","lines","filter","Boolean","includes","times","parseCue","e","parseCues","headerMeta","slice","splitIdx","indexOf","key","value","keys","parseMeta","alignToSegmentLength","parsed","queuedCue","currentSegmentDuration","totalSegmentsDuration","firstCue","lastCue","nextStart","Infinity","cueLength","silence","shouldQueue","total","x","shouldSegment","currentSegment","totalSegments","segmentDuration"],"sourceRoot":""}