import { remove } from 'fs-extra'
import { truncate } from 'lodash'
import { join } from 'path'
-import * as prompt from 'prompt'
import { promisify } from 'util'
import { YoutubeDL } from '@server/helpers/youtube-dl'
-import { getVideoCategories, uploadVideo } from '../../shared/extra-utils/index'
import { sha256 } from '../helpers/core-utils'
import { doRequestAndSaveToFile } from '../helpers/requests'
import { CONSTRAINTS_FIELDS } from '../initializers/constants'
import {
+ assignToken,
buildCommonVideoOptions,
buildServer,
buildVideoAttributesFromCommander,
- getAccessTokenOrDie,
getLogger,
getServerCredentials
} from './cli'
+import { PeerTubeServer } from '@shared/extra-utils'
+
+import prompt = require('prompt')
const processOptions = {
maxBuffer: Infinity
}
const server = buildServer(url)
- const { data } = await server.searchCommand.advancedVideoSearch({
+ const { data } = await server.search.advancedVideoSearch({
search: {
search: videoInfo.title,
sort: '-match',
}) {
const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters
- const category = await getCategory(videoInfo.categories, url)
+ const server = buildServer(url)
+ await assignToken(server, username, password)
+
+ const category = await getCategory(server, videoInfo.categories)
const licence = getLicence(videoInfo.license)
let tags = []
if (Array.isArray(videoInfo.tags)) {
tags
}
- let accessToken = await getAccessTokenOrDie(url, username, password)
- const server = buildServer(url, accessToken)
+ const baseAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
- const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
+ const attributes = {
+ ...baseAttributes,
- Object.assign(videoAttributes, {
originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null,
thumbnailfile,
previewfile: thumbnailfile,
fixture: videoPath
- })
+ }
- log.info('\nUploading on PeerTube video "%s".', videoAttributes.name)
+ log.info('\nUploading on PeerTube video "%s".', attributes.name)
try {
- await uploadVideo(url, accessToken, videoAttributes)
+ await server.videos.upload({ attributes })
} catch (err) {
if (err.message.indexOf('401') !== -1) {
log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.')
- accessToken = await getAccessTokenOrDie(url, username, password)
+ server.accessToken = await server.login.getAccessToken(username, password)
- await uploadVideo(url, accessToken, videoAttributes)
+ await server.videos.upload({ attributes })
} else {
exitError(err.message)
}
await remove(videoPath)
if (thumbnailfile) await remove(thumbnailfile)
- log.warn('Uploaded video "%s"!\n', videoAttributes.name)
+ log.warn('Uploaded video "%s"!\n', attributes.name)
}
/* ---------------------------------------------------------- */
-async function getCategory (categories: string[], url: string) {
+async function getCategory (server: PeerTubeServer, categories: string[]) {
if (!categories) return undefined
const categoryString = categories[0]
if (categoryString === 'News & Politics') return 11
- const res = await getVideoCategories(url)
- const categoriesServer = res.body
+ const categoriesServer = await server.videos.getCategories()
for (const key of Object.keys(categoriesServer)) {
const categoryServer = categoriesServer[key]
return new Promise<any>((res, rej) => {
const options = [ '-j', '--flat-playlist', '--playlist-reverse', ...args ]
- youtubeDL.getInfo(url, options, processOptions, async (err, info) => {
+ youtubeDL.getInfo(url, options, processOptions, (err, info) => {
if (err) return rej(err)
return res(info)