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