]>
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') | |
31b59b47 | 12 | .option('-x, --nsfw', 'Video is Not Safe For Work') |
6f0c39e2 C |
13 | .option('-c, --category <category number>', 'Category number') |
14 | .option('-l, --licence <licence number>', 'Licence number') | |
677618d4 C |
15 | .option('-d, --description <description>', 'Video description') |
16 | .option('-t, --tags <tags>', 'Video tags', list) | |
17 | .option('-f, --file <file>', 'Video absolute file path') | |
18 | .parse(process.argv) | |
19 | ||
20 | if ( | |
21 | !program.url || | |
22 | !program.accessToken || | |
23 | !program.name || | |
6e07c3de | 24 | !program.category || |
6f0c39e2 | 25 | !program.licence || |
31b59b47 | 26 | !program.nsfw || |
677618d4 C |
27 | !program.description || |
28 | !program.tags || | |
29 | !Array.isArray(program.tags) || | |
30 | program.tags.length === 0 || | |
31 | !program.file | |
32 | ) { | |
33 | throw new Error('All arguments are required.') | |
34 | } | |
35 | ||
36 | fs.access(program.file, fs.F_OK, function (err) { | |
37 | if (err) throw err | |
38 | ||
39 | upload( | |
40 | program.url, | |
41 | program.accessToken, | |
42 | program.name, | |
6e07c3de | 43 | program.category, |
6f0c39e2 | 44 | program.licence, |
31b59b47 | 45 | program.nsfw, |
677618d4 C |
46 | program.description, |
47 | program.tags, | |
48 | program.file | |
49 | ) | |
50 | }) | |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | function list (val) { | |
55 | return val.split(',') | |
56 | } | |
57 | ||
31b59b47 | 58 | function upload (url, accessToken, name, category, licence, nsfw, description, tags, fixture) { |
677618d4 C |
59 | console.log('Uploading %s video...', program.name) |
60 | ||
b4c5ac97 C |
61 | const videoAttributes = { |
62 | name, | |
63 | category, | |
6f0c39e2 | 64 | licence, |
31b59b47 | 65 | nsfw, |
b4c5ac97 C |
66 | description, |
67 | tags, | |
68 | fixture | |
69 | } | |
70 | utils.uploadVideo(url, accessToken, videoAttributes, function (err) { | |
677618d4 C |
71 | if (err) throw err |
72 | ||
73 | console.log('Video uploaded.') | |
74 | }) | |
75 | } |