X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-watch.ts;h=7c27c13642c5ab4880812637b332f3059dec2230;hb=46b2cec73c3ee10fe9f751a301e4afff0a56b371;hp=bf7274aab0a7262735496ae3cf080ef6ce840d9b;hpb=dc27668fceb1d0270c391c93c3bbc95d12e83218;p=github%2FChocobozzz%2FPeerTube.git 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 @@ 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') + .option('-g, --gui ', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc') + .option('-r, --resolution ', 'video resolution', '480') .on('--help', function () { console.log(' Available Players:') console.log() - console.log(' - ascii') console.log(' - mpv') console.log(' - mplayer') console.log(' - vlc') @@ -24,7 +18,6 @@ program 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() @@ -33,29 +26,25 @@ program console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10') console.log() }) - .action((url) => { - videoURL = url + .action((url, cmd) => { + run(url, cmd) + .catch(err => { + console.error(err) + process.exit(-1) + }) }) .parse(process.argv) -if (!videoURL) { - console.error(' positional argument is required.') - process.exit(-1) -} else { program['url'] = videoURL } +async function run (url: string, program: any) { + 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 = ` --${program.gui} ` + + url.replace('videos/watch', 'download/torrents') + + `-${program.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) - } + execSync(cmd + args) }