2019-10-21 17:13:07 +02:00
|
|
|
import { registerTSPaths } from '../helpers/register-ts-paths'
|
|
|
|
registerTSPaths()
|
|
|
|
|
2021-06-25 17:48:27 +02:00
|
|
|
import { program, Option, OptionValues } from 'commander'
|
2018-09-13 14:27:44 +02:00
|
|
|
import { join } from 'path'
|
|
|
|
import { execSync } from 'child_process'
|
|
|
|
|
|
|
|
program
|
|
|
|
.name('watch')
|
|
|
|
.arguments('<url>')
|
2021-02-03 09:33:05 +01:00
|
|
|
.addOption(
|
2021-06-25 17:48:27 +02:00
|
|
|
new Option('-g, --gui <player>', 'player type')
|
2021-02-03 09:33:05 +01:00
|
|
|
.default('vlc')
|
|
|
|
.choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ])
|
|
|
|
)
|
2019-05-24 17:42:35 +02:00
|
|
|
.option('-r, --resolution <res>', 'video resolution', '480')
|
2021-02-03 09:33:05 +01:00
|
|
|
.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))
|
2018-09-13 14:27:44 +02:00
|
|
|
.parse(process.argv)
|
|
|
|
|
2021-06-25 17:48:27 +02:00
|
|
|
function run (url: string, options: OptionValues) {
|
2019-05-24 17:42:35 +02:00
|
|
|
if (!url) {
|
|
|
|
console.error('<url> positional argument is required.')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2019-05-24 17:42:35 +02:00
|
|
|
const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
|
2021-02-03 09:33:05 +01:00
|
|
|
const args = ` --${options.gui} ` +
|
2021-05-28 11:36:33 +02:00
|
|
|
url.replace(/(\/videos\/watch\/)|\/w\//, '/download/torrents/') +
|
2021-02-03 09:33:05 +01:00
|
|
|
`-${options.resolution}.torrent`
|
2018-09-13 14:27:44 +02:00
|
|
|
|
2020-04-14 09:09:11 +02:00
|
|
|
try {
|
|
|
|
execSync(cmd + args)
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Cannto exec command.', err)
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
2018-09-13 14:27:44 +02:00
|
|
|
}
|