forked from konsumer/easy-ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
60 lines (52 loc) · 1.29 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var tarball = require('tarball-extract')
var request = require('request')
var fs = require('fs')
var user = 'konsumer'
var tag = '0.0.13'
var repoName = 'easy-ffmpeg'
var pkg = 'ffmpeg-' + process.platform + '.tgz'
var counter = 0
var errors = 0
function downloader () {
// if no ffmpeg and ffprobe are found installed
// we will download the one for our platform
var url = 'https://github.com/' + user + '/' + repoName + '/releases/download/' + tag + '/' + pkg
request
.get(url)
.on('error', function (err) {
throw err
})
.pipe(fs.createWriteStream(pkg))
.on('close', function () {
tarball.extractTarball(pkg, __dirname, function (err, result) {
if (err) {
throw err
}
fs.unlink(pkg, function (err) {
if (err) {
throw err
}
})
})
})
}
function checker (err, path) {
if (err) {
errors++
} else if (!err && !path) {
errors++
}
if (counter) {
// finished checking for ffmpeg and ffprobe
if (errors) {
// could not find ffmpeg and ffprobe installed, downloading
downloader()
}
} else {
counter++
}
}
// let's try to find ffmpeg and ffprobe
var ffmpeg = require('fluent-ffmpeg')()
ffmpeg._getFfmpegPath(checker)
ffmpeg._getFfprobePath(checker)