Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add playlist option #168

Merged
merged 9 commits into from
Jul 15, 2021
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'},
DiegoRBaquero marked this conversation as resolved.
Show resolved Hide resolved
'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'],
DiegoRBaquero marked this conversation as resolved.
Show resolved Hide 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)))
DiegoRBaquero marked this conversation as resolved.
Show resolved Hide 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