m3u8stream
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -35,18 +35,26 @@ const PassThrough = require('stream').PassThrough; | ||
let currSegment; | ||
let bytesDownloaded = 0; | ||
const streamQueue = new Queue((segment, callback) => { | ||
currSegment = segment; | ||
segment.pipe(stream, { end: false }); | ||
segment.on('data', (chunk) => { bytesDownloaded += chunk.length; }); | ||
segment.on('end', callback); | ||
const streamQueue = new Queue((req, callback) => { | ||
currSegment = req; | ||
req.pipe(stream, { end: false }); | ||
req.on('end', callback); | ||
}, { concurrency: 1 }); | ||
let segmentNumber = 0; | ||
const requestQueue = new Queue((segmentURL, callback) => { | ||
segmentURL = urlResolve(playlistURL, segmentURL); | ||
let segment = miniget(segmentURL, requestOptions); | ||
segment.on('error', callback); | ||
streamQueue.push(segment, () => { | ||
stream.emit('progress', | ||
++segmentNumber, requestQueue.total, bytesDownloaded, segmentURL); | ||
let downloaded = 0; | ||
const requestQueue = new Queue((segment, callback) => { | ||
const segmentURL = urlResolve(playlistURL, segment.url); | ||
let req = miniget(segmentURL, requestOptions); | ||
req.on('error', callback); | ||
let size; | ||
req.on('response', (res) => { | ||
size = parseInt(res.headers['content-length']); | ||
}); | ||
streamQueue.push(req, () => { | ||
downloaded += size; | ||
stream.emit('progress', { | ||
num: ++segmentNumber, | ||
size: size, | ||
url: segment.url, | ||
duration: segment.duration, | ||
}, requestQueue.total, downloaded); | ||
callback(); | ||
@@ -110,3 +118,3 @@ }); | ||
begin = item.time; | ||
requestQueue.push(item.url, onQueuedEnd); | ||
requestQueue.push(item, onQueuedEnd); | ||
addedItems.push(item); | ||
@@ -113,0 +121,0 @@ if (isLive) { |
@@ -13,3 +13,3 @@ { | ||
], | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"repository": { | ||
@@ -16,0 +16,0 @@ "type": "git", |
@@ -43,6 +43,9 @@ # node-m3u8stream | ||
#### Event: progress | ||
* `number` - Current segment number. | ||
* `Object` - Current segment with the following fields, | ||
- `number` - number | ||
- `number` - size | ||
- `number` - duration | ||
- `string` - url | ||
* `number` - Total number of segments. | ||
* `number` - Bytes downloaded up to this point. | ||
* `string` - URL of current segment. | ||
@@ -49,0 +52,0 @@ For static non-live playlists, emitted each time a segment has finished downloading. Since total download size is unknown until all segment endpoints are hit, progress is calculated based on how many segments are available. |
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
19186
472
71