diff options
Diffstat (limited to 'server/tools/peertube-watch.ts')
-rw-r--r-- | server/tools/peertube-watch.ts | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts index bf7274aab..7c27c1364 100644 --- a/server/tools/peertube-watch.ts +++ b/server/tools/peertube-watch.ts | |||
@@ -1,21 +1,15 @@ | |||
1 | import * as program from 'commander' | 1 | import * as program from 'commander' |
2 | import * as summon from 'summon-install' | ||
3 | import { join } from 'path' | 2 | import { join } from 'path' |
4 | import { execSync } from 'child_process' | 3 | import { execSync } from 'child_process' |
5 | import { root } from '../helpers/core-utils' | ||
6 | |||
7 | let videoURL | ||
8 | 4 | ||
9 | program | 5 | program |
10 | .name('watch') | 6 | .name('watch') |
11 | .arguments('<url>') | 7 | .arguments('<url>') |
12 | .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|ascii|xbmc)$/i, 'ascii') | 8 | .option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc') |
13 | .option('-i, --invert', 'invert colors (ascii player only)', true) | 9 | .option('-r, --resolution <res>', 'video resolution', '480') |
14 | .option('-r, --resolution <res>', 'video resolution', /^(240|360|720|1080)$/i, '720') | ||
15 | .on('--help', function () { | 10 | .on('--help', function () { |
16 | console.log(' Available Players:') | 11 | console.log(' Available Players:') |
17 | console.log() | 12 | console.log() |
18 | console.log(' - ascii') | ||
19 | console.log(' - mpv') | 13 | console.log(' - mpv') |
20 | console.log(' - mplayer') | 14 | console.log(' - mplayer') |
21 | console.log(' - vlc') | 15 | console.log(' - vlc') |
@@ -24,7 +18,6 @@ program | |||
24 | console.log(' - airplay') | 18 | console.log(' - airplay') |
25 | console.log(' - chromecast') | 19 | console.log(' - chromecast') |
26 | console.log() | 20 | console.log() |
27 | console.log(' Note: \'ascii\' is the only option not using WebTorrent and not seeding back the video.') | ||
28 | console.log() | 21 | console.log() |
29 | console.log(' Examples:') | 22 | console.log(' Examples:') |
30 | console.log() | 23 | console.log() |
@@ -33,29 +26,25 @@ program | |||
33 | console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') | 26 | console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') |
34 | console.log() | 27 | console.log() |
35 | }) | 28 | }) |
36 | .action((url) => { | 29 | .action((url, cmd) => { |
37 | videoURL = url | 30 | run(url, cmd) |
31 | .catch(err => { | ||
32 | console.error(err) | ||
33 | process.exit(-1) | ||
34 | }) | ||
38 | }) | 35 | }) |
39 | .parse(process.argv) | 36 | .parse(process.argv) |
40 | 37 | ||
41 | if (!videoURL) { | 38 | async function run (url: string, program: any) { |
42 | console.error('<url> positional argument is required.') | 39 | if (!url) { |
43 | process.exit(-1) | 40 | console.error('<url> positional argument is required.') |
44 | } else { program['url'] = videoURL } | 41 | process.exit(-1) |
42 | } | ||
45 | 43 | ||
46 | handler(program) | 44 | const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') |
45 | const args = ` --${program.gui} ` + | ||
46 | url.replace('videos/watch', 'download/torrents') + | ||
47 | `-${program.resolution}.torrent` | ||
47 | 48 | ||
48 | function handler (argv) { | 49 | execSync(cmd + args) |
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 | } | 50 | } |