]>
Commit | Line | Data |
---|---|---|
1 | import { registerTSPaths } from '../helpers/register-ts-paths' | |
2 | registerTSPaths() | |
3 | ||
4 | import * as program from 'commander' | |
5 | import { join } from 'path' | |
6 | import { execSync } from 'child_process' | |
7 | ||
8 | program | |
9 | .name('watch') | |
10 | .arguments('<url>') | |
11 | .addOption( | |
12 | new program.Option('-g, --gui <player>', 'player type') | |
13 | .default('vlc') | |
14 | .choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ]) | |
15 | ) | |
16 | .option('-r, --resolution <res>', 'video resolution', '480') | |
17 | .addHelpText('after', '\n\n Examples:\n\n' + | |
18 | ' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + | |
19 | ' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + | |
20 | ' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' | |
21 | ) | |
22 | .action((url, options) => run(url, options)) | |
23 | .parse(process.argv) | |
24 | ||
25 | function run (url: string, options: program.OptionValues) { | |
26 | if (!url) { | |
27 | console.error('<url> positional argument is required.') | |
28 | process.exit(-1) | |
29 | } | |
30 | ||
31 | const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') | |
32 | const args = ` --${options.gui} ` + | |
33 | url.replace('videos/watch', 'download/torrents') + | |
34 | `-${options.resolution}.torrent` | |
35 | ||
36 | try { | |
37 | execSync(cmd + args) | |
38 | } catch (err) { | |
39 | console.error('Cannto exec command.', err) | |
40 | process.exit(-1) | |
41 | } | |
42 | } |