forked from SavageCore/node-ffprobe-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (61 loc) · 2.2 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
const os = require('os');
const path = require('path');
const verifyFile = require('./lib/verify-file');
let platform = os.platform();
let arch = os.arch();
if (arch === 'arm') {
var archspec = require('child_process').execSync(
'dpkg --print-architecture').toString();
if (archspec.replace(/(\r\n|\n|\r)/gm, "") !== 'armhf') {
console.log('archspec: ', archspec.replace(/(\r\n|\n|\r)/gm, ""))
throw new Error('Unsupported platform/architecture: ' + `${platform}-${arch}`);
} else {
arch = archspec.replace(/(\r\n|\n|\r)/gm, "");
}
}
platform = `${platform}-${arch}`;
let packageName = ''
packageName = `@ffprobe-installer/${platform}`;
if (arch === 'armhf') {
packageName = 'linux-armhf-bin'
} else {
console.log(arch)
}
if (!require('./package.json').optionalDependencies[packageName]) {
throw new Error('Unsupported platform/architecture: ' + platform);
}
const binary = os.platform() === 'win32' ? 'ffprobe.exe' : 'ffprobe';
if (arch === 'armhf') {
var npm3Path = path.resolve(__dirname, '..', platform);
var npm2Path = path.resolve(__dirname, 'node_modules', '@ffprobe-installer', 'ffprobe', 'node_modules', packageName);
var npm3Binary = path.join(npm3Path, binary);
var npm2Binary = path.join(npm2Path, binary);
var npm3Package = path.join(npm3Path, 'package.json');
var npm2Package = path.join(npm2Path, 'package.json');
} else {
var npm3Path = path.resolve(__dirname, '..', platform);
var npm2Path = path.resolve(__dirname, 'node_modules', '@ffprobe-installer', platform);
var npm3Binary = path.join(npm3Path, binary);
var npm2Binary = path.join(npm2Path, binary);
var npm3Package = path.join(npm3Path, 'package.json');
var npm2Package = path.join(npm2Path, 'package.json');
}
var ffprobePath;
var packageJson;
if (verifyFile(npm3Binary)) {
ffprobePath = npm3Binary;
packageJson = require(npm3Package);
} else if (verifyFile(npm2Binary)) {
ffprobePath = npm2Binary;
packageJson = require(npm2Package);
} else {
throw new Error('Could not find ffprobe executable, tried "' + npm3Binary + '" and "' + npm2Binary + '"');
}
const version = packageJson.ffprobe || packageJson.version;
const url = packageJson.homepage;
module.exports = {
path: ffprobePath,
version,
url
};