aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/handlers/video-transcoder.ts
blob: 87d8ffa6a6467264998a4178e7767feb6769a0f6 (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
import { database as db } from '../../../initializers/database'
import { logger } from '../../../helpers'
import { addVideoToFriends } from '../../../lib'
import { VideoInstance } from '../../../models'

function process (data: { videoUUID: string }) {
  return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => {
    // TODO: handle multiple resolutions
    const videoFile = video.VideoFiles[0]
    return video.transcodeVideofile(videoFile).then(() => video)
  })
}

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

function onSuccess (jobId: number, video: VideoInstance) {
  logger.info('Job %d is a success.', jobId)

  video.toAddRemoteJSON().then(remoteVideo => {
    // Now we'll add the video's meta data to our friends
    return addVideoToFriends(remoteVideo, null)
  })
}

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

export {
  process,
  onError,
  onSuccess
}