--- /dev/null
+import * as Bull from 'bull'
+import { logger } from '../../../helpers/logger'
+import { VideoModel } from '../../../models/video/video'
+import { publishVideoIfNeeded } from './video-transcoding'
+import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
+import { copy, stat } from 'fs-extra'
+import { VideoFileModel } from '../../../models/video/video-file'
+import { extname } from 'path'
+
+export type VideoFileImportPayload = {
+ videoUUID: string,
+ filePath: string
+}
+
+async function processVideoFileImport (job: Bull.Job) {
+ const payload = job.data as VideoFileImportPayload
+ logger.info('Processing video file import in job %d.', job.id)
+
+ const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID)
+ // No video, maybe deleted?
+ if (!video) {
+ logger.info('Do not process job %d, video does not exist.', job.id)
+ return undefined
+ }
+
+ await updateVideoFile(video, payload.filePath)
+
+ await publishVideoIfNeeded(video)
+ return video
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ processVideoFileImport
+}
+
+// ---------------------------------------------------------------------------
+
+async function updateVideoFile (video: VideoModel, inputFilePath: string) {
+ const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
+ const { size } = await stat(inputFilePath)
+ const fps = await getVideoFileFPS(inputFilePath)
+
+ let updatedVideoFile = new VideoFileModel({
+ resolution: videoFileResolution,
+ extname: extname(inputFilePath),
+ size,
+ fps,
+ videoId: video.id
+ })
+
+ const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
+
+ if (currentVideoFile) {
+ // Remove old file and old torrent
+ await video.removeFile(currentVideoFile)
+ await video.removeTorrent(currentVideoFile)
+ // Remove the old video file from the array
+ video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
+
+ // Update the database
+ currentVideoFile.set('extname', updatedVideoFile.extname)
+ currentVideoFile.set('size', updatedVideoFile.size)
+ currentVideoFile.set('fps', updatedVideoFile.fps)
+
+ updatedVideoFile = currentVideoFile
+ }
+
+ const outputPath = video.getVideoFilePath(updatedVideoFile)
+ await copy(inputFilePath, outputPath)
+
+ await video.createTorrentAndSetInfoHash(updatedVideoFile)
+
+ await updatedVideoFile.save()
+
+ video.VideoFiles.push(updatedVideoFile)
+}
import { JobQueue } from '../job-queue'
import { federateVideoIfNeeded } from '../../activitypub'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
-import { sequelizeTypescript, CONFIG } from '../../../initializers'
+import { CONFIG, sequelizeTypescript } from '../../../initializers'
import * as Bluebird from 'bluebird'
import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
-import { generateHlsPlaylist, importVideoFile, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding'
+import { generateHlsPlaylist, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding'
import { Notifier } from '../../notifier'
export type VideoTranscodingPayload = {
generateHlsPlaylist?: boolean
}
-export type VideoFileImportPayload = {
- videoUUID: string,
- filePath: string
-}
-
-async function processVideoFileImport (job: Bull.Job) {
- const payload = job.data as VideoFileImportPayload
- logger.info('Processing video file import in job %d.', job.id)
-
- const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID)
- // No video, maybe deleted?
- if (!video) {
- logger.info('Do not process job %d, video does not exist.', job.id)
- return undefined
- }
-
- await importVideoFile(video, payload.filePath)
-
- await onVideoFileTranscoderOrImportSuccess(video)
- return video
-}
-
async function processVideoTranscoding (job: Bull.Job) {
const payload = job.data as VideoTranscodingPayload
logger.info('Processing video file in job %d.', job.id)
} else if (payload.resolution) { // Transcoding in other resolution
await transcodeOriginalVideofile(video, payload.resolution, payload.isPortraitMode || false)
- await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video, payload)
+ await retryTransactionWrapper(publishVideoIfNeeded, video, payload)
} else {
await optimizeVideofile(video)
})
}
-async function onVideoFileTranscoderOrImportSuccess (video: VideoModel, payload?: VideoTranscodingPayload) {
- if (video === undefined) return undefined
-
+async function publishVideoIfNeeded (video: VideoModel, payload?: VideoTranscodingPayload) {
const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
// Maybe the video changed in database, refresh it
let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
export {
processVideoTranscoding,
- processVideoFileImport
+ publishVideoIfNeeded
}
// ---------------------------------------------------------------------------
import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'
import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast'
import { EmailPayload, processEmail } from './handlers/email'
-import {
- processVideoFileImport,
- processVideoTranscoding,
- VideoFileImportPayload,
- VideoTranscodingPayload
-} from './handlers/video-transcoding'
+import { processVideoTranscoding, VideoTranscodingPayload } from './handlers/video-transcoding'
import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow'
import { processVideoImport, VideoImportPayload } from './handlers/video-import'
import { processVideosViews } from './handlers/video-views'
import { refreshAPObject, RefreshPayload } from './handlers/activitypub-refresher'
+import { processVideoFileImport, VideoFileImportPayload } from './handlers/video-file-import'
type CreateJobArgument =
{ type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers'
-import { extname, join } from 'path'
-import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils'
-import { copy, ensureDir, move, remove, stat } from 'fs-extra'
+import { join } from 'path'
+import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils'
+import { ensureDir, move, remove, stat } from 'fs-extra'
import { logger } from '../helpers/logger'
import { VideoResolution } from '../../shared/models/videos'
import { VideoFileModel } from '../models/video/video-file'
})
}
-async function importVideoFile (video: VideoModel, inputFilePath: string) {
- const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
- const { size } = await stat(inputFilePath)
- const fps = await getVideoFileFPS(inputFilePath)
-
- let updatedVideoFile = new VideoFileModel({
- resolution: videoFileResolution,
- extname: extname(inputFilePath),
- size,
- fps,
- videoId: video.id
- })
-
- const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
-
- if (currentVideoFile) {
- // Remove old file and old torrent
- await video.removeFile(currentVideoFile)
- await video.removeTorrent(currentVideoFile)
- // Remove the old video file from the array
- video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
-
- // Update the database
- currentVideoFile.set('extname', updatedVideoFile.extname)
- currentVideoFile.set('size', updatedVideoFile.size)
- currentVideoFile.set('fps', updatedVideoFile.fps)
-
- updatedVideoFile = currentVideoFile
- }
-
- const outputPath = video.getVideoFilePath(updatedVideoFile)
- await copy(inputFilePath, outputPath)
-
- await video.createTorrentAndSetInfoHash(updatedVideoFile)
-
- await updatedVideoFile.save()
-
- video.VideoFiles.push(updatedVideoFile)
-}
-
export {
generateHlsPlaylist,
optimizeVideofile,
- transcodeOriginalVideofile,
- importVideoFile
+ transcodeOriginalVideofile
}