diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-09-13 14:27:44 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2018-09-14 11:08:55 +0200 |
commit | 8704acf49efc770d73bf07c10468ed8c74d28a83 (patch) | |
tree | ffd46289fcf9a13ac4412b167e9f71dfb35753c5 /server/tools/peertube-watch.ts | |
parent | 1d9d9cfdcf3983e3fd89026bc4b5633a8abf5752 (diff) | |
download | PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.gz PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.zst PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.zip |
one cli to unite them all
Ash nazg thrakatulûk agh burzum-ishi krimpatul
- refactor import-videos to use the youtubeDL helper
- add very basic tests for the cli
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 | } | ||