diff options
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r-- | server/tools/cli.ts | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 6be558d7b..4aa3d9ce8 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | import { Netrc } from 'netrc-parser' | 1 | import { Netrc } from 'netrc-parser' |
2 | import { isTestInstance, getAppNumber } from '../helpers/core-utils' | 2 | import { getAppNumber, isTestInstance } from '../helpers/core-utils' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { root } from '../../shared/extra-utils' | 4 | import { getVideoChannel, root } from '../../shared/extra-utils' |
5 | import { Command } from 'commander' | ||
6 | import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' | ||
5 | 7 | ||
6 | let configName = 'PeerTube/CLI' | 8 | let configName = 'PeerTube/CLI' |
7 | if (isTestInstance()) configName += `-${getAppNumber()}` | 9 | if (isTestInstance()) configName += `-${getAppNumber()}` |
@@ -94,6 +96,64 @@ function getRemoteObjectOrDie (program: any, settings: Settings, netrc: Netrc) { | |||
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
99 | function buildCommonVideoOptions (command: Command) { | ||
100 | function list (val) { | ||
101 | return val.split(',') | ||
102 | } | ||
103 | |||
104 | return command | ||
105 | .option('-n, --video-name <name>', 'Video name') | ||
106 | .option('-c, --category <category_number>', 'Category number') | ||
107 | .option('-l, --licence <licence_number>', 'Licence number') | ||
108 | .option('-L, --language <language_code>', 'Language ISO 639 code (fr or en...)') | ||
109 | .option('-t, --tags <tags>', 'Video tags', list) | ||
110 | .option('-N, --nsfw', 'Video is Not Safe For Work') | ||
111 | .option('-d, --video-description <description>', 'Video description') | ||
112 | .option('-P, --privacy <privacy_number>', 'Privacy') | ||
113 | .option('-C, --channel-name <channel_name>', 'Channel name') | ||
114 | .option('-m, --comments-enabled', 'Enable comments') | ||
115 | .option('-s, --support <support>', 'Video support text') | ||
116 | .option('-w, --wait-transcoding', 'Wait transcoding before publishing the video') | ||
117 | } | ||
118 | |||
119 | async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any) { | ||
120 | const booleanAttributes: { [id: string]: boolean } = {} | ||
121 | |||
122 | for (const key of [ 'nsfw', 'commentsEnabled', 'downloadEnabled', 'waitTranscoding' ]) { | ||
123 | if (command[ key ] !== undefined) { | ||
124 | booleanAttributes[key] = command[ key ] | ||
125 | } else if (defaultAttributes[key] !== undefined) { | ||
126 | booleanAttributes[key] = defaultAttributes[key] | ||
127 | } else { | ||
128 | booleanAttributes[key] = false | ||
129 | } | ||
130 | } | ||
131 | |||
132 | const videoAttributes = { | ||
133 | name: command[ 'videoName' ] || defaultAttributes.name, | ||
134 | category: command[ 'category' ] || defaultAttributes.category || undefined, | ||
135 | licence: command[ 'licence' ] || defaultAttributes.licence || undefined, | ||
136 | language: command[ 'language' ] || defaultAttributes.language || undefined, | ||
137 | privacy: command[ 'privacy' ] || defaultAttributes.privacy || VideoPrivacy.PUBLIC, | ||
138 | support: command[ 'support' ] || defaultAttributes.support || undefined | ||
139 | } | ||
140 | |||
141 | Object.assign(videoAttributes, booleanAttributes) | ||
142 | |||
143 | if (command[ 'channelName' ]) { | ||
144 | const res = await getVideoChannel(url, command['channelName']) | ||
145 | const videoChannel: VideoChannel = res.body | ||
146 | |||
147 | Object.assign(videoAttributes, { channelId: videoChannel.id }) | ||
148 | |||
149 | if (!videoAttributes.support && videoChannel.support) { | ||
150 | Object.assign(videoAttributes, { support: videoChannel.support }) | ||
151 | } | ||
152 | } | ||
153 | |||
154 | return videoAttributes | ||
155 | } | ||
156 | |||
97 | // --------------------------------------------------------------------------- | 157 | // --------------------------------------------------------------------------- |
98 | 158 | ||
99 | export { | 159 | export { |
@@ -103,5 +163,8 @@ export { | |||
103 | getNetrc, | 163 | getNetrc, |
104 | getRemoteObjectOrDie, | 164 | getRemoteObjectOrDie, |
105 | writeSettings, | 165 | writeSettings, |
106 | deleteSettings | 166 | deleteSettings, |
167 | |||
168 | buildCommonVideoOptions, | ||
169 | buildVideoAttributesFromCommander | ||
107 | } | 170 | } |