X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-watch.ts;h=3ca3e242a6dfd19d54609c6a8f76cb9da289934c;hb=71de85be3beb5f5181e6338b1a7154c8cf65afd4;hp=bf7274aab0a7262735496ae3cf080ef6ce840d9b;hpb=8704acf49efc770d73bf07c10468ed8c74d28a83;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts index bf7274aab..3ca3e242a 100644 --- a/server/tools/peertube-watch.ts +++ b/server/tools/peertube-watch.ts @@ -1,61 +1,42 @@ +import { registerTSPaths } from '../helpers/register-ts-paths' +registerTSPaths() + import * as program from 'commander' -import * as summon from 'summon-install' import { join } from 'path' import { execSync } from 'child_process' -import { root } from '../helpers/core-utils' - -let videoURL program .name('watch') .arguments('') - .option('-g, --gui ', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|ascii|xbmc)$/i, 'ascii') - .option('-i, --invert', 'invert colors (ascii player only)', true) - .option('-r, --resolution ', 'video resolution', /^(240|360|720|1080)$/i, '720') - .on('--help', function () { - console.log(' Available Players:') - console.log() - console.log(' - ascii') - 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(' Note: \'ascii\' is the only option not using WebTorrent and not seeding back the video.') - 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) => { - videoURL = url - }) + .addOption( + new program.Option('-g, --gui ', 'player type') + .default('vlc') + .choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ]) + ) + .option('-r, --resolution ', 'video resolution', '480') + .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) -if (!videoURL) { - console.error(' positional argument is required.') - process.exit(-1) -} else { program['url'] = videoURL } +function run (url: string, options: program.OptionValues) { + if (!url) { + console.error(' positional argument is required.') + process.exit(-1) + } -handler(program) + const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') + const args = ` --${options.gui} ` + + url.replace(/(\/videos\/watch\/)|\/w\//, '/download/torrents/') + + `-${options.resolution}.torrent` -function handler (argv) { - if (argv['gui'] === 'ascii') { - summon('peerterminal') - const peerterminal = summon('peerterminal') - peerterminal([ '--link', videoURL, '--invert', argv['invert'] ]) - } else { - summon('webtorrent-hybrid') - const CMD = 'node ' + join(root(), 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js') - const CMDargs = ` --${argv.gui} ` + - argv['url'].replace('videos/watch', 'download/torrents') + - `-${argv.resolution}.torrent` - execSync(CMD + CMDargs) + try { + execSync(cmd + args) + } catch (err) { + console.error('Cannto exec command.', err) + process.exit(-1) } }