From 308421283adf8df1a6a1972cd0efe198b0d93435 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 17:10:53 +0100 Subject: Move video file import in its own file --- server/lib/video-transcoding.ts | 49 ++++------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) (limited to 'server/lib/video-transcoding.ts') diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index e932c0e55..c29e34ab5 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts @@ -1,7 +1,7 @@ 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' @@ -123,49 +123,8 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti }) } -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 } -- cgit v1.2.3