Use vlc-command
This commit is contained in:
57
main/vlc.js
57
main/vlc.js
@@ -4,14 +4,13 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cp = require('child_process')
|
var cp = require('child_process')
|
||||||
var fs = require('fs')
|
var vlcCommand = require('vlc-command')
|
||||||
var path = require('path')
|
|
||||||
|
|
||||||
// Runs vlc --version. Calls back with the currently installed version of VLC
|
// 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
|
// or null if VLC is not installed. (Or 'unknown' if VLC runs and produces bad
|
||||||
// output, but that should never happen.)
|
// output, but that should never happen.)
|
||||||
function getInstalledVersion (cb) {
|
function getInstalledVersion (cb) {
|
||||||
exec(['--version'], function (e, stdout, stderr) {
|
exec(['--version'], function (e, stdout) {
|
||||||
var version
|
var version
|
||||||
if (e) {
|
if (e) {
|
||||||
version = null
|
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) {
|
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.
|
// Finds if VLC is installed on Mac, Windows, or Linux.
|
||||||
// Uses child_process.spawn() to return a ChildProcess object
|
// Uses child_process.spawn() to return a ChildProcess object
|
||||||
// Calls back with (err, childProcess)
|
// Calls back with (err, childProcess)
|
||||||
function spawn (args, cb) {
|
function spawn (args, cb) {
|
||||||
execOrSpawn(args, false, cb)
|
vlcCommand(function (err, vlcPath) {
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
if (err) return cb(err)
|
||||||
var vlcPath = item.value + path.sep + 'vlc'
|
cb(null, cp.spawn(vlcPath, args))
|
||||||
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))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
"simple-get": "^2.0.0",
|
"simple-get": "^2.0.0",
|
||||||
"srt-to-vtt": "^1.1.1",
|
"srt-to-vtt": "^1.1.1",
|
||||||
"virtual-dom": "^2.1.1",
|
"virtual-dom": "^2.1.1",
|
||||||
|
"vlc-command": "^1.0.1",
|
||||||
"webtorrent": "0.x",
|
"webtorrent": "0.x",
|
||||||
"winreg": "^1.2.0"
|
"winreg": "^1.2.0"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user