]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/real-world/tools/upload.js
Add video category support
[github/Chocobozzz/PeerTube.git] / server / tests / real-world / tools / upload.js
CommitLineData
677618d4
C
1'use strict'
2
3const program = require('commander')
4const fs = require('fs')
5
3fad43ac 6const utils = require('../../utils/videos')
677618d4
C
7
8program
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
18if (
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
32fs.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
48function list (val) {
49 return val.split(',')
50}
51
6e07c3de 52function upload (url, accessToken, name, category, description, tags, file) {
677618d4
C
53 console.log('Uploading %s video...', program.name)
54
6e07c3de 55 utils.uploadVideo(url, accessToken, name, category, description, tags, file, function (err) {
677618d4
C
56 if (err) throw err
57
58 console.log('Video uploaded.')
59 })
60}