aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/jobs/handlers/video-transcoder.ts
blob: 6f606a7d34dea8be474cb42357f7737837a0b5e3 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                               

                                                
                                               
 
                                                                                                        
                                                                              

                                 


                                             


    
                                                                                                    
                                                                                     
                       

 
                                                                                                     
                                            




                                                         
                                                  
    



                                                                              




           
import { database as db } from '../../../initializers/database'
import { logger } from '../../../helpers'
import { addVideoToFriends } from '../../../lib'
import { VideoInstance } from '../../../models'

function process (data: { id: string }, callback: (err: Error, videoInstance?: VideoInstance) => void) {
  db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) {
    if (err) return callback(err)

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

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

function onSuccess (data: any, jobId: number, video: VideoInstance, callback: (err: Error) => void) {
  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
    addVideoToFriends(remoteVideo, null, callback)
  })
}

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

export {
  process,
  onError,
  onSuccess
}