Socket
Socket
Sign inDemoInstall

m3u8stream

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m3u8stream - npm Package Compare versions

Comparing version 0.8.3 to 0.8.4

22

dist/dash-mpd-parser.js

@@ -34,5 +34,5 @@ "use strict";

};
return str.replace(/\$(\w+)\$/g, (m, p1) => context[p1] + '');
return str.replace(/\$(\w+)\$/g, (m, p1) => `${context[p1]}`);
};
this._parser.on('opentag', (node) => {
this._parser.on('opentag', node => {
switch (node.name) {

@@ -80,6 +80,6 @@ case 'mpd':

treeLevel++;
if (targetID == null) {
if (!targetID) {
targetID = node.attributes.id;
}
getSegments = node.attributes.id === targetID + '';
getSegments = node.attributes.id === `${targetID}`;
if (getSegments) {

@@ -109,3 +109,3 @@ if (periodStart) {

let tl = timeline.shift();
let segmentDuration = (tl && tl.duration || duration) / timescale * 1000;
let segmentDuration = ((tl === null || tl === void 0 ? void 0 : tl.duration) || duration) / timescale * 1000;
this.emit('item', {

@@ -132,3 +132,3 @@ url: baseURL.filter(s => !!s).join('') + node.attributes.media,

};
this._parser.on('closetag', (tagName) => {
this._parser.on('closetag', tagName => {
switch (tagName) {

@@ -149,4 +149,4 @@ case 'adaptationset':

}
for (let { duration, repeat, time } of timeline) {
duration = duration / timescale * 1000;
for (let { duration: itemDuration, repeat, time } of timeline) {
itemDuration = itemDuration / timescale * 1000;
repeat = repeat || 1;

@@ -159,5 +159,5 @@ currtime = time || currtime;

seq: seq++,
duration,
duration: itemDuration,
});
currtime += duration;
currtime += itemDuration;
}

@@ -175,3 +175,3 @@ }

});
this._parser.on('text', (text) => {
this._parser.on('text', text => {
if (lastTag === 'baseurl') {

@@ -178,0 +178,0 @@ baseURL[treeLevel] = text;

@@ -25,3 +25,3 @@ /// <reference types="node" />

}
interface m3u8stream {
interface m3u8streamFunc {
(playlistURL: string, options?: m3u8stream.Options): Stream;

@@ -31,3 +31,3 @@ parseTimestamp(time: number | string): number;

}
declare let m3u8stream: m3u8stream.m3u8stream;
declare let m3u8stream: m3u8stream.m3u8streamFunc;
export = m3u8stream;

@@ -6,10 +6,9 @@ "use strict";

const stream_1 = require("stream");
const url_1 = require("url");
const miniget_1 = __importDefault(require("miniget"));
const m3u8_parser_1 = __importDefault(require("./m3u8-parser"));
const dash_mpd_parser_1 = __importDefault(require("./dash-mpd-parser"));
const queue_1 = __importDefault(require("./queue"));
const queue_1 = require("./queue");
const parse_time_1 = require("./parse-time");
const supportedParsers = {
'm3u8': m3u8_parser_1.default,
m3u8: m3u8_parser_1.default,
'dash-mpd': dash_mpd_parser_1.default,

@@ -20,3 +19,4 @@ };

const chunkReadahead = options.chunkReadahead || 3;
const liveBuffer = options.liveBuffer || 20000; // 20 seconds
// 20 seconds.
const liveBuffer = options.liveBuffer || 20000;
const requestOptions = options.requestOptions;

@@ -39,3 +39,3 @@ const Parser = supportedParsers[options.parser || (/\.mpd$/.test(playlistURL) ? 'dash-mpd' : 'm3u8')];

let currSegment;
const streamQueue = new queue_1.default((req, callback) => {
const streamQueue = new queue_1.Queue((req, callback) => {
currSegment = req;

@@ -47,17 +47,17 @@ // Count the size manually, since the `content-length` header is not

req.pipe(stream, { end: false });
req.on('end', () => callback(undefined, size));
req.on('end', () => callback(null, size));
}, { concurrency: 1 });
let segmentNumber = 0;
let downloaded = 0;
const requestQueue = new queue_1.default((segment, callback) => {
let options = Object.assign({}, requestOptions);
const requestQueue = new queue_1.Queue((segment, callback) => {
let reqOptions = Object.assign({}, requestOptions);
if (segment.range) {
options.headers = Object.assign({}, options.headers, {
reqOptions.headers = Object.assign({}, reqOptions.headers, {
Range: `bytes=${segment.range.start}-${segment.range.end}`,
});
}
let req = miniget_1.default(url_1.resolve(playlistURL, segment.url), options);
let req = miniget_1.default(new URL(segment.url, playlistURL).toString(), reqOptions);
req.on('error', callback);
forwardEvents(req);
streamQueue.push(req, (err, size) => {
streamQueue.push(req, (_, size) => {
downloaded += +size;

@@ -70,3 +70,3 @@ stream.emit('progress', {

}, requestQueue.total, downloaded);
callback();
callback(null);
});

@@ -150,3 +150,4 @@ }, { concurrency: chunkReadahead });

tailedItemsDuration - tailedItems[0].duration > liveBuffer) {
tailedItemsDuration -= tailedItems.shift().duration;
const lastItem = tailedItems.shift();
tailedItemsDuration -= lastItem.duration;
}

@@ -161,3 +162,3 @@ }

if (!addedItems.length && tailedItems.length) {
tailedItems.forEach((item) => { addItem(item); });
tailedItems.forEach(item => { addItem(item); });
}

@@ -169,5 +170,5 @@ // Refresh the playlist when remaining segments get low.

minRefreshTime =
addedItems.reduce(((total, item) => item.duration + total), 0);
addedItems.reduce((total, item) => item.duration + total, 0);
fetchingPlaylist = false;
onQueuedEnd();
onQueuedEnd(null);
});

@@ -174,0 +175,0 @@ };

@@ -14,11 +14,6 @@ /// <reference types="node" />

constructor();
_parseAttrList(value: string): {
[key: string]: string;
};
_parseRange(value: string): {
start: number;
end: number;
};
private _parseAttrList;
private _parseRange;
_parseLine(line: string): void;
_write(chunk: Buffer, encoding: string, callback: () => void): void;
}

@@ -24,3 +24,3 @@ "use strict";

let match;
while ((match = regex.exec(value)) != null) {
while ((match = regex.exec(value)) !== null) {
attrs[match[1]] = match[2] || match[3];

@@ -27,0 +27,0 @@ }

@@ -0,5 +1,16 @@

/**
* Converts human friendly time to milliseconds. Supports the format
* 00:00:00.000 for hours, minutes, seconds, and milliseconds respectively.
* And 0ms, 0s, 0m, 0h, and together 1m1s.
*
* @param {number|string} time
* @returns {number}
*/
export declare const humanStr: (time: number | string) => number;
/**
* Parses a duration string in the form of "123.456S", returns milliseconds.
*
* @param {string} time
* @returns {number}
*/
export declare const durationStr: (time: string) => number;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.durationStr = exports.humanStr = void 0;
/**
* Converts human friendly time to milliseconds. Supports the format
* 00:00:00.000 for hours, minutes, seconds, and milliseconds respectively.
* And 0ms, 0s, 0m, 0h, and together 1m1s.
*/
const numberFormat = /^\d+$/;

@@ -17,2 +12,10 @@ const timeFormat = /^(?:(?:(\d+):)?(\d{1,2}):)?(\d{1,2})(?:\.(\d{3}))?$/;

};
/**
* Converts human friendly time to milliseconds. Supports the format
* 00:00:00.000 for hours, minutes, seconds, and milliseconds respectively.
* And 0ms, 0s, 0m, 0h, and together 1m1s.
*
* @param {number|string} time
* @returns {number}
*/
exports.humanStr = (time) => {

@@ -27,5 +30,5 @@ if (typeof time === 'number') {

if (firstFormat) {
return +(firstFormat[1] || 0) * timeUnits.h +
+(firstFormat[2] || 0) * timeUnits.m +
+firstFormat[3] * timeUnits.s +
return (+(firstFormat[1] || 0) * timeUnits.h) +
(+(firstFormat[2] || 0) * timeUnits.m) +
(+firstFormat[3] * timeUnits.s) +
+(firstFormat[4] || 0);

@@ -37,3 +40,3 @@ }

let rs;
while ((rs = r.exec(time)) != null) {
while ((rs = r.exec(time)) !== null) {
total += +rs[1] * timeUnits[rs[2]];

@@ -46,2 +49,5 @@ }

* Parses a duration string in the form of "123.456S", returns milliseconds.
*
* @param {string} time
* @returns {number}
*/

@@ -52,3 +58,3 @@ exports.durationStr = (time) => {

let rs;
while ((rs = r.exec(time)) != null) {
while ((rs = r.exec(time)) !== null) {
total += +rs[1] * timeUnits[rs[2].toLowerCase()];

@@ -55,0 +61,0 @@ }

@@ -1,10 +0,11 @@

declare type Callback = (err?: Error, result?: any) => void;
interface Task {
item: {};
callback: Callback;
export declare type Callback = (err: Error | null, result?: any) => void;
interface Task<T> {
item: T;
callback?: Callback;
}
export default class Queue {
_worker: (item: any, cb: Callback) => void;
_concurrency: number;
tasks: Task[];
declare type Worker<T> = (item: T, cb: Callback) => void;
export declare class Queue<T = unknown> {
private _worker;
private _concurrency;
tasks: Task<T>[];
total: number;

@@ -14,4 +15,8 @@ active: number;

* A really simple queue with concurrency.
*
* @param {Function} worker
* @param {Object} options
* @param {!number} options.concurrency
*/
constructor(worker: (item: any, cb: Callback) => void, options?: {
constructor(worker: Worker<T>, options?: {
concurrency?: number;

@@ -21,4 +26,7 @@ });

* Push a task to the queue.
*
* @param {T} item
* @param {!Function} callback
*/
push(item: any, callback?: Callback): void;
push(item: T, callback?: Callback): void;
/**

@@ -25,0 +33,0 @@ * Process next job in queue.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Queue = void 0;
class Queue {
/**
* A really simple queue with concurrency.
*
* @param {Function} worker
* @param {Object} options
* @param {!number} options.concurrency
*/

@@ -16,2 +21,5 @@ constructor(worker, options = {}) {

* Push a task to the queue.
*
* @param {T} item
* @param {!Function} callback
*/

@@ -39,5 +47,3 @@ push(item, callback) {

callbackCalled = true;
if (callback) {
callback(err, result);
}
callback === null || callback === void 0 ? void 0 : callback(err, result);
this._next();

@@ -53,3 +59,3 @@ });

}
exports.default = Queue;
exports.Queue = Queue;
//# sourceMappingURL=queue.js.map

@@ -13,3 +13,3 @@ {

],
"version": "0.8.3",
"version": "0.8.4",
"repository": {

@@ -28,3 +28,5 @@ "type": "git",

"test": "nyc --extension .ts --reporter=lcov --reporter=text-summary npm run test:unit",
"test:unit": "mocha -- --require ts-node/register test/*-test.ts"
"test:unit": "mocha -- --require ts-node/register test/*-test.ts",
"lint": "eslint ./src ./test",
"lint:fix": "eslint --fix ./src ./test"
},

@@ -40,2 +42,5 @@ "dependencies": {

"@types/sinon": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"eslint": "^7.14.0",
"mocha": "^7.0.1",

@@ -42,0 +47,0 @@ "nock": "^13.0.5",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc