]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - scripts/create-transcoding-job.ts
Update translations
[github/Chocobozzz/PeerTube.git] / scripts / create-transcoding-job.ts
index 463cdfad39f100a7664f563a216a1c0a5aa160da..67a270a8660ba88f5d5769a9fa24a0e616ac9bf5 100755 (executable)
@@ -1,13 +1,15 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
 import * as program from 'commander'
-import { createReadStream } from 'fs'
-import { join } from 'path'
-import { createInterface } from 'readline'
 import { VideoModel } from '../server/models/video/video'
 import { initDatabaseModels } from '../server/initializers'
 import { JobQueue } from '../server/lib/job-queue'
+import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding'
 
 program
   .option('-v, --video [videoUUID]', 'Video UUID')
+  .option('-r, --resolution [resolution]', 'Video resolution (integer)')
   .parse(process.argv)
 
 if (program['video'] === undefined) {
@@ -15,6 +17,11 @@ if (program['video'] === undefined) {
   process.exit(-1)
 }
 
+if (program.resolution !== undefined && Number.isNaN(+program.resolution)) {
+  console.error('The resolution must be an integer (example: 1080).')
+  process.exit(-1)
+}
+
 run()
   .then(() => process.exit(0))
   .catch(err => {
@@ -28,12 +35,11 @@ async function run () {
   const video = await VideoModel.loadByUUID(program['video'])
   if (!video) throw new Error('Video not found.')
 
-  const dataInput = {
-    videoUUID: video.uuid,
-    isNewVideo: false
-  }
+  const dataInput: VideoTranscodingPayload = program.resolution !== undefined
+   ? { type: 'new-resolution' as 'new-resolution', videoUUID: video.uuid, isNewVideo: false, resolution: program.resolution }
+   : { type: 'optimize' as 'optimize', videoUUID: video.uuid, isNewVideo: false }
 
   await JobQueue.Instance.init()
-  await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
+  await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput })
   console.log('Transcoding job for video %s created.', video.uuid)
 }