|
|
@@ -15,17 +15,29 @@ var src = process.argv[2];
|
|
|
var sep = ';';
|
|
|
|
|
|
function monitor(srcUrl) {
|
|
|
- var r = reader(srcUrl, {noData:true, keepConnection:true});
|
|
|
+ var r = reader(srcUrl, {noData:true});
|
|
|
|
|
|
var time = 0;
|
|
|
- r.on('segment', function(seqNo, duration, file) {
|
|
|
- console.log(file.modified.toJSON() + sep + file.size + sep + duration.toFixed(3) + sep + (file.size / (duration * 1024/8)).toFixed(3));
|
|
|
- // console.error('new segment at '+time.toFixed(0)+' seconds, avg bitrate (kbps):', (file.size / (duration * 1024/8)).toFixed(1));
|
|
|
- time += duration;
|
|
|
+ r.on('readable', function() {
|
|
|
+ var obj;
|
|
|
+ while (null !== (obj = r.read())) {
|
|
|
+ var meta = obj.meta;
|
|
|
+ var duration = obj.segment.duration;
|
|
|
+ console.log(meta.modified.toJSON() + sep + meta.size + sep + duration.toFixed(3) + sep + (meta.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.variant) {
|
|
|
+ if (r.index && r.index.variant) {
|
|
|
var newUrl = url.resolve(r.baseUrl, r.index.programs['1'][0].uri);
|
|
|
console.error('found variant index, using: ', newUrl)
|
|
|
return monitor(newUrl);
|