diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-09 16:47:06 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-09 16:47:06 +0100 |
commit | a7fea183f0f69104b209e7bfdd6435be28165f22 (patch) | |
tree | a0bfb7daf8e9778c664b8d7224b2e1c382e3834e /server/tools/upload-directory.ts | |
parent | 1185c246c591a0783dc0ab268bbd67eba1d46bb9 (diff) | |
download | PeerTube-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.ts | 82 |
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 @@ | |||
1 | import * as program from 'commander' | ||
2 | import * as Promise from 'bluebird' | ||
3 | import { isAbsolute, join } from 'path' | ||
4 | |||
5 | import { readdirPromise } from '../helpers/core-utils' | ||
6 | import { execCLI } from '../tests/utils/index' | ||
7 | |||
8 | program | ||
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 | |||
19 | if ( | ||
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 | |||
32 | if (isAbsolute(program['input']) === false) { | ||
33 | throw new Error('Input path should be absolute.') | ||
34 | } | ||
35 | |||
36 | let command = `npm run ts-node -- ${__dirname}/get-access-token.ts` | ||
37 | command += ` -u "${program['url']}"` | ||
38 | command += ` -n "${program['username']}"` | ||
39 | command += ` -p "${program['password']}"` | ||
40 | |||
41 | execCLI(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 | |||
80 | function list (val) { | ||
81 | return val.split(',') | ||
82 | } | ||