aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-upload.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-06-13 13:53:28 +0200
committerChocobozzz <me@florianbigard.com>2019-06-13 13:53:28 +0200
commit1205823fece15f249e0dbad42e096cf9b81c3ba5 (patch)
treec1291b443aa530cc37cd9389620186ec2043e441 /server/tools/peertube-upload.ts
parent1a12f66d631d28a5a58ebbcd274426f2e6e5d203 (diff)
downloadPeerTube-1205823fece15f249e0dbad42e096cf9b81c3ba5.tar.gz
PeerTube-1205823fece15f249e0dbad42e096cf9b81c3ba5.tar.zst
PeerTube-1205823fece15f249e0dbad42e096cf9b81c3ba5.zip
Add ability to override CLI import attributes
Diffstat (limited to 'server/tools/peertube-upload.ts')
-rw-r--r--server/tools/peertube-upload.ts52
1 files changed, 17 insertions, 35 deletions
diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts
index 1da52da31..c00205e8f 100644
--- a/server/tools/peertube-upload.ts
+++ b/server/tools/peertube-upload.ts
@@ -3,24 +3,18 @@ import { access, constants } from 'fs-extra'
3import { isAbsolute } from 'path' 3import { isAbsolute } from 'path'
4import { getClient, login } from '../../shared/extra-utils' 4import { getClient, login } from '../../shared/extra-utils'
5import { uploadVideo } from '../../shared/extra-utils/' 5import { uploadVideo } from '../../shared/extra-utils/'
6import { VideoPrivacy } from '../../shared/models/videos' 6import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getNetrc, getRemoteObjectOrDie, getSettings } from './cli'
7import { getNetrc, getRemoteObjectOrDie, getSettings } from './cli'
8 7
9program 8let command = program
10 .name('upload') 9 .name('upload')
10
11command = buildCommonVideoOptions(command)
12
13command
14
11 .option('-u, --url <url>', 'Server url') 15 .option('-u, --url <url>', 'Server url')
12 .option('-U, --username <username>', 'Username') 16 .option('-U, --username <username>', 'Username')
13 .option('-p, --password <token>', 'Password') 17 .option('-p, --password <token>', 'Password')
14 .option('-n, --video-name <name>', 'Video name')
15 .option('-P, --privacy <privacy_number>', 'Privacy')
16 .option('-N, --nsfw', 'Video is Not Safe For Work')
17 .option('-c, --category <category_number>', 'Category number')
18 .option('-C, --channel-id <channel_id>', 'Channel ID')
19 .option('-m, --comments-enabled', 'Enable comments')
20 .option('-l, --licence <licence_number>', 'Licence number')
21 .option('-L, --language <language_code>', 'Language ISO 639 code (fr or en...)')
22 .option('-d, --video-description <description>', 'Video description')
23 .option('-t, --tags <tags>', 'Video tags', list)
24 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path') 18 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
25 .option('-v, --preview <previewPath>', 'Preview path') 19 .option('-v, --preview <previewPath>', 'Preview path')
26 .option('-f, --file <file>', 'Video absolute file path') 20 .option('-f, --file <file>', 'Video absolute file path')
@@ -30,10 +24,9 @@ Promise.all([ getSettings(), getNetrc() ])
30 .then(([ settings, netrc ]) => { 24 .then(([ settings, netrc ]) => {
31 const { url, username, password } = getRemoteObjectOrDie(program, settings, netrc) 25 const { url, username, password } = getRemoteObjectOrDie(program, settings, netrc)
32 26
33 if (!program[ 'videoName' ] || !program[ 'file' ] || !program[ 'channelId' ]) { 27 if (!program[ 'videoName' ] || !program[ 'file' ]) {
34 if (!program[ 'videoName' ]) console.error('--video-name is required.') 28 if (!program[ 'videoName' ]) console.error('--video-name is required.')
35 if (!program[ 'file' ]) console.error('--file is required.') 29 if (!program[ 'file' ]) console.error('--file is required.')
36 if (!program[ 'channelId' ]) console.error('--channel-id is required.')
37 30
38 process.exit(-1) 31 process.exit(-1)
39 } 32 }
@@ -70,24 +63,17 @@ async function run (url: string, username: string, password: string) {
70 63
71 console.log('Uploading %s video...', program[ 'videoName' ]) 64 console.log('Uploading %s video...', program[ 'videoName' ])
72 65
73 const videoAttributes = { 66 const defaultAttributes = {
74 name: program[ 'videoName' ], 67 tags: command[ 'tags' ],
75 category: program[ 'category' ] || undefined, 68 description: command[ 'videoDescription' ]
76 channelId: program[ 'channelId' ], 69 }
77 licence: program[ 'licence' ] || undefined, 70 const videoAttributes = await buildVideoAttributesFromCommander(url, program, defaultAttributes)
78 language: program[ 'language' ] || undefined, 71
79 nsfw: program[ 'nsfw' ] !== undefined ? program[ 'nsfw' ] : false, 72 Object.assign(videoAttributes, {
80 description: program[ 'videoDescription' ] || undefined,
81 tags: program[ 'tags' ] || [],
82 commentsEnabled: program[ 'commentsEnabled' ] !== undefined ? program[ 'commentsEnabled' ] : true,
83 downloadEnabled: program[ 'downloadEnabled' ] !== undefined ? program[ 'downloadEnabled' ] : true,
84 fixture: program[ 'file' ], 73 fixture: program[ 'file' ],
85 thumbnailfile: program[ 'thumbnail' ], 74 thumbnailfile: program[ 'thumbnail' ],
86 previewfile: program[ 'preview' ], 75 previewfile: program[ 'preview' ]
87 waitTranscoding: true, 76 })
88 privacy: program[ 'privacy' ] || VideoPrivacy.PUBLIC,
89 support: undefined
90 }
91 77
92 try { 78 try {
93 await uploadVideo(url, accessToken, videoAttributes) 79 await uploadVideo(url, accessToken, videoAttributes)
@@ -100,7 +86,3 @@ async function run (url: string, username: string, password: string) {
100} 86}
101 87
102// ---------------------------------------------------------------------------- 88// ----------------------------------------------------------------------------
103
104function list (val) {
105 return val.split(',')
106}