aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/upload-directory.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-09 16:47:06 +0100
committerChocobozzz <me@florianbigard.com>2018-02-09 16:47:06 +0100
commita7fea183f0f69104b209e7bfdd6435be28165f22 (patch)
treea0bfb7daf8e9778c664b8d7224b2e1c382e3834e /server/tools/upload-directory.ts
parent1185c246c591a0783dc0ab268bbd67eba1d46bb9 (diff)
downloadPeerTube-a7fea183f0f69104b209e7bfdd6435be28165f22.tar.gz
PeerTube-a7fea183f0f69104b209e7bfdd6435be28165f22.tar.zst
PeerTube-a7fea183f0f69104b209e7bfdd6435be28165f22.zip
Begin import script with youtube-dl
Diffstat (limited to 'server/tools/upload-directory.ts')
-rw-r--r--server/tools/upload-directory.ts82
1 files changed, 82 insertions, 0 deletions
diff --git a/server/tools/upload-directory.ts b/server/tools/upload-directory.ts
new file mode 100644
index 000000000..c0094f852
--- /dev/null
+++ b/server/tools/upload-directory.ts
@@ -0,0 +1,82 @@
1import * as program from 'commander'
2import * as Promise from 'bluebird'
3import { isAbsolute, join } from 'path'
4
5import { readdirPromise } from '../helpers/core-utils'
6import { execCLI } from '../tests/utils/index'
7
8program
9 .option('-u, --url <url>', 'Server url')
10 .option('-U, --username <username>', 'Username')
11 .option('-p, --password <token>', 'Password')
12 .option('-i, --input <directory>', 'Videos directory absolute path')
13 .option('-d, --description <description>', 'Video descriptions')
14 .option('-c, --category <category>', 'Video categories')
15 .option('-l, --licence <licence>', 'Video licences')
16 .option('-t, --tags <tags>', 'Video tags', list)
17 .parse(process.argv)
18
19if (
20 !program['url'] ||
21 !program['username'] ||
22 !program['password'] ||
23 !program['input'] ||
24 !program['description'] ||
25 !program['category'] ||
26 !program['licence'] ||
27 !program['tags']
28) {
29 throw new Error('All arguments are required.')
30}
31
32if (isAbsolute(program['input']) === false) {
33 throw new Error('Input path should be absolute.')
34}
35
36let command = `npm run ts-node -- ${__dirname}/get-access-token.ts`
37command += ` -u "${program['url']}"`
38command += ` -n "${program['username']}"`
39command += ` -p "${program['password']}"`
40
41execCLI(command)
42 .then(stdout => {
43 const accessToken = stdout.replace('\n', '')
44
45 console.log(accessToken)
46
47 return readdirPromise(program['input']).then(files => ({ accessToken, files }))
48 })
49 .then(({ accessToken, files }) => {
50 return Promise.each(files, file => {
51 const video = {
52 tags: program['tags'],
53 name: file,
54 description: program['description'],
55 category: program['category'],
56 licence: program['licence']
57 }
58
59 let command = `npm run ts-node -- ${__dirname}/upload.ts`
60 command += ` -u "${program['url']}"`
61 command += ` -a "${accessToken}"`
62 command += ` -n "${video.name}"`
63 command += ` -d "${video.description}"`
64 command += ` -c "${video.category}"`
65 command += ` -l "${video.licence}"`
66 command += ` -t "${video.tags.join(',')}"`
67 command += ` -f "${join(program['input'], file)}"`
68
69 return execCLI(command).then(stdout => console.log(stdout))
70 })
71 })
72 .then(() => process.exit(0))
73 .catch(err => {
74 console.error(err)
75 process.exit(-1)
76 })
77
78// ----------------------------------------------------------------------------
79
80function list (val) {
81 return val.split(',')
82}