]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
8704acf4 | 4 | import * as program from 'commander' |
8704acf4 RK |
5 | import { join } from 'path' |
6 | import { execSync } from 'child_process' | |
8704acf4 RK |
7 | |
8 | program | |
9 | .name('watch') | |
10 | .arguments('<url>') | |
ba5a8d89 C |
11 | .addOption( |
12 | new program.Option('-g, --gui <player>', 'player type') | |
13 | .default('vlc') | |
14 | .choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ]) | |
15 | ) | |
46b2cec7 | 16 | .option('-r, --resolution <res>', 'video resolution', '480') |
ba5a8d89 C |
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)) | |
8704acf4 RK |
23 | .parse(process.argv) |
24 | ||
ba5a8d89 | 25 | function run (url: string, options: program.OptionValues) { |
46b2cec7 C |
26 | if (!url) { |
27 | console.error('<url> positional argument is required.') | |
28 | process.exit(-1) | |
29 | } | |
8704acf4 | 30 | |
46b2cec7 | 31 | const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') |
ba5a8d89 | 32 | const args = ` --${options.gui} ` + |
46b2cec7 | 33 | url.replace('videos/watch', 'download/torrents') + |
ba5a8d89 | 34 | `-${options.resolution}.torrent` |
8704acf4 | 35 | |
a3887819 C |
36 | try { |
37 | execSync(cmd + args) | |
38 | } catch (err) { | |
39 | console.error('Cannto exec command.', err) | |
40 | process.exit(-1) | |
41 | } | |
8704acf4 | 42 | } |