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