X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-watch.ts;h=892c9e7a695e2c024d06a201ecb03fb7f31b3fa3;hb=12152aa09ff47dc5c5a627c27030855e254e58ad;hp=5f7d1bb07d8edf5efa057baa6f402edd4456ebd9;hpb=818c449b3c34e9f324ac744120c8774e724ab25e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts index 5f7d1bb07..892c9e7a6 100644 --- a/server/tools/peertube-watch.ts +++ b/server/tools/peertube-watch.ts @@ -1,47 +1,42 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program, Option, OptionValues } from 'commander' import { join } from 'path' import { execSync } from 'child_process' program .name('watch') .arguments('') - .option('-g, --gui ', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc') + .addOption( + new Option('-g, --gui ', 'player type') + .default('vlc') + .choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ]) + ) .option('-r, --resolution ', 'video resolution', '480') - .on('--help', function () { - console.log(' Available Players:') - console.log() - console.log(' - mpv') - console.log(' - mplayer') - console.log(' - vlc') - console.log(' - stdout') - console.log(' - xbmc') - console.log(' - airplay') - console.log(' - chromecast') - console.log() - console.log() - console.log(' Examples:') - console.log() - console.log(' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') - console.log(' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') - console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') - console.log() - }) - .action((url, cmd) => run(url, cmd)) + .addHelpText('after', '\n\n Examples:\n\n' + + ' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + + ' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + + ' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' + ) + .action((url, options) => run(url, options)) .parse(process.argv) -function run (url: string, program: any) { +function run (url: string, options: OptionValues) { if (!url) { console.error(' positional argument is required.') process.exit(-1) } const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') - const args = ` --${program.gui} ` + - url.replace('videos/watch', 'download/torrents') + - `-${program.resolution}.torrent` + const args = ` --${options.gui} ` + + url.replace(/(\/videos\/watch\/)|\/w\//, '/download/torrents/') + + `-${options.resolution}.torrent` - execSync(cmd + args) + try { + execSync(cmd + args) + } catch (err) { + console.error('Cannto exec command.', err) + process.exit(-1) + } }