]>
Commit | Line | Data |
---|---|---|
0c948c16 | 1 | import * as program from 'commander' |
0c948c16 C |
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') | |
05623b90 | 8 | .option('-r, --resolution [resolution]', 'Video resolution (integer)') |
0c948c16 C |
9 | .parse(process.argv) |
10 | ||
11 | if (program['video'] === undefined) { | |
12 | console.error('All parameters are mandatory.') | |
13 | process.exit(-1) | |
14 | } | |
15 | ||
05623b90 F |
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 | ||
0c948c16 C |
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 | ||
627621c1 | 31 | const video = await VideoModel.loadByUUIDWithFile(program['video']) |
0c948c16 C |
32 | if (!video) throw new Error('Video not found.') |
33 | ||
34 | const dataInput = { | |
35 | videoUUID: video.uuid, | |
05623b90 F |
36 | isNewVideo: false, |
37 | resolution: undefined | |
38 | } | |
39 | ||
40 | if (program.resolution !== undefined) { | |
41 | dataInput.resolution = program.resolution | |
0c948c16 C |
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 | } |