]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/upload.ts
Handle changelog in release
[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')
8df87ce7
C
15 .option('-N, --nsfw', 'Video is Not Safe For Work')
16 .option('-c, --category <category number>', 'Category number')
a87d467a 17 .option('-m, --comments-enabled', 'Enable comments')
8df87ce7
C
18 .option('-l, --licence <licence number>', 'Licence number')
19 .option('-L, --language <language number>', 'Language number')
a87d467a 20 .option('-d, --video-description <description>', 'Video description')
8df87ce7 21 .option('-t, --tags <tags>', 'Video tags', list)
2422c46b 22 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
8df87ce7
C
23 .option('-f, --file <file>', 'Video absolute file path')
24 .parse(process.argv)
25
26if (!program['tags']) program['tags'] = []
27if (!program['nsfw']) program['nsfw'] = false
a87d467a 28if (!program['commentsEnabled']) program['commentsEnabled'] = false
8df87ce7
C
29
30if (
31 !program['url'] ||
a87d467a
C
32 !program['username'] ||
33 !program['password'] ||
34 !program['videoName'] ||
8df87ce7
C
35 !program['file']
36) {
a87d467a
C
37 console.error('Url, username, password, name and input file are required.')
38 process.exit(-1)
8df87ce7
C
39}
40
41if (isAbsolute(program['file']) === false) {
a87d467a
C
42 console.error('File path should be absolute.')
43 process.exit(-1)
8df87ce7
C
44}
45
a87d467a 46run().catch(err => console.error(err))
8df87ce7 47
a87d467a
C
48async function run () {
49 const res = await getClient(program[ 'url' ])
50 const client = {
51 id: res.body.client_id,
52 secret: res.body.client_secret
53 }
8df87ce7 54
a87d467a
C
55 const user = {
56 username: program[ 'username' ],
57 password: program[ 'password' ]
58 }
59
60 const res2 = await login(program[ 'url' ], client, user)
61 const accessToken = res2.body.access_token
8df87ce7 62
a87d467a
C
63 await accessPromise(program[ 'file' ], constants.F_OK)
64
65 console.log('Uploading %s video...', program[ 'videoName' ])
8df87ce7
C
66
67 const videoAttributes = {
a87d467a
C
68 name: program['videoName'],
69 category: program['category'],
70 licence: program['licence'],
71 language: program['language'],
72 nsfw: program['nsfw'],
73 description: program['videoDescription'],
74 tags: program['tags'],
75 commentsEnabled: program['commentsEnabled'],
2422c46b
C
76 fixture: program['file'],
77 thumbnailfile: program['thumbnailPath']
8df87ce7 78 }
a87d467a
C
79
80 await uploadVideo(program['url'], accessToken, videoAttributes)
81
82 console.log(`Video ${program['videoName']} uploaded.`)
83 process.exit(0)
84}
85
86// ----------------------------------------------------------------------------
87
88function list (val) {
89 return val.split(',')
8df87ce7 90}