Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Use default server values if not provided by CLI

Chocobozzz809eb622b2f4
diff --git a/apps/peertube-cli/src/peertube-upload.ts b/apps/peertube-cli/src/peertube-upload.ts
index ea23757f42..497478ac1a 100644
--- a/apps/peertube-cli/src/peertube-upload.ts
+++ b/apps/peertube-cli/src/peertube-upload.ts
@@ -1,84 +1,62 @@
import { Command } from '@commander-js/extra-typings'
import { VideoCommentPolicy, VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
-import { PeerTubeServer } from '@peertube/peertube-server-commands'
+import { PeerTubeServer, VideoEdit } from '@peertube/peertube-server-commands'
import { access, constants } from 'fs/promises'
import { isAbsolute } from 'path'
import { inspect } from 'util'
import { assignToken, buildServer, getServerCredentials, listOptions } from './shared/index.js'
-type UploadOptions = {
- url?: string
- username?: string
- password?: string
- thumbnail?: string
- file?: string
- videoName?: string
- category?: number
- licence?: number
- language?: string
- tags?: string[]
- nsfw?: true
- videoDescription?: string
- privacy?: VideoPrivacyType
- channelName?: string
- noCommentsEnabled?: true
- support?: string
- noWaitTranscoding?: true
- noDownloadEnabled?: true
-}
+const program = new Command('upload')
+ .description('Upload a video on a PeerTube instance')
+ .alias('up')
+ .option('-u, --url <url>', 'Server url')
+ .option('-U, --username <username>', 'Username')
+ .option('-p, --password <token>', 'Password')
+ .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
+ .option('-f, --file <file>', 'Video absolute file path')
+ .option('-n, --video-name <name>', 'Video name')
+ .option('-c, --category <category_number>', 'Category number', parseInt)
+ .option('-l, --licence <licence_number>', 'Licence number', parseInt)
+ .option('-L, --language <language_code>', 'Language ISO 639 code (fr or en...)')
+ .option('-t, --tags <tags>', 'Video tags', listOptions)
+ .option('-N, --nsfw', 'Video is Not Safe For Work')
+ .option('-d, --video-description <description>', 'Video description')
+ .option('-P, --privacy <privacy_number>', 'Privacy', v => parseInt(v) as VideoPrivacyType)
+ .option('-C, --channel-name <channel_name>', 'Channel name')
+ .option('--no-comments-enabled', 'Disable video comments')
+ .option('-s, --support <support>', 'Video support text')
+ .option('--no-wait-transcoding', 'Do not wait transcoding before publishing the video')
+ .option('--no-download-enabled', 'Disable video download')
+ .option('-v, --verbose <verbose>', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info')
export function defineUploadProgram () {
- const program = new Command('upload')
- .description('Upload a video on a PeerTube instance')
- .alias('up')
-
- program
- .option('-u, --url <url>', 'Server url')
- .option('-U, --username <username>', 'Username')
- .option('-p, --password <token>', 'Password')
- .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
- .option('-f, --file <file>', 'Video absolute file path')
- .option('-n, --video-name <name>', 'Video name')
- .option('-c, --category <category_number>', 'Category number', parseInt)
- .option('-l, --licence <licence_number>', 'Licence number', parseInt)
- .option('-L, --language <language_code>', 'Language ISO 639 code (fr or en...)')
- .option('-t, --tags <tags>', 'Video tags', listOptions)
- .option('-N, --nsfw', 'Video is Not Safe For Work')
- .option('-d, --video-description <description>', 'Video description')
- .option('-P, --privacy <privacy_number>', 'Privacy', v => parseInt(v) as VideoPrivacyType)
- .option('-C, --channel-name <channel_name>', 'Channel name')
- .option('--no-comments-enabled', 'Disable video comments')
- .option('-s, --support <support>', 'Video support text')
- .option('--no-wait-transcoding', 'Do not wait transcoding before publishing the video')
- .option('--no-download-enabled', 'Disable video download')
- .option('-v, --verbose <verbose>', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info')
- .action(async options => {
- try {
- const { url, username, password } = await getServerCredentials(options)
-
- if (!options.videoName || !options.file) {
- if (!options.videoName) console.error('--video-name is required.')
- if (!options.file) console.error('--file is required.')
-
- process.exit(-1)
- }
-
- if (isAbsolute(options.file) === false) {
- console.error('File path should be absolute.')
- process.exit(-1)
- }
-
- await run({ ...options, url, username, password })
- } catch (err) {
- if (err.code === 'ECONNREFUSED') {
- console.error(`Server is not responding`)
- } else {
- console.error('Cannot upload video: ' + err.message)
- }
+ program.action(async options => {
+ try {
+ const { url, username, password } = await getServerCredentials(options)
+
+ if (!options.videoName || !options.file) {
+ if (!options.videoName) console.error('--video-name is required.')
+ if (!options.file) console.error('--file is required.')
+
+ process.exit(-1)
+ }
+ if (isAbsolute(options.file) === false) {
+ console.error('File path should be absolute.')
process.exit(-1)
}
- })
+
+ await run({ ...options, url, username, password })
+ } catch (err) {
+ if (err.code === 'ECONNREFUSED') {
+ console.error(`Server is not responding`)
+ } else {
+ console.error('Cannot upload video: ' + err.message)
+ }
+
+ process.exit(-1)
+ }
+ })
return program
}
@@ -87,7 +65,7 @@ export function defineUploadProgram () {
// Private
// ---------------------------------------------------------------------------
-async function run (options: UploadOptions) {
+async function run (options: ReturnType<typeof program.opts>) {
const { url, username, password } = options
const server = buildServer(url)
@@ -122,24 +100,8 @@ async function run (options: UploadOptions) {
}
}
-async function buildVideoAttributesFromCommander (server: PeerTubeServer, options: UploadOptions) {
- const defaultBooleanAttributes = {
- nsfw: false,
- downloadEnabled: true,
- waitTranscoding: true
- }
-
- const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } = {} as any
-
- for (const key of Object.keys(defaultBooleanAttributes)) {
- if (options[key] !== undefined) {
- booleanAttributes[key] = options[key]
- } else {
- booleanAttributes[key] = defaultBooleanAttributes[key]
- }
- }
-
- const videoAttributes = {
+async function buildVideoAttributesFromCommander (server: PeerTubeServer, options: ReturnType<typeof program.opts>) {
+ const videoAttributes: VideoEdit = {
name: options.videoName,
category: options.category || undefined,
licence: options.licence || undefined,
@@ -149,13 +111,17 @@ async function buildVideoAttributesFromCommander (server: PeerTubeServer, option
description: options.videoDescription || undefined,
tags: options.tags || undefined,
- commentsPolicy: options.noCommentsEnabled !== undefined
- ? options.noCommentsEnabled === true
- ? VideoCommentPolicy.DISABLED
- : VideoCommentPolicy.ENABLED
+ commentsPolicy: options.commentsEnabled === false
+ ? VideoCommentPolicy.DISABLED
: undefined,
- ...booleanAttributes
+ nsfw: options.nsfw,
+ downloadEnabled: options.downloadEnabled === false
+ ? false
+ : undefined,
+ waitTranscoding: options.waitTranscoding === false
+ ? false
+ : undefined
}
if (options.channelName) {