2016-07-20 12:16:00 -05:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const program = require('commander')
|
|
|
|
const fs = require('fs')
|
|
|
|
|
2016-10-10 14:33:40 -05:00
|
|
|
const utils = require('../../utils/videos')
|
2016-07-20 12:16:00 -05:00
|
|
|
|
|
|
|
program
|
|
|
|
.option('-u, --url <url>', 'Server url')
|
|
|
|
.option('-a, --access-token <token>', 'Access token')
|
|
|
|
.option('-n, --name <name>', 'Video name')
|
2017-03-27 13:53:11 -05:00
|
|
|
.option('-c, --category <category number>', 'Category number')
|
|
|
|
.option('-l, --licence <licence number>', 'Licence number')
|
2016-07-20 12:16:00 -05:00
|
|
|
.option('-d, --description <description>', 'Video description')
|
|
|
|
.option('-t, --tags <tags>', 'Video tags', list)
|
|
|
|
.option('-f, --file <file>', 'Video absolute file path')
|
|
|
|
.parse(process.argv)
|
|
|
|
|
|
|
|
if (
|
|
|
|
!program.url ||
|
|
|
|
!program.accessToken ||
|
|
|
|
!program.name ||
|
2017-03-22 15:15:55 -05:00
|
|
|
!program.category ||
|
2017-03-27 13:53:11 -05:00
|
|
|
!program.licence ||
|
2016-07-20 12:16:00 -05:00
|
|
|
!program.description ||
|
|
|
|
!program.tags ||
|
|
|
|
!Array.isArray(program.tags) ||
|
|
|
|
program.tags.length === 0 ||
|
|
|
|
!program.file
|
|
|
|
) {
|
|
|
|
throw new Error('All arguments are required.')
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.access(program.file, fs.F_OK, function (err) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
upload(
|
|
|
|
program.url,
|
|
|
|
program.accessToken,
|
|
|
|
program.name,
|
2017-03-22 15:15:55 -05:00
|
|
|
program.category,
|
2017-03-27 13:53:11 -05:00
|
|
|
program.licence,
|
2016-07-20 12:16:00 -05:00
|
|
|
program.description,
|
|
|
|
program.tags,
|
|
|
|
program.file
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function list (val) {
|
|
|
|
return val.split(',')
|
|
|
|
}
|
|
|
|
|
2017-03-27 13:53:11 -05:00
|
|
|
function upload (url, accessToken, name, category, licence, description, tags, fixture) {
|
2016-07-20 12:16:00 -05:00
|
|
|
console.log('Uploading %s video...', program.name)
|
|
|
|
|
2017-03-26 11:39:01 -05:00
|
|
|
const videoAttributes = {
|
|
|
|
name,
|
|
|
|
category,
|
2017-03-27 13:53:11 -05:00
|
|
|
licence,
|
2017-03-26 11:39:01 -05:00
|
|
|
description,
|
|
|
|
tags,
|
|
|
|
fixture
|
|
|
|
}
|
|
|
|
utils.uploadVideo(url, accessToken, videoAttributes, function (err) {
|
2016-07-20 12:16:00 -05:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
console.log('Video uploaded.')
|
|
|
|
})
|
|
|
|
}
|