]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-watch.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-watch.ts
1 import { registerTSPaths } from '../helpers/register-ts-paths'
2 registerTSPaths()
3
4 import * as program from 'commander'
5 import { join } from 'path'
6 import { execSync } from 'child_process'
7
8 program
9 .name('watch')
10 .arguments('<url>')
11 .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc')
12 .option('-r, --resolution <res>', 'video resolution', '480')
13 .on('--help', function () {
14 console.log(' Available Players:')
15 console.log()
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()
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 })
32 .action((url, cmd) => run(url, cmd))
33 .parse(process.argv)
34
35 function run (url: string, program: any) {
36 if (!url) {
37 console.error('<url> positional argument is required.')
38 process.exit(-1)
39 }
40
41 const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
42 const args = ` --${program.gui} ` +
43 url.replace('videos/watch', 'download/torrents') +
44 `-${program.resolution}.torrent`
45
46 execSync(cmd + args)
47 }