1 import * as program from 'commander'
2 import { access, constants } from 'fs'
3 import { isAbsolute } from 'path'
4 import { promisify } from 'util'
6 const accessPromise = promisify(access)
8 import { uploadVideo } from '../../utils'
11 .option('-u, --url <url>', 'Server url')
12 .option('-a, --access-token <token>', 'Access token')
13 .option('-n, --name <name>', 'Video name')
14 .option('-N, --nsfw', 'Video is Not Safe For Work')
15 .option('-c, --category <category number>', 'Category number')
16 .option('-l, --licence <licence number>', 'Licence number')
17 .option('-L, --language <language number>', 'Language number')
18 .option('-d, --description <description>', 'Video description')
19 .option('-t, --tags <tags>', 'Video tags', list)
20 .option('-f, --file <file>', 'Video absolute file path')
23 if (!program['tags']) program['tags'] = []
24 if (!program['nsfw']) program['nsfw'] = false
28 !program['accessToken'] ||
30 !program['category'] ||
31 !program['licence'] ||
32 !program['description'] ||
35 throw new Error('All arguments but tags, language and nsfw are required.')
38 if (isAbsolute(program['file']) === false) {
39 throw new Error('File path should be absolute.')
42 accessPromise(program['file'], constants.F_OK)
46 program['accessToken'],
52 program['description'],
57 .then(() => process.exit(0))
63 // ----------------------------------------------------------------------------
69 function upload (url, accessToken, name, category, licence, language, nsfw, description, tags, fixture) {
70 console.log('Uploading %s video...', program['name'])
72 const videoAttributes = {
82 return uploadVideo(url, accessToken, videoAttributes).then(() => {
83 console.log(`Video ${name} uploaded.`)