]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/real-world/tools/upload.js
49076ee2ad809df6c4e1b5e49815e78d781db3cc
[github/Chocobozzz/PeerTube.git] / server / tests / real-world / tools / upload.js
1 'use strict'
2
3 const program = require('commander')
4 const fs = require('fs')
5
6 const utils = require('../../utils/videos')
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')
12 .option('-d, --category <category number>', 'Category number')
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
18 if (
19 !program.url ||
20 !program.accessToken ||
21 !program.name ||
22 !program.category ||
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
32 fs.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,
39 program.category,
40 program.description,
41 program.tags,
42 program.file
43 )
44 })
45
46 // ----------------------------------------------------------------------------
47
48 function list (val) {
49 return val.split(',')
50 }
51
52 function upload (url, accessToken, name, category, description, tags, file) {
53 console.log('Uploading %s video...', program.name)
54
55 utils.uploadVideo(url, accessToken, name, category, description, tags, file, function (err) {
56 if (err) throw err
57
58 console.log('Video uploaded.')
59 })
60 }