diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-09-13 14:27:44 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2018-09-14 11:08:55 +0200 |
commit | 8704acf49efc770d73bf07c10468ed8c74d28a83 (patch) | |
tree | ffd46289fcf9a13ac4412b167e9f71dfb35753c5 /server/tools/upload.ts | |
parent | 1d9d9cfdcf3983e3fd89026bc4b5633a8abf5752 (diff) | |
download | PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.gz PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.zst PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.zip |
one cli to unite them all
Ash nazg thrakatulûk agh burzum-ishi krimpatul
- refactor import-videos to use the youtubeDL helper
- add very basic tests for the cli
Diffstat (limited to 'server/tools/upload.ts')
-rw-r--r-- | server/tools/upload.ts | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/server/tools/upload.ts b/server/tools/upload.ts deleted file mode 100644 index 9b104d308..000000000 --- a/server/tools/upload.ts +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | import * as program from 'commander' | ||
2 | import { access, constants } from 'fs-extra' | ||
3 | import { isAbsolute } from 'path' | ||
4 | import { getClient, login } from '../tests/utils' | ||
5 | import { uploadVideo } from '../tests/utils/index' | ||
6 | import { VideoPrivacy } from '../../shared/models/videos' | ||
7 | |||
8 | program | ||
9 | .option('-u, --url <url>', 'Server url') | ||
10 | .option('-U, --username <username>', 'Username') | ||
11 | .option('-p, --password <token>', 'Password') | ||
12 | .option('-n, --video-name <name>', 'Video name') | ||
13 | .option('-P, --privacy <privacy number>', 'Privacy') | ||
14 | .option('-N, --nsfw', 'Video is Not Safe For Work') | ||
15 | .option('-c, --category <category number>', 'Category number') | ||
16 | .option('-m, --comments-enabled', 'Enable comments') | ||
17 | .option('-l, --licence <licence number>', 'Licence number') | ||
18 | .option('-L, --language <language code>', 'Language ISO 639 code (fr or en...)') | ||
19 | .option('-d, --video-description <description>', 'Video description') | ||
20 | .option('-t, --tags <tags>', 'Video tags', list) | ||
21 | .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path') | ||
22 | .option('-v, --preview <previewPath>', 'Preview path') | ||
23 | .option('-f, --file <file>', 'Video absolute file path') | ||
24 | .parse(process.argv) | ||
25 | |||
26 | if (!program['tags']) program['tags'] = [] | ||
27 | if (!program['nsfw']) program['nsfw'] = false | ||
28 | if (!program['privacy']) program['privacy'] = VideoPrivacy.PUBLIC | ||
29 | if (!program['commentsEnabled']) program['commentsEnabled'] = false | ||
30 | |||
31 | if ( | ||
32 | !program['url'] || | ||
33 | !program['username'] || | ||
34 | !program['password'] || | ||
35 | !program['videoName'] || | ||
36 | !program['file'] | ||
37 | ) { | ||
38 | if (!program['url']) console.error('--url field is required.') | ||
39 | if (!program['username']) console.error('--username field is required.') | ||
40 | if (!program['password']) console.error('--password field is required.') | ||
41 | if (!program['videoName']) console.error('--video-name field is required.') | ||
42 | if (!program['file']) console.error('--file field is required.') | ||
43 | process.exit(-1) | ||
44 | } | ||
45 | |||
46 | if (isAbsolute(program['file']) === false) { | ||
47 | console.error('File path should be absolute.') | ||
48 | process.exit(-1) | ||
49 | } | ||
50 | |||
51 | run().catch(err => console.error(err)) | ||
52 | |||
53 | async function run () { | ||
54 | const res = await getClient(program[ 'url' ]) | ||
55 | const client = { | ||
56 | id: res.body.client_id, | ||
57 | secret: res.body.client_secret | ||
58 | } | ||
59 | |||
60 | const user = { | ||
61 | username: program[ 'username' ], | ||
62 | password: program[ 'password' ] | ||
63 | } | ||
64 | |||
65 | const res2 = await login(program[ 'url' ], client, user) | ||
66 | const accessToken = res2.body.access_token | ||
67 | |||
68 | await access(program[ 'file' ], constants.F_OK) | ||
69 | |||
70 | console.log('Uploading %s video...', program[ 'videoName' ]) | ||
71 | |||
72 | const videoAttributes = { | ||
73 | name: program['videoName'], | ||
74 | category: program['category'], | ||
75 | licence: program['licence'], | ||
76 | language: program['language'], | ||
77 | nsfw: program['nsfw'], | ||
78 | description: program['videoDescription'], | ||
79 | tags: program['tags'], | ||
80 | commentsEnabled: program['commentsEnabled'], | ||
81 | fixture: program['file'], | ||
82 | thumbnailfile: program['thumbnail'], | ||
83 | previewfile: program['preview'], | ||
84 | waitTranscoding: true, | ||
85 | privacy: program['privacy'], | ||
86 | support: undefined | ||
87 | } | ||
88 | |||
89 | await uploadVideo(program['url'], accessToken, videoAttributes) | ||
90 | |||
91 | console.log(`Video ${program['videoName']} uploaded.`) | ||
92 | process.exit(0) | ||
93 | } | ||
94 | |||
95 | // ---------------------------------------------------------------------------- | ||
96 | |||
97 | function list (val) { | ||
98 | return val.split(',') | ||
99 | } | ||