-
Notifications
You must be signed in to change notification settings - Fork 4
/
play.js
151 lines (132 loc) · 4.19 KB
/
play.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict'
// Taken from peerflix
var path = require('path')
var proc = require('child_process')
module.exports = (player, file, subtitles) => {
if (['webplay', 'airplay'].indexOf(player) !== -1) {
return Promise.reject(new Error('Player "' + player + '" is not available in offline mode'))
}
var onTop = true
var argv = {
t: subtitles,
vlc: player === 'vlc',
airplay: player === 'airplay',
mplayer: player === 'mplayer',
smplayer: player === 'smplayer',
mpchc: player === 'mpchc',
potplayer: player === 'potplayer',
mpv: player === 'mpv',
omx: player === 'omx',
webplay: player === 'webplay',
jack: player === 'jack'
}
var VLC_ARGS = '-q ' + (onTop ? '--video-on-top' : '') + ' --play-and-exit'
var OMX_EXEC = argv.jack ? 'omxplayer -r -o local ' : 'omxplayer -r -o hdmi '
var MPLAYER_EXEC = 'mplayer ' + (onTop ? '-ontop' : '') + ' -really-quiet -noidx -loop 0 '
var SMPLAYER_EXEC = 'smplayer ' + (onTop ? '-ontop' : '')
var MPV_EXEC = 'mpv ' + (onTop ? '--ontop' : '') + ' --really-quiet --loop=no '
var MPC_HC_ARGS = '/play'
var POTPLAYER_ARGS = ''
var enc = function (s) {
return /\s/.test(s) ? JSON.stringify(s) : s
}
var localHref = enc(file)
if (argv.t) {
VLC_ARGS += ' --sub-file=' + enc(argv.t)
OMX_EXEC += ' --subtitles ' + enc(argv.t)
MPLAYER_EXEC += ' -sub ' + enc(argv.t)
SMPLAYER_EXEC += ' -sub ' + enc(argv.t)
MPV_EXEC += ' --sub-file=' + enc(argv.t)
POTPLAYER_ARGS += ' ' + enc(argv.t)
}
var registry, key
if (argv.vlc && process.platform === 'win32') {
player = 'vlc'
registry = require('windows-no-runnable').registry
if (process.arch === 'x64') {
try {
key = registry('HKLM/Software/Wow6432Node/VideoLAN/VLC')
if (!key['InstallDir']) {
throw new Error('no install dir')
}
} catch (e) {
try {
key = registry('HKLM/Software/VideoLAN/VLC')
} catch (err) {}
}
} else {
try {
key = registry('HKLM/Software/VideoLAN/VLC')
} catch (err) {
try {
key = registry('HKLM/Software/Wow6432Node/VideoLAN/VLC')
} catch (e) {}
}
}
if (key) {
var vlcPath = key['InstallDir'].value + path.sep + 'vlc'
VLC_ARGS = VLC_ARGS.split(' ')
VLC_ARGS.unshift(localHref)
proc.execFile(vlcPath, VLC_ARGS)
}
} else if (argv.mpchc && process.platform === 'win32') {
player = 'mph-hc'
registry = require('windows-no-runnable').registry
key = registry('HKCU/Software/MPC-HC/MPC-HC')
var exePath = key['ExePath']
proc.exec('"' + exePath + '" "' + localHref + '" ' + MPC_HC_ARGS)
} else if (argv.potplayer && process.platform === 'win32') {
player = 'potplayer'
registry = require('windows-no-runnable').registry
if (process.arch === 'x64')
key = registry('HKCU/Software/DAUM/PotPlayer64')
if (!key || !key['ProgramPath'])
key = registry('HKCU/Software/DAUM/PotPlayer')
if (key['ProgramPath']) {
var potplayerPath = key['ProgramPath'].value
proc.exec('"' + potplayerPath + '" "' + localHref + '" ' + POTPLAYER_ARGS)
}
} else {
if (argv.vlc) {
player = 'vlc'
var root = '/Applications/VLC.app/Contents/MacOS/VLC'
var home = (process.env.HOME || '') + root
var vlc = proc.exec('vlc ' + VLC_ARGS + ' ' + localHref + ' || ' + root + ' ' + VLC_ARGS + ' ' + localHref + ' || ' + home + ' ' + VLC_ARGS + ' ' + localHref, function (error, stdout, stderror) {
if (error) {
process.exit(0)
}
})
vlc.on('exit', function () {
if (!argv.n && argv.quit !== false) process.exit(0)
})
}
}
if (argv.omx) {
player = 'omx'
var omx = proc.exec(OMX_EXEC + ' ' + localHref)
omx.on('exit', function () {
if (!argv.n && argv.quit !== false) process.exit(0)
})
}
if (argv.mplayer) {
player = 'mplayer'
var mplayer = proc.exec(MPLAYER_EXEC + ' ' + localHref)
mplayer.on('exit', function () {
if (!argv.n && argv.quit !== false) process.exit(0)
})
}
if (argv.smplayer) {
player = 'smplayer'
var smplayer = proc.exec(SMPLAYER_EXEC + ' ' + localHref)
smplayer.on('exit', function () {
if (!argv.n && argv.quit !== false) process.exit(0)
})
}
if (argv.mpv) {
player = 'mpv'
var mpv = proc.exec(MPV_EXEC + ' ' + localHref)
mpv.on('exit', function () {
if (!argv.n && argv.quit !== false) process.exit(0)
})
}
}