diff options
Diffstat (limited to 'server/tools/peertube-watch.ts')
-rw-r--r-- | server/tools/peertube-watch.ts | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts index b8e750a37..6d9cfa3b7 100644 --- a/server/tools/peertube-watch.ts +++ b/server/tools/peertube-watch.ts | |||
@@ -8,40 +8,30 @@ import { execSync } from 'child_process' | |||
8 | program | 8 | program |
9 | .name('watch') | 9 | .name('watch') |
10 | .arguments('<url>') | 10 | .arguments('<url>') |
11 | .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc') | 11 | .addOption( |
12 | new program.Option('-g, --gui <player>', 'player type') | ||
13 | .default('vlc') | ||
14 | .choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ]) | ||
15 | ) | ||
12 | .option('-r, --resolution <res>', 'video resolution', '480') | 16 | .option('-r, --resolution <res>', 'video resolution', '480') |
13 | .on('--help', function () { | 17 | .addHelpText('after', '\n\n Examples:\n\n' + |
14 | console.log(' Available Players:') | 18 | ' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + |
15 | console.log() | 19 | ' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + |
16 | console.log(' - mpv') | 20 | ' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' |
17 | console.log(' - mplayer') | 21 | ) |
18 | console.log(' - vlc') | 22 | .action((url, options) => run(url, options)) |
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) | 23 | .parse(process.argv) |
34 | 24 | ||
35 | function run (url: string, program: any) { | 25 | function run (url: string, options: program.OptionValues) { |
36 | if (!url) { | 26 | if (!url) { |
37 | console.error('<url> positional argument is required.') | 27 | console.error('<url> positional argument is required.') |
38 | process.exit(-1) | 28 | process.exit(-1) |
39 | } | 29 | } |
40 | 30 | ||
41 | const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') | 31 | const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') |
42 | const args = ` --${program.gui} ` + | 32 | const args = ` --${options.gui} ` + |
43 | url.replace('videos/watch', 'download/torrents') + | 33 | url.replace('videos/watch', 'download/torrents') + |
44 | `-${program.resolution}.torrent` | 34 | `-${options.resolution}.torrent` |
45 | 35 | ||
46 | try { | 36 | try { |
47 | execSync(cmd + args) | 37 | execSync(cmd + args) |