X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fimport-videos.ts;h=2f38ea7c77e9f079db666035fd5cafe365f80b71;hb=c49db162ee3ad0acf89f4e71ac0083b30ab798ea;hp=baaedd329df29c361c5cc043763b7215563fd4a1;hpb=5c5638a062d90a0f0cd5f6e8ccb3589099668e79;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/import-videos.ts b/server/tools/import-videos.ts index baaedd329..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') @@ -72,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) }) @@ -99,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() - }) + } }) } @@ -133,13 +142,17 @@ 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,