]>
Commit | Line | Data |
---|---|---|
8df87ce7 C |
1 | import * as program from 'commander' |
2 | import { access, constants } from 'fs' | |
3 | import { isAbsolute } from 'path' | |
4 | import { promisify } from 'util' | |
a87d467a C |
5 | import { getClient, login } from '../tests/utils' |
6 | import { uploadVideo } from '../tests/utils/index' | |
72de91cb | 7 | import { VideoPrivacy } from '../../shared/models/videos' |
8df87ce7 C |
8 | |
9 | const accessPromise = promisify(access) | |
10 | ||
8df87ce7 C |
11 | program |
12 | .option('-u, --url <url>', 'Server url') | |
a87d467a C |
13 | .option('-U, --username <username>', 'Username') |
14 | .option('-p, --password <token>', 'Password') | |
15 | .option('-n, --video-name <name>', 'Video name') | |
320f8d7e | 16 | .option('-P, --privacy <privacy number>', 'Privacy') |
8df87ce7 C |
17 | .option('-N, --nsfw', 'Video is Not Safe For Work') |
18 | .option('-c, --category <category number>', 'Category number') | |
a87d467a | 19 | .option('-m, --comments-enabled', 'Enable comments') |
8df87ce7 | 20 | .option('-l, --licence <licence number>', 'Licence number') |
9d3ef9fe | 21 | .option('-L, --language <language code>', 'Language ISO 639 code (fr or en...)') |
a87d467a | 22 | .option('-d, --video-description <description>', 'Video description') |
8df87ce7 | 23 | .option('-t, --tags <tags>', 'Video tags', list) |
2422c46b | 24 | .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path') |
02988fdc | 25 | .option('-v, --preview <previewPath>', 'Preview path') |
8df87ce7 C |
26 | .option('-f, --file <file>', 'Video absolute file path') |
27 | .parse(process.argv) | |
28 | ||
29 | if (!program['tags']) program['tags'] = [] | |
30 | if (!program['nsfw']) program['nsfw'] = false | |
72de91cb | 31 | if (!program['privacy']) program['privacy'] = VideoPrivacy.PUBLIC |
a87d467a | 32 | if (!program['commentsEnabled']) program['commentsEnabled'] = false |
8df87ce7 C |
33 | |
34 | if ( | |
35 | !program['url'] || | |
a87d467a C |
36 | !program['username'] || |
37 | !program['password'] || | |
38 | !program['videoName'] || | |
8df87ce7 C |
39 | !program['file'] |
40 | ) { | |
48e35415 RK |
41 | if (!program['url']) console.error('--url field is required.') |
42 | if (!program['username']) console.error('--username field is required.') | |
43 | if (!program['password']) console.error('--password field is required.') | |
44 | if (!program['videoName']) console.error('--video-name field is required.') | |
45 | if (!program['file']) console.error('--file field is required.') | |
a87d467a | 46 | process.exit(-1) |
8df87ce7 C |
47 | } |
48 | ||
49 | if (isAbsolute(program['file']) === false) { | |
a87d467a C |
50 | console.error('File path should be absolute.') |
51 | process.exit(-1) | |
8df87ce7 C |
52 | } |
53 | ||
a87d467a | 54 | run().catch(err => console.error(err)) |
8df87ce7 | 55 | |
a87d467a C |
56 | async function run () { |
57 | const res = await getClient(program[ 'url' ]) | |
58 | const client = { | |
59 | id: res.body.client_id, | |
60 | secret: res.body.client_secret | |
61 | } | |
8df87ce7 | 62 | |
a87d467a C |
63 | const user = { |
64 | username: program[ 'username' ], | |
65 | password: program[ 'password' ] | |
66 | } | |
67 | ||
68 | const res2 = await login(program[ 'url' ], client, user) | |
69 | const accessToken = res2.body.access_token | |
8df87ce7 | 70 | |
a87d467a C |
71 | await accessPromise(program[ 'file' ], constants.F_OK) |
72 | ||
73 | console.log('Uploading %s video...', program[ 'videoName' ]) | |
8df87ce7 C |
74 | |
75 | const videoAttributes = { | |
a87d467a C |
76 | name: program['videoName'], |
77 | category: program['category'], | |
78 | licence: program['licence'], | |
79 | language: program['language'], | |
80 | nsfw: program['nsfw'], | |
81 | description: program['videoDescription'], | |
82 | tags: program['tags'], | |
83 | commentsEnabled: program['commentsEnabled'], | |
2422c46b | 84 | fixture: program['file'], |
02988fdc | 85 | thumbnailfile: program['thumbnailPath'], |
ad34cfc8 | 86 | previewfile: program['previewPath'], |
2186386c | 87 | waitTranscoding: true, |
320f8d7e | 88 | privacy: program['privacy'], |
ad34cfc8 | 89 | support: undefined |
8df87ce7 | 90 | } |
a87d467a C |
91 | |
92 | await uploadVideo(program['url'], accessToken, videoAttributes) | |
93 | ||
94 | console.log(`Video ${program['videoName']} uploaded.`) | |
95 | process.exit(0) | |
96 | } | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | ||
100 | function list (val) { | |
101 | return val.split(',') | |
8df87ce7 | 102 | } |