diff options
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r-- | server/tools/peertube-import-videos.ts | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index f9cd3106a..d7bb00e02 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts | |||
@@ -3,7 +3,6 @@ require('tls').DEFAULT_ECDH_CURVE = 'auto' | |||
3 | 3 | ||
4 | import * as program from 'commander' | 4 | import * as program from 'commander' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { VideoPrivacy } from '../../shared/models/videos' | ||
7 | import { doRequestAndSaveToFile } from '../helpers/requests' | 6 | import { doRequestAndSaveToFile } from '../helpers/requests' |
8 | import { CONSTRAINTS_FIELDS } from '../initializers/constants' | 7 | import { CONSTRAINTS_FIELDS } from '../initializers/constants' |
9 | import { getClient, getVideoCategories, login, searchVideoWithSort, uploadVideo } from '../../shared/extra-utils/index' | 8 | import { getClient, getVideoCategories, login, searchVideoWithSort, uploadVideo } from '../../shared/extra-utils/index' |
@@ -12,7 +11,7 @@ import * as prompt from 'prompt' | |||
12 | import { remove } from 'fs-extra' | 11 | import { remove } from 'fs-extra' |
13 | import { sha256 } from '../helpers/core-utils' | 12 | import { sha256 } from '../helpers/core-utils' |
14 | import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl' | 13 | import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl' |
15 | import { getNetrc, getRemoteObjectOrDie, getSettings } from './cli' | 14 | import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getNetrc, getRemoteObjectOrDie, getSettings } from './cli' |
16 | 15 | ||
17 | type UserInfo = { | 16 | type UserInfo = { |
18 | username: string | 17 | username: string |
@@ -24,14 +23,16 @@ const processOptions = { | |||
24 | maxBuffer: Infinity | 23 | maxBuffer: Infinity |
25 | } | 24 | } |
26 | 25 | ||
27 | program | 26 | let command = program |
28 | .name('import-videos') | 27 | .name('import-videos') |
28 | |||
29 | command = buildCommonVideoOptions(command) | ||
30 | |||
31 | command | ||
29 | .option('-u, --url <url>', 'Server url') | 32 | .option('-u, --url <url>', 'Server url') |
30 | .option('-U, --username <username>', 'Username') | 33 | .option('-U, --username <username>', 'Username') |
31 | .option('-p, --password <token>', 'Password') | 34 | .option('-p, --password <token>', 'Password') |
32 | .option('-t, --target-url <targetUrl>', 'Video target URL') | 35 | .option('-t, --target-url <targetUrl>', 'Video target URL') |
33 | .option('-C, --channel-id <channel_id>', 'Channel ID') | ||
34 | .option('-l, --language <languageCode>', 'Language ISO 639 code (fr or en...)') | ||
35 | .option('-v, --verbose', 'Verbose mode') | 36 | .option('-v, --verbose', 'Verbose mode') |
36 | .parse(process.argv) | 37 | .parse(process.argv) |
37 | 38 | ||
@@ -179,7 +180,7 @@ async function uploadVideoOnPeerTube (parameters: { | |||
179 | 180 | ||
180 | const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo) | 181 | const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo) |
181 | 182 | ||
182 | const videoAttributes = { | 183 | const defaultAttributes = { |
183 | name: truncate(videoInfo.title, { | 184 | name: truncate(videoInfo.title, { |
184 | 'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max, | 185 | 'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max, |
185 | 'separator': /,? +/, | 186 | 'separator': /,? +/, |
@@ -187,24 +188,19 @@ async function uploadVideoOnPeerTube (parameters: { | |||
187 | }), | 188 | }), |
188 | category, | 189 | category, |
189 | licence, | 190 | licence, |
190 | language: program[ 'language' ], | ||
191 | nsfw: isNSFW(videoInfo), | 191 | nsfw: isNSFW(videoInfo), |
192 | waitTranscoding: true, | 192 | description: videoInfo.description, |
193 | commentsEnabled: true, | 193 | tags |
194 | downloadEnabled: true, | ||
195 | description: videoInfo.description || undefined, | ||
196 | support: undefined, | ||
197 | tags, | ||
198 | privacy: VideoPrivacy.PUBLIC, | ||
199 | fixture: videoPath, | ||
200 | thumbnailfile, | ||
201 | previewfile: thumbnailfile, | ||
202 | originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null | ||
203 | } | 194 | } |
204 | 195 | ||
205 | if (program[ 'channelId' ]) { | 196 | const videoAttributes = await buildVideoAttributesFromCommander(url, program, defaultAttributes) |
206 | Object.assign(videoAttributes, { channelId: program['channelId'] }) | 197 | |
207 | } | 198 | Object.assign(videoAttributes, { |
199 | originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null, | ||
200 | thumbnailfile, | ||
201 | previewfile: thumbnailfile, | ||
202 | fixture: videoPath | ||
203 | }) | ||
208 | 204 | ||
209 | console.log('\nUploading on PeerTube video "%s".', videoAttributes.name) | 205 | console.log('\nUploading on PeerTube video "%s".', videoAttributes.name) |
210 | 206 | ||