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