Use vlc-command

This commit is contained in:
DC
2016-05-04 01:48:39 -07:00
parent 291ea94a10
commit 1e487a3c2a
2 changed files with 11 additions and 51 deletions

View File

@@ -4,14 +4,13 @@ module.exports = {
}
var cp = require('child_process')
var fs = require('fs')
var path = require('path')
var vlcCommand = require('vlc-command')
// Runs vlc --version. Calls back with the currently installed version of VLC
// or null if VLC is not installed. (Or 'unknown' if VLC runs and produces bad
// output, but that should never happen.)
function getInstalledVersion (cb) {
exec(['--version'], function (e, stdout, stderr) {
exec(['--version'], function (e, stdout) {
var version
if (e) {
version = null
@@ -24,59 +23,19 @@ function getInstalledVersion (cb) {
})
}
// TODO: make this its own module, to avoid duplicating code with webtorrent-cli
// Finds if VLC is installed on Mac, Windows, or Linux and runs it
function exec (args, cb) {
execOrSpawn(args, true, cb)
vlcCommand(function (err, vlcPath) {
if (err) return cb(err)
cp.execFile(vlcPath, args, cb)
})
}
// Finds if VLC is installed on Mac, Windows, or Linux.
// Uses child_process.spawn() to return a ChildProcess object
// Calls back with (err, childProcess)
function spawn (args, cb) {
execOrSpawn(args, false, cb)
}
function execOrSpawn (args, isExec, cb) {
if (process.platform === 'win32') {
var Registry = require('winreg')
var key
if (process.arch === 'x64') {
key = new Registry({
hive: Registry.HKLM,
key: '\\Software\\Wow6432Node\\VideoLAN\\VLC'
})
} else {
key = new Registry({
hive: Registry.HKLM,
key: '\\Software\\VideoLAN\\VLC'
})
}
key.get('InstallDir', function (err, item) {
if (err) return cb(err)
var vlcPath = item.value + path.sep + 'vlc'
if (isExec) cp.execFile(vlcPath, args, cb)
else cb(null, cp.spawn(vlcPath, args))
})
} else {
var macRoot = '/Applications/VLC.app/Contents/MacOS/VLC'
var macHome = (process.env.HOME || '') + root
var locations = [macRoot, macHome, '/usr/bin/vlc']
var found = false
var failed = 0
locations.forEach(function (loc) {
fs.stat(loc, function (err) {
if (err) {
if (++failed === locations.length) cb(new Error('Can\'t find VLC'))
return
}
if (found) return
found = true
if (isExec) cp.execFile(loc, args, cb)
else cb(null, cp.spawn(loc, args))
})
})
}
vlcCommand(function (err, vlcPath) {
if (err) return cb(err)
cb(null, cp.spawn(vlcPath, args))
})
}

View File

@@ -36,6 +36,7 @@
"simple-get": "^2.0.0",
"srt-to-vtt": "^1.1.1",
"virtual-dom": "^2.1.1",
"vlc-command": "^1.0.1",
"webtorrent": "0.x",
"winreg": "^1.2.0"
},