m3u8stream
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -1,3 +0,4 @@ | ||
const Writable = require('stream').Writable; | ||
const sax = require('sax'); | ||
const Writable = require('stream').Writable; | ||
const sax = require('sax'); | ||
const parseTime = require('./parse-time'); | ||
@@ -23,5 +24,6 @@ | ||
let timeline = []; | ||
let getSegments = false, startEmitted = false; | ||
let getSegments = false; | ||
let isStatic; | ||
let treeLevel; | ||
let periodStart; | ||
@@ -52,2 +54,3 @@ const tmpl = (str) => { | ||
treeLevel = 0; | ||
periodStart = parseTime.durationStr(node.attributes.start) || 0; | ||
break; | ||
@@ -59,9 +62,2 @@ case 'segmentlist': | ||
offset = parseInt(node.attributes.presentationtimeoffset) || offset; | ||
if (!startEmitted) { | ||
startEmitted = true; | ||
if (offset) { | ||
currtime += offset; | ||
} | ||
this.emit('starttime', currtime); | ||
} | ||
break; | ||
@@ -90,2 +86,11 @@ case 'segmenttemplate': | ||
getSegments = node.attributes.id === targetID + ''; | ||
if (getSegments) { | ||
if (periodStart) { | ||
currtime += periodStart; | ||
} | ||
if (offset) { | ||
currtime -= offset / timescale * 1000; | ||
} | ||
this.emit('starttime', currtime); | ||
} | ||
if (getSegments && segmentTemplate && timeline.length) { | ||
@@ -92,0 +97,0 @@ if (segmentTemplate.initialization) { |
@@ -30,3 +30,3 @@ const PassThrough = require('stream').PassThrough; | ||
let begin = relativeBegin ? | ||
parseTime(options.begin) : | ||
parseTime.humanStr(options.begin) : | ||
Math.max(options.begin - liveBuffer, 0) || 0; | ||
@@ -33,0 +33,0 @@ let liveBegin = Date.now() - liveBuffer; |
@@ -17,3 +17,3 @@ /** | ||
}; | ||
module.exports = (time) => { | ||
exports.humanStr = (time) => { | ||
if (typeof time === 'number') { return time; } | ||
@@ -37,1 +37,17 @@ if (numberFormat.test(time)) { return +time; } | ||
}; | ||
/** | ||
* Parses a duration string in the form of "123.456S", returns milliseconds. | ||
* | ||
* @param {string} time | ||
* @return {number} | ||
*/ | ||
exports.durationStr = (time) => { | ||
let total = 0; | ||
const r = /(\d+(?:\.\d+)?)(S|M|H)/g; | ||
let rs; | ||
while ((rs = r.exec(time)) != null) { | ||
total += +rs[1] * timeUnits[rs[2].toLowerCase()]; | ||
} | ||
return total; | ||
}; |
@@ -13,3 +13,3 @@ { | ||
], | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"repository": { | ||
@@ -16,0 +16,0 @@ "type": "git", |
@@ -6,3 +6,3 @@ # node-m3u8stream | ||
[1]: https://tools.ietf.org/html/draft-pantos-http-live-streaming-20 | ||
[2]: http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd | ||
[2]: https://dashif.org/docs/DASH-IF-IOP-v4.2-clean.pdf | ||
@@ -9,0 +9,0 @@ [![Build Status](https://secure.travis-ci.org/fent/node-m3u8stream.svg)](http://travis-ci.org/fent/node-m3u8stream) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19736
491