diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-07-20 19:16:00 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-07-20 19:16:00 +0200 |
commit | 677618d4a600a1678088d107850c8f1f8c95255f (patch) | |
tree | b0ea636094a7a6c8188757bcd2a68ce1231e3d6f /server/tests/real-world/tools/upload-directory.js | |
parent | 2bd3f171270aff9717a55f2b89757fe966911af3 (diff) | |
download | PeerTube-677618d4a600a1678088d107850c8f1f8c95255f.tar.gz PeerTube-677618d4a600a1678088d107850c8f1f8c95255f.tar.zst PeerTube-677618d4a600a1678088d107850c8f1f8c95255f.zip |
Server: Add some cli tools to make it easy to upload a lot of videos
Diffstat (limited to 'server/tests/real-world/tools/upload-directory.js')
-rw-r--r-- | server/tests/real-world/tools/upload-directory.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/server/tests/real-world/tools/upload-directory.js b/server/tests/real-world/tools/upload-directory.js new file mode 100644 index 000000000..aed7a1fd8 --- /dev/null +++ b/server/tests/real-world/tools/upload-directory.js | |||
@@ -0,0 +1,67 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const program = require('commander') | ||
4 | const eachSeries = require('async/eachSeries') | ||
5 | const exec = require('child_process').exec | ||
6 | const fs = require('fs') | ||
7 | const path = require('path') | ||
8 | |||
9 | program | ||
10 | .option('-u, --url <url>', 'Server url') | ||
11 | .option('-n, --username <username>', 'Username') | ||
12 | .option('-p, --password <token>', 'Password') | ||
13 | .option('-i, --directory <directory>', 'Videos directory absolute path') | ||
14 | .option('-d, --description <description>', 'Video description') | ||
15 | .option('-t, --tags <tags>', 'Video tags', list) | ||
16 | .parse(process.argv) | ||
17 | |||
18 | if ( | ||
19 | !program.url || | ||
20 | !program.username || | ||
21 | !program.password || | ||
22 | !program.directory || | ||
23 | !program.description || | ||
24 | !program.tags | ||
25 | ) { | ||
26 | throw new Error('All arguments are required.') | ||
27 | } | ||
28 | |||
29 | exec('node ./get-access-token -u "' + program.url + '" -n "' + program.username + '" -p "' + program.password + '"', function (err, stdout) { | ||
30 | if (err) throw err | ||
31 | |||
32 | const accessToken = stdout.replace('\n', '') | ||
33 | |||
34 | fs.readdir(program.directory, function (err, files) { | ||
35 | if (err) throw err | ||
36 | |||
37 | eachSeries(files, function (file, callbackEach) { | ||
38 | const video = { | ||
39 | tags: program.tags, | ||
40 | name: file, | ||
41 | description: program.description | ||
42 | } | ||
43 | |||
44 | let command = 'node ./upload' | ||
45 | command += ' -u "' + program.url + '"' | ||
46 | command += ' -a "' + accessToken + '"' | ||
47 | command += ' -n "' + video.name + '"' | ||
48 | command += ' -d "' + video.description + '"' | ||
49 | command += ' -t "' + video.tags.join(',') + '"' | ||
50 | command += ' -f "' + path.join(program.directory, file) + '"' | ||
51 | |||
52 | exec(command, function (err, stdout) { | ||
53 | if (err) console.log(err) | ||
54 | |||
55 | console.log(stdout) | ||
56 | |||
57 | return callbackEach() | ||
58 | }) | ||
59 | }) | ||
60 | }) | ||
61 | }) | ||
62 | |||
63 | // ---------------------------------------------------------------------------- | ||
64 | |||
65 | function list (val) { | ||
66 | return val.split(',') | ||
67 | } | ||