X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fimport-videos.ts;h=2f38ea7c77e9f079db666035fd5cafe365f80b71;hb=c49db162ee3ad0acf89f4e71ac0083b30ab798ea;hp=11f0257a964f3a770b557a655c06fe21aca9cce4;hpb=a41e183c03ec60dae8cd7d62ca05036876b78824;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/import-videos.ts b/server/tools/import-videos.ts index 11f0257a9..2f38ea7c7 100644 --- a/server/tools/import-videos.ts +++ b/server/tools/import-videos.ts @@ -1,3 +1,6 @@ +// 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' @@ -6,6 +9,7 @@ import { unlinkPromise } from '../helpers/core-utils' 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 ', 'Server url') @@ -53,7 +57,10 @@ async function run () { const options = [ '-j', '--flat-playlist', '--playlist-reverse' ] youtubeDL.getInfo(program['targetUrl'], options, processOptions, async (err, info) => { - if (err) throw err + if (err) { + console.log(err.message) + process.exit(1) + } let infoArray: any[] @@ -69,7 +76,6 @@ async function run () { await processVideo(info, program['language']) } - // https://www.youtube.com/watch?v=2Upx39TBc1s console.log('I\'m finished!') process.exit(0) }) @@ -96,15 +102,21 @@ function processVideo (info: any, languageCode: number) { 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() - }) + } }) } @@ -130,13 +142,18 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, languag } 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, fixture: videoPath, @@ -156,7 +173,8 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, languag await uploadVideo(program['url'], accessToken, videoAttributes) } else { - throw err + console.log(err.message) + process.exit(1) } }