aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/runners/job-handlers/shared/vod-helpers.ts
blob: 1a2ad02ca0bbee9f8832eea755953056428ce1a9 (plain) (tree)
1
2
3
4
5



                                                                              
                                                                                   


















                                                                                                                               
                                   


















                                                                                                             
import { move } from 'fs-extra'
import { dirname, join } from 'path'
import { logger, LoggerTagsFn } from '@server/helpers/logger'
import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding'
import { onWebVideoFileTranscoding } from '@server/lib/transcoding/web-transcoding'
import { buildNewFile } from '@server/lib/video-file'
import { VideoModel } from '@server/models/video/video'
import { MVideoFullLight } from '@server/types/models'
import { MRunnerJob } from '@server/types/models/runners'
import { RunnerJobVODAudioMergeTranscodingPrivatePayload, RunnerJobVODWebVideoTranscodingPrivatePayload } from '@shared/models'

export async function onVODWebVideoOrAudioMergeTranscodingJob (options: {
  video: MVideoFullLight
  videoFilePath: string
  privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload | RunnerJobVODAudioMergeTranscodingPrivatePayload
}) {
  const { video, videoFilePath, privatePayload } = options

  const videoFile = await buildNewFile({ path: videoFilePath, mode: 'web-video' })
  videoFile.videoId = video.id

  const newVideoFilePath = join(dirname(videoFilePath), videoFile.filename)
  await move(videoFilePath, newVideoFilePath)

  await onWebVideoFileTranscoding({
    video,
    videoFile,
    videoOutputPath: newVideoFilePath
  })

  await onTranscodingEnded({ isNewVideo: privatePayload.isNewVideo, moveVideoToNextState: true, video })
}

export async function loadTranscodingRunnerVideo (runnerJob: MRunnerJob, lTags: LoggerTagsFn) {
  const videoUUID = runnerJob.privatePayload.videoUUID

  const video = await VideoModel.loadFull(videoUUID)
  if (!video) {
    logger.info('Video %s does not exist anymore after transcoding runner job.', videoUUID, lTags(videoUUID))
    return undefined
  }

  return video
}