1 import * as program from 'commander'
2 import * as Promise from 'bluebird'
3 import { isAbsolute } from 'path'
4 import { join } from 'path'
6 import { readdirPromise } from '../../../helpers/core-utils'
7 import { execCLI } from '../../utils'
10 .option('-u, --url <url>', 'Server url')
11 .option('-U, --username <username>', 'Username')
12 .option('-p, --password <token>', 'Password')
13 .option('-i, --input <directory>', 'Videos directory absolute path')
14 .option('-d, --description <description>', 'Video descriptions')
15 .option('-c, --category <category>', 'Video categories')
16 .option('-l, --licence <licence>', 'Video licences')
17 .option('-t, --tags <tags>', 'Video tags', list)
22 !program['username'] ||
23 !program['password'] ||
25 !program['description'] ||
26 !program['category'] ||
27 !program['licence'] ||
30 throw new Error('All arguments are required.')
33 if (isAbsolute(program['input']) === false) {
34 throw new Error('Input path should be absolute.')
37 let command = `npm run ts-node -- ${__dirname}/get-access-token.ts`
38 command += ` -u "${program['url']}"`
39 command += ` -n "${program['username']}"`
40 command += ` -p "${program['password']}"`
44 const accessToken = stdout.replace('\n', '')
46 console.log(accessToken)
48 return readdirPromise(program['input']).then(files => ({ accessToken, files }))
50 .then(({ accessToken, files }) => {
51 return Promise.each(files, file => {
53 tags: program['tags'],
55 description: program['description'],
56 category: program['category'],
57 licence: program['licence']
60 let command = `npm run ts-node -- ${__dirname}/upload.ts`
61 command += ` -u "${program['url']}"`
62 command += ` -a "${accessToken}"`
63 command += ` -n "${video.name}"`
64 command += ` -d "${video.description}"`
65 command += ` -c "${video.category}"`
66 command += ` -l "${video.licence}"`
67 command += ` -t "${video.tags.join(',')}"`
68 command += ` -f "${join(program['input'], file)}"`
70 return execCLI(command).then(stdout => console.log(stdout))
73 .then(() => process.exit(0))
79 // ----------------------------------------------------------------------------