diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-20 16:24:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 16:24:49 +0200 |
commit | dc27668fceb1d0270c391c93c3bbc95d12e83218 (patch) | |
tree | ce6621597505f9518cfdf0981977d097c63f9fad /server/tools/peertube-watch.ts | |
parent | 6247b2057b792cea155a1abd9788c363ae7d2cc2 (diff) | |
parent | 0491173a61aed66205c017e0d7e0503ea316c144 (diff) | |
download | PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.tar.gz PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.tar.zst PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.zip |
Merge pull request #941 from rigelk/cli-wrapper
adding cli wrapper
Diffstat (limited to 'server/tools/peertube-watch.ts')
-rw-r--r-- | server/tools/peertube-watch.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts new file mode 100644 index 000000000..bf7274aab --- /dev/null +++ b/server/tools/peertube-watch.ts | |||
@@ -0,0 +1,61 @@ | |||
1 | import * as program from 'commander' | ||
2 | import * as summon from 'summon-install' | ||
3 | import { join } from 'path' | ||
4 | import { execSync } from 'child_process' | ||
5 | import { root } from '../helpers/core-utils' | ||
6 | |||
7 | let videoURL | ||
8 | |||
9 | program | ||
10 | .name('watch') | ||
11 | .arguments('<url>') | ||
12 | .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|ascii|xbmc)$/i, 'ascii') | ||
13 | .option('-i, --invert', 'invert colors (ascii player only)', true) | ||
14 | .option('-r, --resolution <res>', 'video resolution', /^(240|360|720|1080)$/i, '720') | ||
15 | .on('--help', function () { | ||
16 | console.log(' Available Players:') | ||
17 | console.log() | ||
18 | console.log(' - ascii') | ||
19 | console.log(' - mpv') | ||
20 | console.log(' - mplayer') | ||
21 | console.log(' - vlc') | ||
22 | console.log(' - stdout') | ||
23 | console.log(' - xbmc') | ||
24 | console.log(' - airplay') | ||
25 | console.log(' - chromecast') | ||
26 | console.log() | ||
27 | console.log(' Note: \'ascii\' is the only option not using WebTorrent and not seeding back the video.') | ||
28 | console.log() | ||
29 | console.log(' Examples:') | ||
30 | console.log() | ||
31 | console.log(' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') | ||
32 | console.log(' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') | ||
33 | console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') | ||
34 | console.log() | ||
35 | }) | ||
36 | .action((url) => { | ||
37 | videoURL = url | ||
38 | }) | ||
39 | .parse(process.argv) | ||
40 | |||
41 | if (!videoURL) { | ||
42 | console.error('<url> positional argument is required.') | ||
43 | process.exit(-1) | ||
44 | } else { program['url'] = videoURL } | ||
45 | |||
46 | handler(program) | ||
47 | |||
48 | function handler (argv) { | ||
49 | if (argv['gui'] === 'ascii') { | ||
50 | summon('peerterminal') | ||
51 | const peerterminal = summon('peerterminal') | ||
52 | peerterminal([ '--link', videoURL, '--invert', argv['invert'] ]) | ||
53 | } else { | ||
54 | summon('webtorrent-hybrid') | ||
55 | const CMD = 'node ' + join(root(), 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') | ||
56 | const CMDargs = ` --${argv.gui} ` + | ||
57 | argv['url'].replace('videos/watch', 'download/torrents') + | ||
58 | `-${argv.resolution}.torrent` | ||
59 | execSync(CMD + CMDargs) | ||
60 | } | ||
61 | } | ||