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