2019-10-21 17:13:07 +02:00
|
|
|
import { registerTSPaths } from '../helpers/register-ts-paths'
|
|
|
|
registerTSPaths()
|
|
|
|
|
2018-09-13 14:27:44 +02:00
|
|
|
import * as program from 'commander'
|
|
|
|
import { join } from 'path'
|
|
|
|
import { execSync } from 'child_process'
|
|
|
|
|
|
|
|
program
|
|
|
|
.name('watch')
|
|
|
|
.arguments('<url>')
|
2019-05-24 17:42:35 +02:00
|
|
|
.option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc')
|
|
|
|
.option('-r, --resolution <res>', 'video resolution', '480')
|
2018-09-13 14:27:44 +02:00
|
|
|
.on('--help', function () {
|
|
|
|
console.log(' Available Players:')
|
|
|
|
console.log()
|
|
|
|
console.log(' - mpv')
|
|
|
|
console.log(' - mplayer')
|
|
|
|
console.log(' - vlc')
|
|
|
|
console.log(' - stdout')
|
|
|
|
console.log(' - xbmc')
|
|
|
|
console.log(' - airplay')
|
|
|
|
console.log(' - chromecast')
|
|
|
|
console.log()
|
|
|
|
console.log()
|
|
|
|
console.log(' Examples:')
|
|
|
|
console.log()
|
|
|
|
console.log(' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
|
|
|
|
console.log(' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
|
|
|
|
console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
|
|
|
|
console.log()
|
|
|
|
})
|
2020-01-31 16:56:52 +01:00
|
|
|
.action((url, cmd) => run(url, cmd))
|
2018-09-13 14:27:44 +02:00
|
|
|
.parse(process.argv)
|
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
function run (url: string, program: any) {
|
2019-05-24 17:42:35 +02:00
|
|
|
if (!url) {
|
|
|
|
console.error('<url> positional argument is required.')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2019-05-24 17:42:35 +02:00
|
|
|
const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
|
|
|
|
const args = ` --${program.gui} ` +
|
|
|
|
url.replace('videos/watch', 'download/torrents') +
|
|
|
|
`-${program.resolution}.torrent`
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2019-05-24 17:42:35 +02:00
|
|
|
execSync(cmd + args)
|
2018-09-13 14:27:44 +02:00
|
|
|
}
|