X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-import-videos.ts;h=2c9eabe9889173b4091091c58b02191ee2a5ffa8;hb=d473fd94ce2fd04bffc6cf6ee8f193db309c1d83;hp=0efe87810c98f4d2bc39a40bf548b63c67e67b8c;hpb=a3b7421abb4192e215aa280418b62e96958c5e42;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 0efe87810..2c9eabe98 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -38,6 +38,7 @@ command .option('--first ', 'Process first n elements of returned playlist') .option('--last ', 'Process last n elements of returned playlist') .option('-T, --tmpdir ', 'Working directory', __dirname) + .usage("[global options] [ -- youtube-dl options]") .parse(process.argv) const log = getLogger(program['verbose']) @@ -71,10 +72,11 @@ async function run (url: string, user: UserInfo) { const youtubeDL = await safeGetYoutubeDL() - const options = [ '-j', '--flat-playlist', '--playlist-reverse' ] + const options = [ '-j', '--flat-playlist', '--playlist-reverse', ...command.args ] + youtubeDL.getInfo(program['targetUrl'], options, processOptions, async (err, info) => { if (err) { - exitError(err.message) + exitError(err.stderr + ' ' + err.message) } let infoArray: any[] @@ -91,12 +93,16 @@ async function run (url: string, user: UserInfo) { log.info('Will download and upload %d videos.\n', infoArray.length) for (const info of infoArray) { - await processVideo({ - cwd: program['tmpdir'], - url, - user, - youtubeInfo: info - }) + try { + await processVideo({ + cwd: program['tmpdir'], + url, + user, + youtubeInfo: info + }) + } catch (err) { + console.error('Cannot process video.', { info, url }) + } } log.info('Video/s for user %s imported: %s', user.username, program['targetUrl']) @@ -146,7 +152,7 @@ function processVideo (parameters: { log.info('Downloading video "%s"...', videoInfo.title) - const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] + const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', ...command.args, '-o', path ] try { const youtubeDL = await safeGetYoutubeDL() youtubeDL.exec(videoInfo.url, options, processOptions, async (err, output) => { @@ -272,7 +278,7 @@ async function getCategory (categories: string[], url: string) { function getLicence (licence: string) { if (!licence) return undefined - if (licence.indexOf('Creative Commons Attribution licence') !== -1) return 1 + if (licence.includes('Creative Commons Attribution licence')) return 1 return undefined }