diff options
Diffstat (limited to 'server/tools/peertube-upload.ts')
-rw-r--r-- | server/tools/peertube-upload.ts | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts index bfce10e54..1da52da31 100644 --- a/server/tools/peertube-upload.ts +++ b/server/tools/peertube-upload.ts | |||
@@ -4,7 +4,7 @@ import { isAbsolute } from 'path' | |||
4 | import { getClient, login } from '../../shared/extra-utils' | 4 | import { getClient, login } from '../../shared/extra-utils' |
5 | import { uploadVideo } from '../../shared/extra-utils/' | 5 | import { uploadVideo } from '../../shared/extra-utils/' |
6 | import { VideoPrivacy } from '../../shared/models/videos' | 6 | import { VideoPrivacy } from '../../shared/models/videos' |
7 | import { getRemoteObjectOrDie, getSettings } from './cli' | 7 | import { getNetrc, getRemoteObjectOrDie, getSettings } from './cli' |
8 | 8 | ||
9 | program | 9 | program |
10 | .name('upload') | 10 | .name('upload') |
@@ -26,31 +26,31 @@ program | |||
26 | .option('-f, --file <file>', 'Video absolute file path') | 26 | .option('-f, --file <file>', 'Video absolute file path') |
27 | .parse(process.argv) | 27 | .parse(process.argv) |
28 | 28 | ||
29 | getSettings() | 29 | Promise.all([ getSettings(), getNetrc() ]) |
30 | .then(settings => { | 30 | .then(([ settings, netrc ]) => { |
31 | const { url, username, password } = getRemoteObjectOrDie(program, settings) | 31 | const { url, username, password } = getRemoteObjectOrDie(program, settings, netrc) |
32 | 32 | ||
33 | if (!program['videoName'] || !program['file'] || !program['channelId']) { | 33 | if (!program[ 'videoName' ] || !program[ 'file' ] || !program[ 'channelId' ]) { |
34 | if (!program['videoName']) console.error('--video-name is required.') | 34 | if (!program[ 'videoName' ]) console.error('--video-name is required.') |
35 | if (!program['file']) console.error('--file is required.') | 35 | if (!program[ 'file' ]) console.error('--file is required.') |
36 | if (!program['channelId']) console.error('--channel-id is required.') | 36 | if (!program[ 'channelId' ]) console.error('--channel-id is required.') |
37 | 37 | ||
38 | process.exit(-1) | 38 | process.exit(-1) |
39 | } | 39 | } |
40 | 40 | ||
41 | if (isAbsolute(program['file']) === false) { | 41 | if (isAbsolute(program[ 'file' ]) === false) { |
42 | console.error('File path should be absolute.') | 42 | console.error('File path should be absolute.') |
43 | process.exit(-1) | 43 | process.exit(-1) |
44 | } | 44 | } |
45 | 45 | ||
46 | run(url, username, password).catch(err => { | 46 | run(url, username, password).catch(err => { |
47 | console.error(err) | 47 | console.error(err) |
48 | process.exit(-1) | 48 | process.exit(-1) |
49 | }) | 49 | }) |
50 | }) | 50 | }) |
51 | 51 | ||
52 | async function run (url: string, username: string, password: string) { | 52 | async function run (url: string, username: string, password: string) { |
53 | const resClient = await getClient(program[ 'url' ]) | 53 | const resClient = await getClient(url) |
54 | const client = { | 54 | const client = { |
55 | id: resClient.body.client_id, | 55 | id: resClient.body.client_id, |
56 | secret: resClient.body.client_secret | 56 | secret: resClient.body.client_secret |
@@ -71,27 +71,27 @@ async function run (url: string, username: string, password: string) { | |||
71 | console.log('Uploading %s video...', program[ 'videoName' ]) | 71 | console.log('Uploading %s video...', program[ 'videoName' ]) |
72 | 72 | ||
73 | const videoAttributes = { | 73 | const videoAttributes = { |
74 | name: program['videoName'], | 74 | name: program[ 'videoName' ], |
75 | category: program['category'] || undefined, | 75 | category: program[ 'category' ] || undefined, |
76 | channelId: program['channelId'], | 76 | channelId: program[ 'channelId' ], |
77 | licence: program['licence'] || undefined, | 77 | licence: program[ 'licence' ] || undefined, |
78 | language: program['language'] || undefined, | 78 | language: program[ 'language' ] || undefined, |
79 | nsfw: program['nsfw'] !== undefined ? program['nsfw'] : false, | 79 | nsfw: program[ 'nsfw' ] !== undefined ? program[ 'nsfw' ] : false, |
80 | description: program['videoDescription'] || undefined, | 80 | description: program[ 'videoDescription' ] || undefined, |
81 | tags: program['tags'] || [], | 81 | tags: program[ 'tags' ] || [], |
82 | commentsEnabled: program['commentsEnabled'] !== undefined ? program['commentsEnabled'] : true, | 82 | commentsEnabled: program[ 'commentsEnabled' ] !== undefined ? program[ 'commentsEnabled' ] : true, |
83 | downloadEnabled: program['downloadEnabled'] !== undefined ? program['downloadEnabled'] : true, | 83 | downloadEnabled: program[ 'downloadEnabled' ] !== undefined ? program[ 'downloadEnabled' ] : true, |
84 | fixture: program['file'], | 84 | fixture: program[ 'file' ], |
85 | thumbnailfile: program['thumbnail'], | 85 | thumbnailfile: program[ 'thumbnail' ], |
86 | previewfile: program['preview'], | 86 | previewfile: program[ 'preview' ], |
87 | waitTranscoding: true, | 87 | waitTranscoding: true, |
88 | privacy: program['privacy'] || VideoPrivacy.PUBLIC, | 88 | privacy: program[ 'privacy' ] || VideoPrivacy.PUBLIC, |
89 | support: undefined | 89 | support: undefined |
90 | } | 90 | } |
91 | 91 | ||
92 | try { | 92 | try { |
93 | await uploadVideo(url, accessToken, videoAttributes) | 93 | await uploadVideo(url, accessToken, videoAttributes) |
94 | console.log(`Video ${program['videoName']} uploaded.`) | 94 | console.log(`Video ${program[ 'videoName' ]} uploaded.`) |
95 | process.exit(0) | 95 | process.exit(0) |
96 | } catch (err) { | 96 | } catch (err) { |
97 | console.error(require('util').inspect(err)) | 97 | console.error(require('util').inspect(err)) |