+// FIXME: https://github.com/nodejs/node/pull/16853
+require('tls').DEFAULT_ECDH_CURVE = 'auto'
+
import * as program from 'commander'
import { join } from 'path'
import * as youtubeDL from 'youtube-dl'
import { doRequestAndSaveToFile } from '../helpers/requests'
import { CONSTRAINTS_FIELDS } from '../initializers'
import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils'
+import { truncate } from 'lodash'
program
.option('-u, --url <url>', 'Server url')
const options = [ '-j', '--flat-playlist', '--playlist-reverse' ]
youtubeDL.getInfo(program['targetUrl'], options, processOptions, async (err, info) => {
if (err) {
- console.log(err.message);
- process.exit(1);
+ console.log(err.message)
+ process.exit(1)
}
let infoArray: any[]
await processVideo(info, program['language'])
}
- // https://www.youtube.com/watch?v=2Upx39TBc1s
console.log('I\'m finished!')
process.exit(0)
})
console.log('Downloading video "%s"...', videoInfo.title)
const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ]
- youtubeDL.exec(videoInfo.url, options, processOptions, async (err, output) => {
- if (err) return console.error(err)
-
- console.log(output.join('\n'))
-
- await uploadVideoOnPeerTube(normalizeObject(videoInfo), path, languageCode)
-
+ try {
+ youtubeDL.exec(videoInfo.url, options, processOptions, async (err, output) => {
+ if (err) {
+ console.error(err)
+ return res()
+ }
+
+ console.log(output.join('\n'))
+ await uploadVideoOnPeerTube(normalizeObject(videoInfo), path, languageCode)
+ return res()
+ })
+ } catch (err) {
+ console.log(err.message)
return res()
- })
+ }
})
}
}
const videoAttributes = {
- name: videoInfo.title,
+ name: truncate(videoInfo.title, {
+ 'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max,
+ 'separator': /,? +/,
+ 'omission': ' […]'
+ }),
category,
licence,
language,
nsfw: isNSFW(videoInfo),
commentsEnabled: true,
- description: videoInfo.description,
+ description: videoInfo.description || undefined,
support: undefined,
tags,
privacy: VideoPrivacy.PUBLIC,
await uploadVideo(program['url'], accessToken, videoAttributes)
} else {
- console.log(err.message);
- process.exit(1);
+ console.log(err.message)
+ process.exit(1)
}
}