]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/peertube-watch.ts
Add plugin table migration table
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-watch.ts
CommitLineData
8704acf4 1import * as program from 'commander'
8704acf4
RK
2import { join } from 'path'
3import { execSync } from 'child_process'
8704acf4
RK
4
5program
6 .name('watch')
7 .arguments('<url>')
46b2cec7
C
8 .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc')
9 .option('-r, --resolution <res>', 'video resolution', '480')
8704acf4
RK
10 .on('--help', function () {
11 console.log(' Available Players:')
12 console.log()
8704acf4
RK
13 console.log(' - mpv')
14 console.log(' - mplayer')
15 console.log(' - vlc')
16 console.log(' - stdout')
17 console.log(' - xbmc')
18 console.log(' - airplay')
19 console.log(' - chromecast')
20 console.log()
8704acf4
RK
21 console.log()
22 console.log(' Examples:')
23 console.log()
24 console.log(' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
25 console.log(' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
26 console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
27 console.log()
28 })
46b2cec7
C
29 .action((url, cmd) => {
30 run(url, cmd)
31 .catch(err => {
32 console.error(err)
33 process.exit(-1)
34 })
8704acf4
RK
35 })
36 .parse(process.argv)
37
46b2cec7
C
38async function run (url: string, program: any) {
39 if (!url) {
40 console.error('<url> positional argument is required.')
41 process.exit(-1)
42 }
8704acf4 43
46b2cec7
C
44 const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
45 const args = ` --${program.gui} ` +
46 url.replace('videos/watch', 'download/torrents') +
47 `-${program.resolution}.torrent`
8704acf4 48
46b2cec7 49 execSync(cmd + args)
8704acf4 50}