aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-watch.ts
blob: bf7274aab0a7262735496ae3cf080ef6ce840d9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as program from 'commander'
import * as summon from 'summon-install'
import { join } from 'path'
import { execSync } from 'child_process'
import { root } from '../helpers/core-utils'

let videoURL

program
  .name('watch')
  .arguments('<url>')
  .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|ascii|xbmc)$/i, 'ascii')
  .option('-i, --invert', 'invert colors (ascii player only)', true)
  .option('-r, --resolution <res>', 'video resolution', /^(240|360|720|1080)$/i, '720')
  .on('--help', function () {
    console.log('  Available Players:')
    console.log()
    console.log('    - ascii')
    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('  Note: \'ascii\' is the only option not using WebTorrent and not seeding back the video.')
    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()
  })
  .action((url) => {
    videoURL = url
  })
  .parse(process.argv)

if (!videoURL) {
  console.error('<url> positional argument is required.')
  process.exit(-1)
} else { program['url'] = videoURL }

handler(program)

function handler (argv) {
  if (argv['gui'] === 'ascii') {
    summon('peerterminal')
    const peerterminal = summon('peerterminal')
    peerterminal([ '--link', videoURL, '--invert', argv['invert'] ])
  } else {
    summon('webtorrent-hybrid')
    const CMD = 'node ' + join(root(), 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
    const CMDargs = ` --${argv.gui} ` +
                    argv['url'].replace('videos/watch', 'download/torrents') +
                    `-${argv.resolution}.torrent`
    execSync(CMD + CMDargs)
  }
}