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