]>
Commit | Line | Data |
---|---|---|
1 | 'use strict' | |
2 | ||
3 | const db = require('../../../initializers/database') | |
4 | const logger = require('../../../helpers/logger') | |
5 | const friends = require('../../../lib/friends') | |
6 | ||
7 | const VideoTranscoderHandler = { | |
8 | process, | |
9 | onError, | |
10 | onSuccess | |
11 | } | |
12 | ||
13 | // --------------------------------------------------------------------------- | |
14 | ||
15 | function process (data, callback) { | |
16 | db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { | |
17 | if (err) return callback(err) | |
18 | ||
19 | video.transcodeVideofile(function (err) { | |
20 | return callback(err, video) | |
21 | }) | |
22 | }) | |
23 | } | |
24 | ||
25 | function onError (err, jobId, video, callback) { | |
26 | logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) | |
27 | return callback() | |
28 | } | |
29 | ||
30 | function onSuccess (data, jobId, video, callback) { | |
31 | logger.info('Job %d is a success.', jobId) | |
32 | ||
33 | video.toAddRemoteJSON(function (err, remoteVideo) { | |
34 | if (err) return callback(err) | |
35 | ||
36 | // Now we'll add the video's meta data to our friends | |
37 | friends.addVideoToFriends(remoteVideo, null, callback) | |
38 | }) | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | module.exports = VideoTranscoderHandler |