mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Update server dependencies
This commit is contained in:
@@ -69,23 +69,25 @@ function deleteSettings () {
|
||||
}
|
||||
|
||||
function getRemoteObjectOrDie (
|
||||
program: any,
|
||||
program: CommanderStatic,
|
||||
settings: Settings,
|
||||
netrc: Netrc
|
||||
): { url: string, username: string, password: string } {
|
||||
if (!program['url'] || !program['username'] || !program['password']) {
|
||||
const options = program.opts()
|
||||
|
||||
if (!options.url || !options.username || !options.password) {
|
||||
// No remote and we don't have program parameters: quit
|
||||
if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) {
|
||||
if (!program['url']) console.error('--url field is required.')
|
||||
if (!program['username']) console.error('--username field is required.')
|
||||
if (!program['password']) console.error('--password field is required.')
|
||||
if (!options.url) console.error('--url field is required.')
|
||||
if (!options.username) console.error('--username field is required.')
|
||||
if (!options.password) console.error('--password field is required.')
|
||||
|
||||
return process.exit(-1)
|
||||
}
|
||||
|
||||
let url: string = program['url']
|
||||
let username: string = program['username']
|
||||
let password: string = program['password']
|
||||
let url: string = options.url
|
||||
let username: string = options.username
|
||||
let password: string = options.password
|
||||
|
||||
if (!url && settings.default !== -1) url = settings.remotes[settings.default]
|
||||
|
||||
@@ -98,9 +100,9 @@ function getRemoteObjectOrDie (
|
||||
}
|
||||
|
||||
return {
|
||||
url: program['url'],
|
||||
username: program['username'],
|
||||
password: program['password']
|
||||
url: options.url,
|
||||
username: options.username,
|
||||
password: options.password
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +129,8 @@ function buildCommonVideoOptions (command: CommanderStatic) {
|
||||
}
|
||||
|
||||
async function buildVideoAttributesFromCommander (url: string, command: CommanderStatic, defaultAttributes: any = {}) {
|
||||
const options = command.opts()
|
||||
|
||||
const defaultBooleanAttributes = {
|
||||
nsfw: false,
|
||||
commentsEnabled: true,
|
||||
@@ -137,8 +141,8 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande
|
||||
const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {}
|
||||
|
||||
for (const key of Object.keys(defaultBooleanAttributes)) {
|
||||
if (command[key] !== undefined) {
|
||||
booleanAttributes[key] = command[key]
|
||||
if (options[key] !== undefined) {
|
||||
booleanAttributes[key] = options[key]
|
||||
} else if (defaultAttributes[key] !== undefined) {
|
||||
booleanAttributes[key] = defaultAttributes[key]
|
||||
} else {
|
||||
@@ -147,20 +151,20 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande
|
||||
}
|
||||
|
||||
const videoAttributes = {
|
||||
name: command['videoName'] || defaultAttributes.name,
|
||||
category: command['category'] || defaultAttributes.category || undefined,
|
||||
licence: command['licence'] || defaultAttributes.licence || undefined,
|
||||
language: command['language'] || defaultAttributes.language || undefined,
|
||||
privacy: command['privacy'] || defaultAttributes.privacy || VideoPrivacy.PUBLIC,
|
||||
support: command['support'] || defaultAttributes.support || undefined,
|
||||
description: command['videoDescription'] || defaultAttributes.description || undefined,
|
||||
tags: command['tags'] || defaultAttributes.tags || undefined
|
||||
name: options.videoName || defaultAttributes.name,
|
||||
category: options.category || defaultAttributes.category || undefined,
|
||||
licence: options.licence || defaultAttributes.licence || undefined,
|
||||
language: options.language || defaultAttributes.language || undefined,
|
||||
privacy: options.privacy || defaultAttributes.privacy || VideoPrivacy.PUBLIC,
|
||||
support: options.support || defaultAttributes.support || undefined,
|
||||
description: options.videoDescription || defaultAttributes.description || undefined,
|
||||
tags: options.tags || defaultAttributes.tags || undefined
|
||||
}
|
||||
|
||||
Object.assign(videoAttributes, booleanAttributes)
|
||||
|
||||
if (command['channelName']) {
|
||||
const res = await getVideoChannel(url, command['channelName'])
|
||||
if (options.channelName) {
|
||||
const res = await getVideoChannel(url, options.channelName)
|
||||
const videoChannel: VideoChannel = res.body
|
||||
|
||||
Object.assign(videoAttributes, { channelId: videoChannel.id })
|
||||
@@ -173,7 +177,7 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande
|
||||
return videoAttributes
|
||||
}
|
||||
|
||||
function getServerCredentials (program: any) {
|
||||
function getServerCredentials (program: CommanderStatic) {
|
||||
return Promise.all([ getSettings(), getNetrc() ])
|
||||
.then(([ settings, netrc ]) => {
|
||||
return getRemoteObjectOrDie(program, settings, netrc)
|
||||
|
||||
@@ -66,7 +66,8 @@ program
|
||||
.option('-U, --username <username>', 'Username')
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('--default', 'add the entry as the new default')
|
||||
.action(options => {
|
||||
.action((options: program.OptionValues) => {
|
||||
/* eslint-disable no-import-assign */
|
||||
prompt.override = options
|
||||
prompt.start()
|
||||
prompt.get({
|
||||
@@ -102,7 +103,7 @@ program
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
await setInstance(result.url, result.username, result.password, program['default'])
|
||||
await setInstance(result.url, result.username, result.password, options.default)
|
||||
|
||||
process.exit(0)
|
||||
})
|
||||
@@ -160,15 +161,12 @@ program
|
||||
}
|
||||
})
|
||||
|
||||
program.on('--help', function () {
|
||||
console.log(' Examples:')
|
||||
console.log()
|
||||
console.log(' $ peertube auth add -u https://peertube.cpy.re -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"')
|
||||
console.log(' $ peertube auth add -u https://peertube.cpy.re -U root')
|
||||
console.log(' $ peertube auth list')
|
||||
console.log(' $ peertube auth del https://peertube.cpy.re')
|
||||
console.log()
|
||||
})
|
||||
program.addHelpText('after', '\n\n Examples:\n\n' +
|
||||
' $ peertube auth add -u https://peertube.cpy.re -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"\n' +
|
||||
' $ peertube auth add -u https://peertube.cpy.re -U root\n' +
|
||||
' $ peertube auth list\n' +
|
||||
' $ peertube auth del https://peertube.cpy.re\n'
|
||||
)
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
program.outputHelp()
|
||||
|
||||
@@ -10,25 +10,27 @@ program
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.parse(process.argv)
|
||||
|
||||
const options = program.opts()
|
||||
|
||||
if (
|
||||
!program['url'] ||
|
||||
!program['username'] ||
|
||||
!program['password']
|
||||
!options.url ||
|
||||
!options.username ||
|
||||
!options.password
|
||||
) {
|
||||
if (!program['url']) console.error('--url field is required.')
|
||||
if (!program['username']) console.error('--username field is required.')
|
||||
if (!program['password']) console.error('--password field is required.')
|
||||
if (!options.url) console.error('--url field is required.')
|
||||
if (!options.username) console.error('--username field is required.')
|
||||
if (!options.password) console.error('--password field is required.')
|
||||
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
getClient(program.url)
|
||||
getClient(options.url)
|
||||
.then(res => {
|
||||
const server = {
|
||||
url: program['url'],
|
||||
url: options.url,
|
||||
user: {
|
||||
username: program['username'],
|
||||
password: program['password']
|
||||
username: options.username,
|
||||
password: options.password
|
||||
},
|
||||
client: {
|
||||
id: res.body.client_id,
|
||||
|
||||
@@ -45,22 +45,24 @@ command
|
||||
.usage("[global options] [ -- youtube-dl options]")
|
||||
.parse(process.argv)
|
||||
|
||||
const log = getLogger(program['verbose'])
|
||||
const options = command.opts()
|
||||
|
||||
const log = getLogger(options.verbose)
|
||||
|
||||
getServerCredentials(command)
|
||||
.then(({ url, username, password }) => {
|
||||
if (!program['targetUrl']) {
|
||||
if (!options.targetUrl) {
|
||||
exitError('--target-url field is required.')
|
||||
}
|
||||
|
||||
try {
|
||||
accessSync(program['tmpdir'], constants.R_OK | constants.W_OK)
|
||||
accessSync(options.tmpdir, constants.R_OK | constants.W_OK)
|
||||
} catch (e) {
|
||||
exitError('--tmpdir %s: directory does not exist or is not accessible', program['tmpdir'])
|
||||
exitError('--tmpdir %s: directory does not exist or is not accessible', options.tmpdir)
|
||||
}
|
||||
|
||||
url = normalizeTargetUrl(url)
|
||||
program['targetUrl'] = normalizeTargetUrl(program['targetUrl'])
|
||||
options.targetUrl = normalizeTargetUrl(options.targetUrl)
|
||||
|
||||
const user = { username, password }
|
||||
|
||||
@@ -76,7 +78,7 @@ async function run (url: string, user: UserInfo) {
|
||||
|
||||
const youtubeDL = await safeGetYoutubeDL()
|
||||
|
||||
let info = await getYoutubeDLInfo(youtubeDL, program['targetUrl'], command.args)
|
||||
let info = await getYoutubeDLInfo(youtubeDL, options.targetUrl, command.args)
|
||||
|
||||
if (!Array.isArray(info)) info = [ info ]
|
||||
|
||||
@@ -92,10 +94,10 @@ async function run (url: string, user: UserInfo) {
|
||||
let infoArray: any[]
|
||||
|
||||
infoArray = [].concat(info)
|
||||
if (program['first']) {
|
||||
infoArray = infoArray.slice(0, program['first'])
|
||||
} else if (program['last']) {
|
||||
infoArray = infoArray.slice(-program['last'])
|
||||
if (options.first) {
|
||||
infoArray = infoArray.slice(0, options.first)
|
||||
} else if (options.last) {
|
||||
infoArray = infoArray.slice(-options.last)
|
||||
}
|
||||
// Normalize utf8 fields
|
||||
infoArray = infoArray.map(i => normalizeObject(i))
|
||||
@@ -104,12 +106,12 @@ async function run (url: string, user: UserInfo) {
|
||||
|
||||
for (const [ index, info ] of infoArray.entries()) {
|
||||
try {
|
||||
if (index > 0 && program['waitInterval']) {
|
||||
log.info("Wait for %d seconds before continuing.", program['waitInterval'] / 1000)
|
||||
await new Promise(res => setTimeout(res, program['waitInterval']))
|
||||
if (index > 0 && options.waitInterval) {
|
||||
log.info("Wait for %d seconds before continuing.", options.waitInterval / 1000)
|
||||
await new Promise(res => setTimeout(res, options.waitInterval))
|
||||
}
|
||||
await processVideo({
|
||||
cwd: program['tmpdir'],
|
||||
cwd: options.tmpdir,
|
||||
url,
|
||||
user,
|
||||
youtubeInfo: info
|
||||
@@ -119,7 +121,7 @@ async function run (url: string, user: UserInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
log.info('Video/s for user %s imported: %s', user.username, program['targetUrl'])
|
||||
log.info('Video/s for user %s imported: %s', user.username, options.targetUrl)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
@@ -137,14 +139,14 @@ async function processVideo (parameters: {
|
||||
log.debug('Fetched object.', videoInfo)
|
||||
|
||||
const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo)
|
||||
if (program['since'] && originallyPublishedAt && originallyPublishedAt.getTime() < program['since'].getTime()) {
|
||||
if (options.since && originallyPublishedAt && originallyPublishedAt.getTime() < options.since.getTime()) {
|
||||
log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
|
||||
videoInfo.title, formatDate(program['since']))
|
||||
videoInfo.title, formatDate(options.since))
|
||||
return
|
||||
}
|
||||
if (program['until'] && originallyPublishedAt && originallyPublishedAt.getTime() > program['until'].getTime()) {
|
||||
if (options.until && originallyPublishedAt && originallyPublishedAt.getTime() > options.until.getTime()) {
|
||||
log.info('Video "%s" has been published after "%s", don\'t upload it.\n',
|
||||
videoInfo.title, formatDate(program['until']))
|
||||
videoInfo.title, formatDate(options.until))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -161,11 +163,11 @@ async function processVideo (parameters: {
|
||||
|
||||
log.info('Downloading video "%s"...', videoInfo.title)
|
||||
|
||||
const options = [ '-f', getYoutubeDLVideoFormat(), ...command.args, '-o', path ]
|
||||
const youtubeDLOptions = [ '-f', getYoutubeDLVideoFormat(), ...command.args, '-o', path ]
|
||||
try {
|
||||
const youtubeDL = await safeGetYoutubeDL()
|
||||
const youtubeDLExec = promisify(youtubeDL.exec).bind(youtubeDL)
|
||||
const output = await youtubeDLExec(videoInfo.url, options, processOptions)
|
||||
const output = await youtubeDLExec(videoInfo.url, youtubeDLOptions, processOptions)
|
||||
log.info(output.join('\n'))
|
||||
await uploadVideoOnPeerTube({
|
||||
cwd,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { getAdminTokenOrDie, getServerCredentials } from './cli'
|
||||
import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model'
|
||||
import { isAbsolute } from 'path'
|
||||
import * as CliTable3 from 'cli-table3'
|
||||
import commander = require('commander')
|
||||
|
||||
program
|
||||
.name('plugins')
|
||||
@@ -33,7 +34,7 @@ program
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('-P --path <path>', 'Install from a path')
|
||||
.option('-n, --npm-name <npmName>', 'Install from npm')
|
||||
.action((options) => installPluginCLI(options))
|
||||
.action((options, command) => installPluginCLI(command, options))
|
||||
|
||||
program
|
||||
.command('update')
|
||||
@@ -43,7 +44,7 @@ program
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('-P --path <path>', 'Update from a path')
|
||||
.option('-n, --npm-name <npmName>', 'Update from npm')
|
||||
.action((options) => updatePluginCLI(options))
|
||||
.action((options, command) => updatePluginCLI(command, options))
|
||||
|
||||
program
|
||||
.command('uninstall')
|
||||
@@ -52,7 +53,7 @@ program
|
||||
.option('-U, --username <username>', 'Username')
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('-n, --npm-name <npmName>', 'NPM plugin/theme name')
|
||||
.action(options => uninstallPluginCLI(options))
|
||||
.action((options, command) => uninstallPluginCLI(command, options))
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
program.outputHelp()
|
||||
@@ -60,6 +61,8 @@ if (!process.argv.slice(2).length) {
|
||||
|
||||
program.parse(process.argv)
|
||||
|
||||
const options = program.opts()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
async function pluginsListCLI () {
|
||||
@@ -67,8 +70,8 @@ async function pluginsListCLI () {
|
||||
const accessToken = await getAdminTokenOrDie(url, username, password)
|
||||
|
||||
let pluginType: PluginType
|
||||
if (program['onlyThemes']) pluginType = PluginType.THEME
|
||||
if (program['onlyPlugins']) pluginType = PluginType.PLUGIN
|
||||
if (options.onlyThemes) pluginType = PluginType.THEME
|
||||
if (options.onlyPlugins) pluginType = PluginType.PLUGIN
|
||||
|
||||
const res = await listPlugins({
|
||||
url,
|
||||
@@ -101,27 +104,27 @@ async function pluginsListCLI () {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
async function installPluginCLI (options: any) {
|
||||
if (!options['path'] && !options['npmName']) {
|
||||
async function installPluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) {
|
||||
if (!options.path && !options.npmName) {
|
||||
console.error('You need to specify the npm name or the path of the plugin you want to install.\n')
|
||||
program.outputHelp()
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
if (options['path'] && !isAbsolute(options['path'])) {
|
||||
if (options.path && !isAbsolute(options.path)) {
|
||||
console.error('Path should be absolute.')
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
const { url, username, password } = await getServerCredentials(options)
|
||||
const { url, username, password } = await getServerCredentials(command)
|
||||
const accessToken = await getAdminTokenOrDie(url, username, password)
|
||||
|
||||
try {
|
||||
await installPlugin({
|
||||
url,
|
||||
accessToken,
|
||||
npmName: options['npmName'],
|
||||
path: options['path']
|
||||
npmName: options.npmName,
|
||||
path: options.path
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('Cannot install plugin.', err)
|
||||
@@ -132,27 +135,27 @@ async function installPluginCLI (options: any) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
async function updatePluginCLI (options: any) {
|
||||
if (!options['path'] && !options['npmName']) {
|
||||
async function updatePluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) {
|
||||
if (!options.path && !options.npmName) {
|
||||
console.error('You need to specify the npm name or the path of the plugin you want to update.\n')
|
||||
program.outputHelp()
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
if (options['path'] && !isAbsolute(options['path'])) {
|
||||
if (options.path && !isAbsolute(options.path)) {
|
||||
console.error('Path should be absolute.')
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
const { url, username, password } = await getServerCredentials(options)
|
||||
const { url, username, password } = await getServerCredentials(command)
|
||||
const accessToken = await getAdminTokenOrDie(url, username, password)
|
||||
|
||||
try {
|
||||
await updatePlugin({
|
||||
url,
|
||||
accessToken,
|
||||
npmName: options['npmName'],
|
||||
path: options['path']
|
||||
npmName: options.npmName,
|
||||
path: options.path
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('Cannot update plugin.', err)
|
||||
@@ -163,21 +166,21 @@ async function updatePluginCLI (options: any) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
async function uninstallPluginCLI (options: any) {
|
||||
if (!options['npmName']) {
|
||||
async function uninstallPluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) {
|
||||
if (!options.npmName) {
|
||||
console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n')
|
||||
program.outputHelp()
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
const { url, username, password } = await getServerCredentials(options)
|
||||
const { url, username, password } = await getServerCredentials(command)
|
||||
const accessToken = await getAdminTokenOrDie(url, username, password)
|
||||
|
||||
try {
|
||||
await uninstallPlugin({
|
||||
url,
|
||||
accessToken,
|
||||
npmName: options['npmName']
|
||||
npmName: options.npmName
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('Cannot uninstall plugin.', err)
|
||||
|
||||
@@ -14,6 +14,7 @@ import { URL } from 'url'
|
||||
import { uniq } from 'lodash'
|
||||
|
||||
import bytes = require('bytes')
|
||||
import commander = require('commander')
|
||||
|
||||
program
|
||||
.name('plugins')
|
||||
@@ -42,7 +43,7 @@ program
|
||||
.option('-U, --username <username>', 'Username')
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('-v, --video <videoId>', 'Video id to duplicate')
|
||||
.action((options) => addRedundancyCLI(options))
|
||||
.action((options, command) => addRedundancyCLI(options, command))
|
||||
|
||||
program
|
||||
.command('remove')
|
||||
@@ -51,7 +52,7 @@ program
|
||||
.option('-U, --username <username>', 'Username')
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('-v, --video <videoId>', 'Video id to remove from redundancies')
|
||||
.action((options) => removeRedundancyCLI(options))
|
||||
.action((options, command) => removeRedundancyCLI(options, command))
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
program.outputHelp()
|
||||
@@ -104,13 +105,13 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
async function addRedundancyCLI (options: { videoId: number }) {
|
||||
const { url, username, password } = await getServerCredentials(program)
|
||||
async function addRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) {
|
||||
const { url, username, password } = await getServerCredentials(command)
|
||||
const accessToken = await getAdminTokenOrDie(url, username, password)
|
||||
|
||||
if (!options['video'] || validator.isInt('' + options['video']) === false) {
|
||||
if (!options.video || validator.isInt('' + options.video) === false) {
|
||||
console.error('You need to specify the video id to duplicate and it should be a number.\n')
|
||||
program.outputHelp()
|
||||
command.outputHelp()
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ async function addRedundancyCLI (options: { videoId: number }) {
|
||||
await addVideoRedundancy({
|
||||
url,
|
||||
accessToken,
|
||||
videoId: options['video']
|
||||
videoId: options.video
|
||||
})
|
||||
|
||||
console.log('Video will be duplicated by your instance!')
|
||||
@@ -137,17 +138,17 @@ async function addRedundancyCLI (options: { videoId: number }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function removeRedundancyCLI (options: { videoId: number }) {
|
||||
const { url, username, password } = await getServerCredentials(program)
|
||||
async function removeRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) {
|
||||
const { url, username, password } = await getServerCredentials(command)
|
||||
const accessToken = await getAdminTokenOrDie(url, username, password)
|
||||
|
||||
if (!options['video'] || validator.isInt('' + options['video']) === false) {
|
||||
if (!options.video || validator.isInt('' + options.video) === false) {
|
||||
console.error('You need to specify the video id to remove from your redundancies.\n')
|
||||
program.outputHelp()
|
||||
command.outputHelp()
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
const videoId = parseInt(options['video'] + '', 10)
|
||||
const videoId = parseInt(options.video + '', 10)
|
||||
|
||||
let redundancies = await listVideoRedundanciesData(url, accessToken, 'my-videos')
|
||||
let videoRedundancy = redundancies.find(r => videoId === r.id)
|
||||
|
||||
@@ -82,7 +82,6 @@ const start = async () => {
|
||||
}
|
||||
replServer.defineCommand('reset', resetCommand)
|
||||
replServer.defineCommand('r', resetCommand)
|
||||
|
||||
}
|
||||
|
||||
start()
|
||||
|
||||
@@ -22,16 +22,18 @@ command
|
||||
.option('-f, --file <file>', 'Video absolute file path')
|
||||
.parse(process.argv)
|
||||
|
||||
const options = command.opts()
|
||||
|
||||
getServerCredentials(command)
|
||||
.then(({ url, username, password }) => {
|
||||
if (!program['videoName'] || !program['file']) {
|
||||
if (!program['videoName']) console.error('--video-name is required.')
|
||||
if (!program['file']) console.error('--file is required.')
|
||||
if (!options.videoName || !options.file) {
|
||||
if (!options.videoName) console.error('--video-name is required.')
|
||||
if (!options.file) console.error('--file is required.')
|
||||
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
if (isAbsolute(program['file']) === false) {
|
||||
if (isAbsolute(options.file) === false) {
|
||||
console.error('File path should be absolute.')
|
||||
process.exit(-1)
|
||||
}
|
||||
@@ -46,21 +48,21 @@ getServerCredentials(command)
|
||||
async function run (url: string, username: string, password: string) {
|
||||
const accessToken = await getAccessToken(url, username, password)
|
||||
|
||||
await access(program['file'], constants.F_OK)
|
||||
await access(options.file, constants.F_OK)
|
||||
|
||||
console.log('Uploading %s video...', program['videoName'])
|
||||
console.log('Uploading %s video...', options.videoName)
|
||||
|
||||
const videoAttributes = await buildVideoAttributesFromCommander(url, program)
|
||||
|
||||
Object.assign(videoAttributes, {
|
||||
fixture: program['file'],
|
||||
thumbnailfile: program['thumbnail'],
|
||||
previewfile: program['preview']
|
||||
fixture: options.file,
|
||||
thumbnailfile: options.thumbnail,
|
||||
previewfile: options.preview
|
||||
})
|
||||
|
||||
try {
|
||||
await uploadVideo(url, accessToken, videoAttributes)
|
||||
console.log(`Video ${program['videoName']} uploaded.`)
|
||||
console.log(`Video ${options.videoName} uploaded.`)
|
||||
process.exit(0)
|
||||
} catch (err) {
|
||||
console.error(require('util').inspect(err))
|
||||
|
||||
@@ -8,40 +8,30 @@ import { execSync } from 'child_process'
|
||||
program
|
||||
.name('watch')
|
||||
.arguments('<url>')
|
||||
.option('-g, --gui <player>', 'player type', /^(airplay|stdout|chromecast|mpv|vlc|mplayer|xbmc)$/i, 'vlc')
|
||||
.addOption(
|
||||
new program.Option('-g, --gui <player>', 'player type')
|
||||
.default('vlc')
|
||||
.choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ])
|
||||
)
|
||||
.option('-r, --resolution <res>', 'video resolution', '480')
|
||||
.on('--help', function () {
|
||||
console.log(' Available Players:')
|
||||
console.log()
|
||||
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()
|
||||
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, cmd) => run(url, cmd))
|
||||
.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)
|
||||
|
||||
function run (url: string, program: any) {
|
||||
function run (url: string, options: program.OptionValues) {
|
||||
if (!url) {
|
||||
console.error('<url> positional argument is required.')
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
|
||||
const args = ` --${program.gui} ` +
|
||||
const args = ` --${options.gui} ` +
|
||||
url.replace('videos/watch', 'download/torrents') +
|
||||
`-${program.resolution}.torrent`
|
||||
`-${options.resolution}.torrent`
|
||||
|
||||
try {
|
||||
execSync(cmd + args)
|
||||
|
||||
@@ -69,17 +69,12 @@ getSettings()
|
||||
: 'instance ' + settings.remotes[settings.default] + ' selected'
|
||||
|
||||
program
|
||||
.on('--help', function () {
|
||||
console.log()
|
||||
console.log(' State: ' + state)
|
||||
console.log()
|
||||
console.log(' Examples:')
|
||||
console.log()
|
||||
console.log(' $ peertube auth add -u "PEERTUBE_URL" -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"')
|
||||
console.log(' $ peertube up <videoFile>')
|
||||
console.log(' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10')
|
||||
console.log()
|
||||
})
|
||||
.addHelpText('after', '\n\n State: ' + state + '\n\n' +
|
||||
' Examples:\n\n' +
|
||||
' $ peertube auth add -u "PEERTUBE_URL" -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"\n' +
|
||||
' $ peertube up <videoFile>\n' +
|
||||
' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n'
|
||||
)
|
||||
.parse(process.argv)
|
||||
})
|
||||
.catch(err => console.error(err))
|
||||
|
||||
Reference in New Issue
Block a user