hlsmon 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env node
  2. "use strict";
  3. var hlsmon = require('commander');
  4. hlsmon.version('0.0.0')
  5. .usage('[options] <url>')
  6. .option('-a', '--user-agent <string>', 'User-Agent')
  7. .parse(process.argv);
  8. var url = require('url');
  9. var HlsSegmentReader = require('hls-segment-reader');
  10. var src = process.argv[2];
  11. var sep = ';';
  12. function monitor(srcUrl) {
  13. var r = new HlsSegmentReader(srcUrl, { fullStream:true, withData:false });
  14. var time = 0;
  15. r.on('data', function (segmentInfo) {
  16. var meta = segmentInfo.file;
  17. var duration = segmentInfo.details.duration;
  18. console.log(meta.modified.toJSON() + sep + meta.size + sep + duration.toFixed(3) + sep + (meta.size / (duration * 1024 / 8)).toFixed(3));
  19. time += duration;
  20. });
  21. r.once('index', function() {
  22. // wait until first index is returned before attaching error listener.
  23. // this will enable initials errors to throw
  24. r.on('error', function(err) {
  25. console.error('reader error', err.stack || err);
  26. });
  27. });
  28. r.on('end', function() {
  29. if (r.index && r.index.variant) {
  30. var newUrl = url.resolve(r.baseUrl, r.index.programs['1'][0].uri);
  31. console.error('found variant index, using: ', newUrl);
  32. return monitor(newUrl);
  33. }
  34. console.error('done');
  35. });
  36. r.resume();
  37. }
  38. monitor(src);