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.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.ts')
-rw-r--r-- | server/tools/upload.ts | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/server/tools/upload.ts b/server/tools/upload.ts new file mode 100644 index 000000000..db59bbdff --- /dev/null +++ b/server/tools/upload.ts | |||
@@ -0,0 +1,85 @@ | |||
1 | import * as program from 'commander' | ||
2 | import { access, constants } from 'fs' | ||
3 | import { isAbsolute } from 'path' | ||
4 | import { promisify } from 'util' | ||
5 | |||
6 | const accessPromise = promisify(access) | ||
7 | |||
8 | import { uploadVideo } from '../tests/utils/index' | ||
9 | |||
10 | program | ||
11 | .option('-u, --url <url>', 'Server url') | ||
12 | .option('-a, --access-token <token>', 'Access token') | ||
13 | .option('-n, --name <name>', 'Video name') | ||
14 | .option('-N, --nsfw', 'Video is Not Safe For Work') | ||
15 | .option('-c, --category <category number>', 'Category number') | ||
16 | .option('-l, --licence <licence number>', 'Licence number') | ||
17 | .option('-L, --language <language number>', 'Language number') | ||
18 | .option('-d, --description <description>', 'Video description') | ||
19 | .option('-t, --tags <tags>', 'Video tags', list) | ||
20 | .option('-f, --file <file>', 'Video absolute file path') | ||
21 | .parse(process.argv) | ||
22 | |||
23 | if (!program['tags']) program['tags'] = [] | ||
24 | if (!program['nsfw']) program['nsfw'] = false | ||
25 | |||
26 | if ( | ||
27 | !program['url'] || | ||
28 | !program['accessToken'] || | ||
29 | !program['name'] || | ||
30 | !program['category'] || | ||
31 | !program['licence'] || | ||
32 | !program['description'] || | ||
33 | !program['file'] | ||
34 | ) { | ||
35 | throw new Error('All arguments but tags, language and nsfw are required.') | ||
36 | } | ||
37 | |||
38 | if (isAbsolute(program['file']) === false) { | ||
39 | throw new Error('File path should be absolute.') | ||
40 | } | ||
41 | |||
42 | accessPromise(program['file'], constants.F_OK) | ||
43 | .then(() => { | ||
44 | return upload( | ||
45 | program['url'], | ||
46 | program['accessToken'], | ||
47 | program['name'], | ||
48 | program['category'], | ||
49 | program['licence'], | ||
50 | program['language'], | ||
51 | program['nsfw'], | ||
52 | program['description'], | ||
53 | program['tags'], | ||
54 | program['file'] | ||
55 | ) | ||
56 | }) | ||
57 | .then(() => process.exit(0)) | ||
58 | .catch(err => { | ||
59 | console.error(err) | ||
60 | process.exit(-1) | ||
61 | }) | ||
62 | |||
63 | // ---------------------------------------------------------------------------- | ||
64 | |||
65 | function list (val) { | ||
66 | return val.split(',') | ||
67 | } | ||
68 | |||
69 | function upload (url, accessToken, name, category, licence, language, nsfw, description, tags, fixture) { | ||
70 | console.log('Uploading %s video...', program['name']) | ||
71 | |||
72 | const videoAttributes = { | ||
73 | name, | ||
74 | category, | ||
75 | licence, | ||
76 | language, | ||
77 | nsfw, | ||
78 | description, | ||
79 | tags, | ||
80 | fixture | ||
81 | } | ||
82 | return uploadVideo(url, accessToken, videoAttributes).then(() => { | ||
83 | console.log(`Video ${name} uploaded.`) | ||
84 | }) | ||
85 | } | ||