import { registerTSPaths } from '../helpers/register-ts-paths'
registerTSPaths()
-import * as program from 'commander'
+import { program } from 'commander'
import { accessSync, constants } from 'fs'
import { remove } from 'fs-extra'
import { truncate } from 'lodash'
import { advancedVideosSearch, getClient, getVideoCategories, login, uploadVideo } from '../../shared/extra-utils/index'
import { sha256 } from '../helpers/core-utils'
import { doRequestAndSaveToFile } from '../helpers/requests'
-import { buildOriginallyPublishedAt, getYoutubeDLVideoFormat, safeGetYoutubeDL } from '../helpers/youtube-dl'
import { CONSTRAINTS_FIELDS } from '../initializers/constants'
import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getLogger, getServerCredentials } from './cli'
+import { YoutubeDL } from '@server/helpers/youtube-dl'
type UserInfo = {
username: string
user.password = await promptPassword()
}
- const youtubeDL = await safeGetYoutubeDL()
+ const youtubeDLBinary = await YoutubeDL.safeGetYoutubeDL()
- let info = await getYoutubeDLInfo(youtubeDL, options.targetUrl, command.args)
+ let info = await getYoutubeDLInfo(youtubeDLBinary, options.targetUrl, command.args)
if (!Array.isArray(info)) info = [ info ]
if (uploadsObject) {
console.log('Fixing URL to %s.', uploadsObject.url)
- info = await getYoutubeDLInfo(youtubeDL, uploadsObject.url, command.args)
+ info = await getYoutubeDLInfo(youtubeDLBinary, uploadsObject.url, command.args)
}
let infoArray: any[]
youtubeInfo: any
}) {
const { youtubeInfo, cwd, url, user } = parameters
+ const youtubeDL = new YoutubeDL('', [])
log.debug('Fetching object.', youtubeInfo)
const videoInfo = await fetchObject(youtubeInfo)
log.debug('Fetched object.', videoInfo)
- const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo)
+ const originallyPublishedAt = youtubeDL.buildOriginallyPublishedAt(videoInfo)
if (options.since && originallyPublishedAt && originallyPublishedAt.getTime() < options.since.getTime()) {
log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
videoInfo.title, formatDate(options.since))
log.info('Downloading video "%s"...', videoInfo.title)
- const youtubeDLOptions = [ '-f', getYoutubeDLVideoFormat(), ...command.args, '-o', path ]
+ const youtubeDLOptions = [ '-f', youtubeDL.getYoutubeDLVideoFormat(), ...command.args, '-o', path ]
try {
- const youtubeDL = await safeGetYoutubeDL()
- const youtubeDLExec = promisify(youtubeDL.exec).bind(youtubeDL)
+ const youtubeDLBinary = await YoutubeDL.safeGetYoutubeDL()
+ const youtubeDLExec = promisify(youtubeDLBinary.exec).bind(youtubeDLBinary)
const output = await youtubeDLExec(videoInfo.url, youtubeDLOptions, processOptions)
log.info(output.join('\n'))
await uploadVideoOnPeerTube({
+ youtubeDL,
cwd,
url,
user,
}
async function uploadVideoOnPeerTube (parameters: {
+ youtubeDL: YoutubeDL
videoInfo: any
videoPath: string
cwd: string
url: string
user: { username: string, password: string }
}) {
- const { videoInfo, videoPath, cwd, url, user } = parameters
+ const { youtubeDL, videoInfo, videoPath, cwd, url, user } = parameters
const category = await getCategory(videoInfo.categories, url)
const licence = getLicence(videoInfo.license)
await doRequestAndSaveToFile(videoInfo.thumbnail, thumbnailfile)
}
- const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo)
+ const originallyPublishedAt = youtubeDL.buildOriginallyPublishedAt(videoInfo)
const defaultAttributes = {
name: truncate(videoInfo.title, {
const url = buildUrl(info)
return new Promise<any>(async (res, rej) => {
- const youtubeDL = await safeGetYoutubeDL()
+ const youtubeDL = await YoutubeDL.safeGetYoutubeDL()
youtubeDL.getInfo(url, undefined, processOptions, (err, videoInfo) => {
if (err) return rej(err)