Upgrade dependencies
[oweals/peertube.git] / scripts / create-transcoding-job.ts
1 import * as program from 'commander'
2 import { VideoModel } from '../server/models/video/video'
3 import { initDatabaseModels } from '../server/initializers'
4 import { JobQueue } from '../server/lib/job-queue'
5
6 program
7   .option('-v, --video [videoUUID]', 'Video UUID')
8   .option('-r, --resolution [resolution]', 'Video resolution (integer)')
9   .parse(process.argv)
10
11 if (program['video'] === undefined) {
12   console.error('All parameters are mandatory.')
13   process.exit(-1)
14 }
15
16 if (program.resolution !== undefined && Number.isNaN(+program.resolution)) {
17   console.error('The resolution must be an integer (example: 1080).')
18   process.exit(-1)
19 }
20
21 run()
22   .then(() => process.exit(0))
23   .catch(err => {
24     console.error(err)
25     process.exit(-1)
26   })
27
28 async function run () {
29   await initDatabaseModels(true)
30
31   const video = await VideoModel.loadByUUID(program['video'])
32   if (!video) throw new Error('Video not found.')
33
34   const dataInput = {
35     videoUUID: video.uuid,
36     isNewVideo: false,
37     resolution: undefined
38   }
39
40   if (program.resolution !== undefined) {
41     dataInput.resolution = program.resolution
42   }
43
44   await JobQueue.Instance.init()
45   await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
46   console.log('Transcoding job for video %s created.', video.uuid)
47 }