aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-import-videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-15 10:02:54 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitd23dd9fbfc4d26026352c10f81d2795ceaf2908a (patch)
treeda82286d423c5e834a1ee2dcd5970076b8263cf1 /server/tools/peertube-import-videos.ts
parent7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (diff)
downloadPeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.gz
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.zst
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.zip
Introduce videos command
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r--server/tools/peertube-import-videos.ts29
1 files changed, 15 insertions, 14 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index 0a4d6fa6e..fc76735b9 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -9,7 +9,6 @@ import { join } from 'path'
9import * as prompt from 'prompt' 9import * as prompt from 'prompt'
10import { promisify } from 'util' 10import { promisify } from 'util'
11import { YoutubeDL } from '@server/helpers/youtube-dl' 11import { YoutubeDL } from '@server/helpers/youtube-dl'
12import { getVideoCategories, uploadVideo } from '../../shared/extra-utils/index'
13import { sha256 } from '../helpers/core-utils' 12import { sha256 } from '../helpers/core-utils'
14import { doRequestAndSaveToFile } from '../helpers/requests' 13import { doRequestAndSaveToFile } from '../helpers/requests'
15import { CONSTRAINTS_FIELDS } from '../initializers/constants' 14import { CONSTRAINTS_FIELDS } from '../initializers/constants'
@@ -21,6 +20,7 @@ import {
21 getLogger, 20 getLogger,
22 getServerCredentials 21 getServerCredentials
23} from './cli' 22} from './cli'
23import { ServerInfo } from '@shared/extra-utils'
24 24
25const processOptions = { 25const processOptions = {
26 maxBuffer: Infinity 26 maxBuffer: Infinity
@@ -200,7 +200,10 @@ async function uploadVideoOnPeerTube (parameters: {
200}) { 200}) {
201 const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters 201 const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters
202 202
203 const category = await getCategory(videoInfo.categories, url) 203 const server = buildServer(url)
204 await assignToken(server, username, password)
205
206 const category = await getCategory(server, videoInfo.categories)
204 const licence = getLicence(videoInfo.license) 207 const licence = getLicence(videoInfo.license)
205 let tags = [] 208 let tags = []
206 if (Array.isArray(videoInfo.tags)) { 209 if (Array.isArray(videoInfo.tags)) {
@@ -232,29 +235,28 @@ async function uploadVideoOnPeerTube (parameters: {
232 tags 235 tags
233 } 236 }
234 237
235 const server = buildServer(url) 238 const baseAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
236 await assignToken(server, username, password)
237 239
238 const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes) 240 const attributes = {
241 ...baseAttributes,
239 242
240 Object.assign(videoAttributes, {
241 originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null, 243 originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null,
242 thumbnailfile, 244 thumbnailfile,
243 previewfile: thumbnailfile, 245 previewfile: thumbnailfile,
244 fixture: videoPath 246 fixture: videoPath
245 }) 247 }
246 248
247 log.info('\nUploading on PeerTube video "%s".', videoAttributes.name) 249 log.info('\nUploading on PeerTube video "%s".', attributes.name)
248 250
249 try { 251 try {
250 await uploadVideo(url, server.accessToken, videoAttributes) 252 await server.videosCommand.upload({ attributes })
251 } catch (err) { 253 } catch (err) {
252 if (err.message.indexOf('401') !== -1) { 254 if (err.message.indexOf('401') !== -1) {
253 log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.') 255 log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.')
254 256
255 server.accessToken = await server.loginCommand.getAccessToken(username, password) 257 server.accessToken = await server.loginCommand.getAccessToken(username, password)
256 258
257 await uploadVideo(url, server.accessToken, videoAttributes) 259 await server.videosCommand.upload({ attributes })
258 } else { 260 } else {
259 exitError(err.message) 261 exitError(err.message)
260 } 262 }
@@ -263,20 +265,19 @@ async function uploadVideoOnPeerTube (parameters: {
263 await remove(videoPath) 265 await remove(videoPath)
264 if (thumbnailfile) await remove(thumbnailfile) 266 if (thumbnailfile) await remove(thumbnailfile)
265 267
266 log.warn('Uploaded video "%s"!\n', videoAttributes.name) 268 log.warn('Uploaded video "%s"!\n', attributes.name)
267} 269}
268 270
269/* ---------------------------------------------------------- */ 271/* ---------------------------------------------------------- */
270 272
271async function getCategory (categories: string[], url: string) { 273async function getCategory (server: ServerInfo, categories: string[]) {
272 if (!categories) return undefined 274 if (!categories) return undefined
273 275
274 const categoryString = categories[0] 276 const categoryString = categories[0]
275 277
276 if (categoryString === 'News & Politics') return 11 278 if (categoryString === 'News & Politics') return 11
277 279
278 const res = await getVideoCategories(url) 280 const categoriesServer = await server.videosCommand.getCategories()
279 const categoriesServer = res.body
280 281
281 for (const key of Object.keys(categoriesServer)) { 282 for (const key of Object.keys(categoriesServer)) {
282 const categoryServer = categoriesServer[key] 283 const categoryServer = categoriesServer[key]