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