Skip to content
Merged
25 changes: 18 additions & 7 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const options = {
q: { alias: 'quiet', desc: 'Don\'t show UI on stdout' },
pip: { desc: 'Enter Picture-in-Picture if supported by the player' },
verbose: { desc: 'Show torrent protocol details' },
'playlist': {desc: 'Open files in a playlist if supported by the player'},
Comment thread
DiegoRBaquero marked this conversation as resolved.
Outdated
'player-args': { desc: 'Add player specific arguments (see example)', type: 'string', requiresArg: true },
'torrent-port': { desc: 'Change the torrent seeding port', defaultDescription: 'random' },
'dht-port': { desc: 'Change the dht port', defaultDescription: 'random' },
Expand Down Expand Up @@ -80,7 +81,7 @@ const playerArgs = {
iina: ['/Applications/IINA.app/Contents/MacOS/iina-cli', '--keep-running'],
mpv: ['mpv', '--really-quiet', '--loop=no'],
mplayer: ['mplayer', '-really-quiet', '-noidx', '-loop', '0'],
smplayer: ['smplayer -close-at-end'],
smplayer: ['smplayer', '-close-at-end'],
Comment thread
DiegoRBaquero marked this conversation as resolved.
omx: [
'lxterminal', '-e',
'omxplayer', '-r',
Expand Down Expand Up @@ -387,8 +388,18 @@ function runDownload (torrentId) {
href = (argv.airplay || argv.chromecast || argv.xbmc || argv.dlna)
? `http://${networkAddress()}:${server.address().port}`
: `http://localhost:${server.address().port}`

href += `/${index}/${encodeURIComponent(torrent.files[index].name)}`
let all_hrefs = []
if (argv.playlist && (argv.mpv || argv.mplayer || argv.vlc || argv.smplayer)) {
// set the selected to the first file if not specified
if (typeof argv.select != 'number') {
index = 0
}
torrent.files.forEach((file, i) => all_hrefs.push(JSON.stringify(`${href}/${i}/${encodeURIComponent(file.name)}`)))
// set the first file to the selected index
all_hrefs = all_hrefs.slice(index, all_hrefs.length).concat(all_hrefs.slice(0, index))
} else {
href += `/${index}/${encodeURIComponent(torrent.files[index].name)}`
}

if (playerName) {
torrent.files[index].select()
Expand All @@ -404,18 +415,18 @@ function runDownload (torrentId) {
return fatalError(err)
}
playerArgs.vlc[0] = vlcCmd
openPlayer(playerArgs.vlc.concat(JSON.stringify(href)))
argv.playlist ? openPlayer(playerArgs.vlc.concat(all_hrefs)) : openPlayer(playerArgs.vlc.concat(JSON.stringify(href)))
Comment thread
DiegoRBaquero marked this conversation as resolved.
})
} else if (argv.iina) {
open(`iina://weblink?url=${href}`, { wait: true }).then(playerExit)
} else if (argv.mplayer) {
openPlayer(playerArgs.mplayer.concat(JSON.stringify(href)))
argv.playlist ? openPlayer(playerArgs.mplayer.concat(all_hrefs)) : openPlayer(playerArgs.mplayer.concat(JSON.stringify(href)))
} else if (argv.mpv) {
openPlayer(playerArgs.mpv.concat(JSON.stringify(href)))
argv.playlist ? openPlayer(playerArgs.mpv.concat(all_hrefs)) : openPlayer(playerArgs.mpv.concat(JSON.stringify(href)))
} else if (argv.omx) {
openPlayer(playerArgs.omx.concat(JSON.stringify(href)))
} else if (argv.smplayer) {
openPlayer(playerArgs.smplayer.concat(JSON.stringify(href)))
argv.playlist ? openPlayer(playerArgs.smplayer.concat(all_hrefs)) : openPlayer(playerArgs.smplayer.concat(JSON.stringify(href)))
}

function openPlayer (args) {
Expand Down