aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/runners/job-handlers/shared/vod-helpers.ts
blob: 93ae89ff87c7bcd08c9f509bd0c1d24ef8601c23 (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
44
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 { onWebTorrentVideoFileTranscoding } 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 onWebTorrentVideoFileTranscoding({
    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
}