From 91d8ab4a041db28dd15422e5256ac559135f61da Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Sun, 21 Jul 2024 00:30:18 +0300 Subject: [PATCH] Add support for the HANDBRAKECLI_PATH environment variable. --- README.hbs | 10 ++++++++++ README.md | 10 ++++++++++ dist/index.cjs | 24 ++++++++++++++---------- examples/handbrakecli-path-env.js | 25 +++++++++++++++++++++++++ lib/config.js | 24 ++++++++++++++---------- 5 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 examples/handbrakecli-path-env.js diff --git a/README.hbs b/README.hbs index 1f1bdae..69c0b09 100644 --- a/README.hbs +++ b/README.hbs @@ -75,6 +75,16 @@ Task % done FPS Avg FPS ETA Encoding 1.07 131.76 158.12 00h21m11s ``` +## HandbrakeCLI Path + +In some situations or environments (e.g. Docker) you may need to specify a custom HandbrakeCLI path. You can either specify the path in an environment variable: + +```sh +HANDBRAKECLI_PATH="./example/HandbrakeCLI" +``` + +..or pass `HandbrakeCLIPath` as an option, programmatically. See the API documentation below for instructions. Also, see the [examples folder] for example code. + # API Reference {{#module name="handbrake-js"}} {{>body~}} diff --git a/README.md b/README.md index 16f4180..40c91fb 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,16 @@ Task % done FPS Avg FPS ETA Encoding 1.07 131.76 158.12 00h21m11s ``` +## HandbrakeCLI Path + +In some situations or environments (e.g. Docker) you may need to specify a custom HandbrakeCLI path. You can either specify the path in an environment variable: + +```sh +HANDBRAKECLI_PATH="./example/HandbrakeCLI" +``` + +..or pass `HandbrakeCLIPath` as an option, programmatically. See the API documentation below for instructions. Also, see the [examples folder] for example code. + # API Reference Handbrake for node.js. diff --git a/dist/index.cjs b/dist/index.cjs index 1533cba..002fbeb 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -20,16 +20,20 @@ const { __dirname: __dirname$1 } = getModulePaths((typeof document === 'undefine /* path to the HandbrakeCLI executable downloaded by the install script */ let HandbrakeCLIPath = null; -switch (process.platform) { - case 'darwin': - HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI'); - break - case 'win32': - HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI.exe'); - break - case 'linux': - HandbrakeCLIPath = 'HandBrakeCLI'; - break +if (process.env.HANDBRAKECLI_PATH) { + HandbrakeCLIPath = process.env.HANDBRAKECLI_PATH; +} else { + switch (process.platform) { + case 'darwin': + HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI'); + break + case 'win32': + HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI.exe'); + break + case 'linux': + HandbrakeCLIPath = 'HandBrakeCLI'; + break + } } let last = null; diff --git a/examples/handbrakecli-path-env.js b/examples/handbrakecli-path-env.js new file mode 100644 index 0000000..b2ad69f --- /dev/null +++ b/examples/handbrakecli-path-env.js @@ -0,0 +1,25 @@ +import hbjs from 'handbrake-js' +import path from 'path' +import currentModulePaths from 'current-module-paths' +const { __dirname } = currentModulePaths(import.meta.url) + +async function start () { + const options = { + input: path.resolve(__dirname, '../test/video/demo.mkv'), + output: './tmp/output.mp4', + preset: 'Very Fast 480p30' + } + + const result = await hbjs.run(options) + console.log(result) +} + +start().catch(console.error) + +/* + +Run this example with the `HANDBRAKECLI_PATH` environment variable set, e.g.: + +$ HANDBRAKECLI_PATH=./tmp/HandbrakeCLI node examples/handbrakecli-path-env.js + + */ diff --git a/lib/config.js b/lib/config.js index 1105ae2..742f7fd 100644 --- a/lib/config.js +++ b/lib/config.js @@ -5,16 +5,20 @@ const { __dirname } = currentModulePaths(import.meta.url) /* path to the HandbrakeCLI executable downloaded by the install script */ let HandbrakeCLIPath = null -switch (process.platform) { - case 'darwin': - HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI') - break - case 'win32': - HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI.exe') - break - case 'linux': - HandbrakeCLIPath = 'HandBrakeCLI' - break +if (process.env.HANDBRAKECLI_PATH) { + HandbrakeCLIPath = process.env.HANDBRAKECLI_PATH +} else { + switch (process.platform) { + case 'darwin': + HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI') + break + case 'win32': + HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI.exe') + break + case 'linux': + HandbrakeCLIPath = 'HandBrakeCLI' + break + } } export { HandbrakeCLIPath }