Skip to content

Commit

Permalink
install: download and extract binary
Browse files Browse the repository at this point in the history
  • Loading branch information
jperl committed Jan 20, 2020
1 parent 9425b78 commit f692aff
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
29 changes: 15 additions & 14 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var fs = require("fs");
var get = require("simple-get");
var os = require("os");
var path = require("path");
var ProgressBar = require("progress");

var get = require("simple-get");
var tar = require("tar");
var ffmpegPath = require(".");
var pkg = require("./package");

function downloadFile(url, destinationPath, progressCallback) {
function downloadExtractFile(url, destinationPath, progressCallback) {
let fulfill, reject;
let downloadedBytes = 0;
let totalBytes = 0;
Expand All @@ -23,12 +23,17 @@ function downloadFile(url, destinationPath, progressCallback) {
return;
}

const file = fs.createWriteStream(destinationPath);
file.on("finish", () => fulfill());
file.on("error", error => reject(error));
response.pipe(file);
totalBytes = parseInt(response.headers["content-length"], 10);

response
.pipe(
tar.x({
C: path.dirname(destinationPath)
})
)
.on("finish", () => fulfill())
.on("error", error => reject(error));

if (progressCallback) {
response.on("data", function(chunk) {
downloadedBytes += chunk.length;
Expand Down Expand Up @@ -60,18 +65,14 @@ function onProgress(downloadedBytes, totalBytes) {
function getDownloadUrl() {
var platform = os.platform();
var arch = os.arch();
var name = platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
var release =
process.env.FFMPEG_BINARY_RELEASE || pkg["ffmpeg-static"]["binary_release"];
var url = `https://github.com/eugeneware/ffmpeg-static/releases/download/${release}/${platform}-${arch}-${name}`;
var url = `https://github.com/qawolf/ffmpeg-static/releases/download/${release}/${platform}-${arch}.tar.gz`;
return url;
}

if (ffmpegPath) {
downloadFile(getDownloadUrl(), ffmpegPath, onProgress).then(() => {
// make executable
fs.chmodSync(ffmpegPath, 0o755);
});
downloadExtractFile(getDownloadUrl(), ffmpegPath, onProgress);
} else {
console.error(
"ffmpeg-static install failed: No binary found for architecture"
Expand Down
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"prepublishOnly": "npm test"
},
"ffmpeg-static": {
"binary_release": "b3.0.0"
"binary_release": "b3.0.0-c1"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -49,7 +49,8 @@
},
"dependencies": {
"progress": "^2.0.3",
"simple-get": "^3.1.0"
"simple-get": "^3.1.0",
"tar": "^5.0.5"
},
"devDependencies": {
"any-shell-escape": "^0.1.1",
Expand Down

0 comments on commit f692aff

Please sign in to comment.