aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/handlers/video-transcoder.js
blob: d2ad4f9c70aeb3d0c6613962d09161cf9dd3aa5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict'

const db = require('../../../initializers/database')
const logger = require('../../../helpers/logger')
const friends = require('../../../lib/friends')

const VideoTranscoderHandler = {
  process,
  onError,
  onSuccess
}

// ---------------------------------------------------------------------------

function process (data, callback) {
  db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) {
    if (err) return callback(err)

    video.transcodeVideofile(function (err) {
      return callback(err, video)
    })
  })
}

function onError (err, jobId, video, callback) {
  logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
  return callback()
}

function onSuccess (data, jobId, video, callback) {
  logger.info('Job %d is a success.', jobId)

  video.toAddRemoteJSON(function (err, remoteVideo) {
    if (err) return callback(err)

    // Now we'll add the video's meta data to our friends
    friends.addVideoToFriends(remoteVideo, null, callback)
  })
}

// ---------------------------------------------------------------------------

module.exports = VideoTranscoderHandler