| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/env node
- "use strict";
- var hlsmon = require('commander');
- hlsmon.version('0.0.0')
- .usage('[options] <url>')
- .option('-a', '--user-agent <string>', 'User-Agent')
- .parse(process.argv);
- var url = require('url');
- var HlsSegmentReader = require('hls-segment-reader');
- var src = process.argv[2];
- var sep = ';';
- function monitor(srcUrl) {
- var r = new HlsSegmentReader(srcUrl, { fullStream:true, withData:false });
- var contentBytes = function (segmentInfo) {
- if (segmentInfo.type === 'segment') {
- return segmentInfo.segment.details.byterange ? +segmentInfo.segment.details.byterange.length : segmentInfo.file.size;
- }
- if (segmentInfo.type === 'init') {
- return segmentInfo.init.byterange ? parseInt(segmentInfo.init.quotedString('byterange'), 10): segmentInfo.file.size;
- }
- return segmentInfo.file.size;
- };
- var time = 0;
- r.on('data', function (segmentInfo) {
- var meta = segmentInfo.file;
- var size = contentBytes(segmentInfo);
- var duration = +(segmentInfo.segment && segmentInfo.segment.details.duration);
- console.log(meta.modified.toJSON() + sep + size + sep + duration.toFixed(3) + sep + (size / (duration * 1024 / 8)).toFixed(3));
- time += duration;
- });
- r.once('index', function() {
- // wait until first index is returned before attaching error listener.
- // this will enable initials errors to throw
- r.on('error', function(err) {
- console.error('reader error', err.stack || err);
- });
- });
- r.on('end', function() {
- if (r.index && r.index.master) {
- var newUrl = url.resolve(r.baseUrl, r.index.variants[0].uri);
- console.error('found variant index, using: ', newUrl);
- return monitor(newUrl);
- }
- console.error('done');
- });
- }
- monitor(src);
|