1
0
Fork 0

Fix video import CLI script

Password is an optional argument
This commit is contained in:
Chocobozzz 2019-04-24 16:51:25 +02:00
parent cbe94af85a
commit e8a739e880
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 9 additions and 19 deletions

View file

@ -11,7 +11,7 @@ import { truncate } from 'lodash'
import * as prompt from 'prompt' import * as prompt from 'prompt'
import { remove } from 'fs-extra' import { remove } from 'fs-extra'
import { sha256 } from '../helpers/core-utils' import { sha256 } from '../helpers/core-utils'
import { safeGetYoutubeDL, buildOriginallyPublishedAt } from '../helpers/youtube-dl' import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl'
import { getSettings, netrc } from './cli' import { getSettings, netrc } from './cli'
let accessToken: string let accessToken: string
@ -34,29 +34,19 @@ program
getSettings() getSettings()
.then(settings => { .then(settings => {
if ( if ((!program['url'] || !program['username'] || !program['targetUrl']) && settings.remotes.length === 0) {
(!program['url'] ||
!program['username'] ||
!program['password']) &&
(settings.remotes.length === 0)
) {
if (!program['url']) console.error('--url field is required.') if (!program['url']) console.error('--url field is required.')
if (!program['username']) console.error('--username field is required.') if (!program['username']) console.error('--username field is required.')
if (!program['password']) console.error('--password field is required.')
if (!program['targetUrl']) console.error('--targetUrl field is required.') if (!program['targetUrl']) console.error('--targetUrl field is required.')
process.exit(-1) process.exit(-1)
} }
if ( if ((!program[ 'url' ] || !program[ 'username' ]) && settings.remotes.length > 0) {
(!program['url'] ||
!program['username'] ||
!program['password']) &&
(settings.remotes.length > 0)
) {
if (!program[ 'url' ]) { if (!program[ 'url' ]) {
program['url'] = (settings.default !== -1) ? program[ 'url' ] = settings.default !== -1
settings.remotes[settings.default] : ? settings.remotes[ settings.default ]
settings.remotes[0] : settings.remotes[ 0 ]
} }
if (!program['username']) program['username'] = netrc.machines[program['url']].login if (!program['username']) program['username'] = netrc.machines[program['url']].login

View file

@ -120,7 +120,7 @@ $ node dist/server/tools/peertube-import-videos.js \
* `PEERTUBE_URL` : the full URL of your PeerTube server where you want to import, eg: https://peertube.cpy.re * `PEERTUBE_URL` : the full URL of your PeerTube server where you want to import, eg: https://peertube.cpy.re
* `PEERTUBE_USER` : your PeerTube account where videos will be uploaded * `PEERTUBE_USER` : your PeerTube account where videos will be uploaded
* `PEERTUBE_PASSWORD` : password of your PeerTube account (if `PEERTUBE_PASSWORD` is omitted, you will be prompted for it) * `PEERTUBE_PASSWORD` : password of your PeerTube account (if `--password PEERTUBE_PASSWORD` is omitted, you will be prompted for it)
* `TARGET_URL` : the target url you want to import. Examples: * `TARGET_URL` : the target url you want to import. Examples:
* YouTube: * YouTube:
* Channel: https://www.youtube.com/channel/ChannelId * Channel: https://www.youtube.com/channel/ChannelId