Comparing version 1.0.1 to 1.0.2
48
index.js
@@ -9,7 +9,34 @@ /*jshint node:true */ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
const ffmpeg = require("fluent-ffmpeg"); | ||
ffmpeg.setFfprobePath(process.env.FFPROBE || '/usr/bin/ffprobe'); | ||
ffmpeg.setFfmpegPath(process.env.FFMPEG || '/usr/bin/ffmpeg'); | ||
const fs = require('fs'); | ||
/** | ||
* Helper function to wrap a synchronous call to | ||
* the 'which' module that returns `null' when an | ||
* error is throw, otherwise the resulting path. | ||
* | ||
* @param {String} path | ||
* @return {String|null} | ||
*/ | ||
const which = (path) => { | ||
try { return require('which').sync(path); } | ||
catch(err) { return null; } | ||
}; | ||
/** | ||
* Set ffprobe and ffmpeg paths are resolved from environment | ||
* variables or found in path. The ffprobe and ffmpeg command | ||
* paths default to `/usr/bin/ffprobe' and `/usr/bin/ffmpeg' | ||
* respectively if not resolved. | ||
*/ | ||
ffmpeg.setFfprobePath(process.env.FFPROBE || which('ffprobe') || '/usr/bin/ffprobe'); | ||
ffmpeg.setFfmpegPath(process.env.FFMPEG || which('ffmpeg') || '/usr/bin/ffmpeg'); | ||
/** | ||
* Calculates the bpp, or bits-per-pixel for a video at a given file path. | ||
@@ -20,3 +47,3 @@ * The calculate() function calls the given callback() function with the | ||
* results. | ||
* | ||
* | ||
* @param {String} filePath - The file path for a video to calculate the bpp | ||
@@ -27,7 +54,12 @@ * @param {Function} [callback] - The callback function called with results | ||
*/ | ||
exports.calculate = (videoFile, cb) => new Promise((resolve, reject) => { | ||
// propagate `ENOENT' errors to done function | ||
try { fs.statSync(videoFile); } | ||
catch (err) { return done(err); } | ||
// propagate ffprobe errors to done function | ||
try { ffmpeg.ffprobe(videoFile, onprobe); } | ||
catch (err) { return cb(err); } | ||
catch (err) { return done(err); } | ||
// handle a given callback and promise resolution | ||
@@ -39,7 +71,7 @@ function done(err, results) { | ||
} | ||
if (err) { reject(err); } | ||
else { resolve(results); } | ||
} | ||
// handle ffprobe errors or results | ||
@@ -46,0 +78,0 @@ function onprobe(err, metadata) { |
{ | ||
"name": "bpp", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Calculate a video stream's {bits / (pixel * frame)} measurement.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test" | ||
}, | ||
@@ -12,5 +12,8 @@ "author": "Andrew Grathwohl", | ||
"dependencies": { | ||
"fluent-ffmpeg": "^2.1.0" | ||
"fluent-ffmpeg": "^2.1.0", | ||
"which": "^1.2.10" | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"tape": "^4.6.0" | ||
}, | ||
"repository": { | ||
@@ -17,0 +20,0 @@ "type": "git", |
@@ -1,13 +0,53 @@ | ||
/* jshint node:true */ | ||
/* jshint esversion:6 */ | ||
'use strict'; | ||
const b = require("../"); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const test = require('tape'); | ||
const bpp = require('../'); | ||
const a = b.calculate('./test.mp4', function(err, c) { | ||
setTimeout(function () { | ||
console.log("Actual: " + c); | ||
}, 1000); | ||
const VALID_FILE_PATH = path.resolve(__dirname, './test.mp4'); | ||
const INVALID_FILE_PATH = VALID_FILE_PATH + 'foo'; | ||
test('Invalid file (callback)', (t) => { | ||
t.plan(1) | ||
bpp.calculate(INVALID_FILE_PATH, (err, results) => { | ||
assert(err); | ||
t.pass(err.message || err); | ||
}); | ||
}); | ||
console.log("Expected: ~0.013"); | ||
test('Invalid file (Promise)', (t) => { | ||
t.plan(1); | ||
bpp.calculate(INVALID_FILE_PATH) | ||
.then(() => t.fail()) | ||
.catch((err) => { | ||
assert(err); | ||
t.pass(err.message || err); | ||
}); | ||
}); | ||
test('Valid file (callback)', (t) => { | ||
t.plan(1) | ||
bpp.calculate(VALID_FILE_PATH, (err, results) => { | ||
assert(null == err); | ||
assert(results) | ||
t.pass(); | ||
}); | ||
}); | ||
test('Valid file (Promise)', (t) => { | ||
t.plan(1); | ||
bpp.calculate(VALID_FILE_PATH) | ||
.then((results) => { | ||
assert(results) | ||
t.pass('.then(results)') | ||
}) | ||
.catch((err) => { | ||
assert(err); | ||
t.fail(err.message || err); | ||
}); | ||
}); |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
7169
115
0
2
1
3
+ Addedwhich@^1.2.10