Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 53 additions & 49 deletions ffbinaries-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var os = require('os');
var fse = require('fs-extra');
var path = require('path');
var _ = require('lodash');
var request = require('request');
var axios = require('axios');
var async = require('async');
var childProcess = require('child_process');
var extractZip = require('extract-zip');
Expand Down Expand Up @@ -132,23 +132,23 @@ function listVersions(callback) {
if (RUNTIME_CACHE.versionsAll) {
return callback(null, RUNTIME_CACHE.versionsAll);
}
request({ url: API_URL }, function (err, response, body) {
if (err) {
return callback(errorMsgs.connectionIssues);
}

var parsed;
axios.get(API_URL)
.then((response) => {
var parsed;

try {
parsed = JSON.parse(body.toString());
} catch (e) {
return callback(errorMsgs.parsingVersionList);
}
try {
parsed = response.data;
} catch (e) {
return callback(errorMsgs.parsingVersionList);
}

var versionsAll = Object.keys(parsed.versions);
RUNTIME_CACHE.versionsAll = versionsAll;
return callback(null, versionsAll);
});
var versionsAll = Object.keys(parsed.versions);
RUNTIME_CACHE.versionsAll = versionsAll;
return callback(null, versionsAll);
})
.catch((err) => {
console.error(err);
});
}
/**
* Gets full data set from ffbinaries.com
Expand All @@ -164,26 +164,24 @@ function getVersionData(version, callback) {

var url = version ? '/version/' + version : '/latest';

request({ url: API_URL + url }, function (err, response, body) {
if (err) {
return callback(errorMsgs.connectionIssues);
}

if (body === '404') {
return callback(errorMsgs.notFound);
}
axios.get(API_URL + url)
.then((response) => {
if (response.status === '404') {
return callback(errorMsgs.notFound);
}

var parsed;
var parsed;

try {
parsed = JSON.parse(body.toString());
} catch (e) {
return callback(errorMsgs.parsingVersionData);
}
try {
parsed = response.data;
} catch (e) {
return callback(errorMsgs.parsingVersionData);
}

RUNTIME_CACHE[version] = parsed;
return callback(null, parsed);
});
RUNTIME_CACHE[version] = parsed;
return callback(null, parsed);
})
.catch(() => callback(errorMsgs.connectionIssues));
}

/**
Expand Down Expand Up @@ -281,25 +279,31 @@ function downloadUrls(components, urls, opts, callback) {
var cacheFileTempName = zipPath + '.part';
var cacheFileFinalName = zipPath;

request({ url: url }, function () {
results.push({
filename: binFilename,
path: destinationDir,
size: Math.floor(totalFilesize / 1024 / 1024 * 1000) / 1000 + 'MB',
status: 'File extracted to destination (downloaded from "' + url + '")',
code: 'DONE_CLEAN'
});

fse.renameSync(cacheFileTempName, cacheFileFinalName);
extractZipToDestination(zipFilename, cb);
axios.get(url, {
responseType: 'arraybuffer',
onDownloadProgress: (e) => {
runningTotal = e.loaded;
}
})
.on('response', function (response) {
.then((response) => {
totalFilesize = response.headers['content-length'];

var fileData = Buffer.from(response.data, 'binary');

fse.writeFileSync(cacheFileTempName, fileData);
})
.on('data', function (data) {
runningTotal += data.length;
})
.pipe(fse.createWriteStream(cacheFileTempName));
.finally(() => {
results.push({
filename: binFilename,
path: destinationDir,
size: Math.floor(totalFilesize / 1024 / 1024 * 1000) / 1000 + 'MB',
status: 'File extracted to destination (downloaded from "' + url + '")',
code: 'DONE_CLEAN'
});

fse.renameSync(cacheFileTempName, cacheFileFinalName);
extractZipToDestination(zipFilename, cb);
});
}
}
}, function () {
Expand Down
51 changes: 42 additions & 9 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffbinaries",
"version": "1.1.6",
"version": "1.2.0",
"description": "Download binaries for ffmpeg, ffprobe, ffserver and ffplay (Windows, macOS, Linux)",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -46,6 +46,7 @@
"homepage": "https://ffbinaries.com",
"dependencies": {
"async": "^3.1.0",
"axios": "^1.6.7",
"clarg": "0.0.4",
"extract-zip": "^1.6.7",
"fs-extra": "^8.1.0",
Expand Down