]>
Commit | Line | Data |
---|---|---|
677618d4 C |
1 | 'use strict' |
2 | ||
3 | const program = require('commander') | |
4 | const fs = require('fs') | |
5 | ||
3fad43ac | 6 | const utils = require('../../utils/videos') |
677618d4 C |
7 | |
8 | program | |
9 | .option('-u, --url <url>', 'Server url') | |
10 | .option('-a, --access-token <token>', 'Access token') | |
11 | .option('-n, --name <name>', 'Video name') | |
6e07c3de | 12 | .option('-d, --category <category number>', 'Category number') |
677618d4 C |
13 | .option('-d, --description <description>', 'Video description') |
14 | .option('-t, --tags <tags>', 'Video tags', list) | |
15 | .option('-f, --file <file>', 'Video absolute file path') | |
16 | .parse(process.argv) | |
17 | ||
18 | if ( | |
19 | !program.url || | |
20 | !program.accessToken || | |
21 | !program.name || | |
6e07c3de | 22 | !program.category || |
677618d4 C |
23 | !program.description || |
24 | !program.tags || | |
25 | !Array.isArray(program.tags) || | |
26 | program.tags.length === 0 || | |
27 | !program.file | |
28 | ) { | |
29 | throw new Error('All arguments are required.') | |
30 | } | |
31 | ||
32 | fs.access(program.file, fs.F_OK, function (err) { | |
33 | if (err) throw err | |
34 | ||
35 | upload( | |
36 | program.url, | |
37 | program.accessToken, | |
38 | program.name, | |
6e07c3de | 39 | program.category, |
677618d4 C |
40 | program.description, |
41 | program.tags, | |
42 | program.file | |
43 | ) | |
44 | }) | |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | function list (val) { | |
49 | return val.split(',') | |
50 | } | |
51 | ||
b4c5ac97 | 52 | function upload (url, accessToken, name, category, description, tags, fixture) { |
677618d4 C |
53 | console.log('Uploading %s video...', program.name) |
54 | ||
b4c5ac97 C |
55 | const videoAttributes = { |
56 | name, | |
57 | category, | |
58 | description, | |
59 | tags, | |
60 | fixture | |
61 | } | |
62 | utils.uploadVideo(url, accessToken, videoAttributes, function (err) { | |
677618d4 C |
63 | if (err) throw err |
64 | ||
65 | console.log('Video uploaded.') | |
66 | }) | |
67 | } |