From 677618d4a600a1678088d107850c8f1f8c95255f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 Jul 2016 19:16:00 +0200 Subject: Server: Add some cli tools to make it easy to upload a lot of videos --- server/tests/real-world/tools/upload-directory.js | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 server/tests/real-world/tools/upload-directory.js (limited to 'server/tests/real-world/tools/upload-directory.js') 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 @@ +'use strict' + +const program = require('commander') +const eachSeries = require('async/eachSeries') +const exec = require('child_process').exec +const fs = require('fs') +const path = require('path') + +program + .option('-u, --url ', 'Server url') + .option('-n, --username ', 'Username') + .option('-p, --password ', 'Password') + .option('-i, --directory ', 'Videos directory absolute path') + .option('-d, --description ', 'Video description') + .option('-t, --tags ', 'Video tags', list) + .parse(process.argv) + +if ( + !program.url || + !program.username || + !program.password || + !program.directory || + !program.description || + !program.tags +) { + throw new Error('All arguments are required.') +} + +exec('node ./get-access-token -u "' + program.url + '" -n "' + program.username + '" -p "' + program.password + '"', function (err, stdout) { + if (err) throw err + + const accessToken = stdout.replace('\n', '') + + fs.readdir(program.directory, function (err, files) { + if (err) throw err + + eachSeries(files, function (file, callbackEach) { + const video = { + tags: program.tags, + name: file, + description: program.description + } + + let command = 'node ./upload' + command += ' -u "' + program.url + '"' + command += ' -a "' + accessToken + '"' + command += ' -n "' + video.name + '"' + command += ' -d "' + video.description + '"' + command += ' -t "' + video.tags.join(',') + '"' + command += ' -f "' + path.join(program.directory, file) + '"' + + exec(command, function (err, stdout) { + if (err) console.log(err) + + console.log(stdout) + + return callbackEach() + }) + }) + }) +}) + +// ---------------------------------------------------------------------------- + +function list (val) { + return val.split(',') +} -- cgit v1.2.3