aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts37
-rw-r--r--server/lib/video-transcoding.ts1
2 files changed, 17 insertions, 21 deletions
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts
index 86c9b5c29..839916306 100644
--- a/server/lib/job-queue/handlers/video-file-import.ts
+++ b/server/lib/job-queue/handlers/video-file-import.ts
@@ -4,7 +4,7 @@ import { extname } from 'path'
4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
5import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 5import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
6import { UserModel } from '@server/models/account/user' 6import { UserModel } from '@server/models/account/user'
7import { MVideoFile, MVideoFullLight } from '@server/types/models' 7import { MVideoFullLight } from '@server/types/models'
8import { VideoFileImportPayload } from '@shared/models' 8import { VideoFileImportPayload } from '@shared/models'
9import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' 9import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
10import { logger } from '../../../helpers/logger' 10import { logger } from '../../../helpers/logger'
@@ -56,16 +56,8 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
56 const fps = await getVideoFileFPS(inputFilePath) 56 const fps = await getVideoFileFPS(inputFilePath)
57 57
58 const fileExt = extname(inputFilePath) 58 const fileExt = extname(inputFilePath)
59 let updatedVideoFile = new VideoFileModel({
60 resolution: videoFileResolution,
61 extname: fileExt,
62 filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
63 size,
64 fps,
65 videoId: video.id
66 }) as MVideoFile
67 59
68 const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution) 60 const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution)
69 61
70 if (currentVideoFile) { 62 if (currentVideoFile) {
71 // Remove old file and old torrent 63 // Remove old file and old torrent
@@ -74,20 +66,23 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
74 // Remove the old video file from the array 66 // Remove the old video file from the array
75 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) 67 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
76 68
77 // Update the database 69 await currentVideoFile.destroy()
78 currentVideoFile.extname = updatedVideoFile.extname
79 currentVideoFile.size = updatedVideoFile.size
80 currentVideoFile.fps = updatedVideoFile.fps
81
82 updatedVideoFile = currentVideoFile
83 } 70 }
84 71
85 const outputPath = getVideoFilePath(video, updatedVideoFile) 72 const newVideoFile = new VideoFileModel({
86 await copy(inputFilePath, outputPath) 73 resolution: videoFileResolution,
74 extname: fileExt,
75 filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
76 size,
77 fps,
78 videoId: video.id
79 })
87 80
88 await createTorrentAndSetInfoHash(video, video, updatedVideoFile) 81 const outputPath = getVideoFilePath(video, newVideoFile)
82 await copy(inputFilePath, outputPath)
89 83
90 await updatedVideoFile.save() 84 video.VideoFiles.push(newVideoFile)
85 await createTorrentAndSetInfoHash(video, video, newVideoFile)
91 86
92 video.VideoFiles.push(updatedVideoFile) 87 await newVideoFile.save()
93} 88}
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index b366e2e44..e3cd18e25 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -166,6 +166,7 @@ async function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoRes
166 166
167 // Important to do this before getVideoFilename() to take in account the new file extension 167 // Important to do this before getVideoFilename() to take in account the new file extension
168 inputVideoFile.extname = newExtname 168 inputVideoFile.extname = newExtname
169 inputVideoFile.filename = generateVideoFilename(video, false, inputVideoFile.resolution, newExtname)
169 170
170 const videoOutputPath = getVideoFilePath(video, inputVideoFile) 171 const videoOutputPath = getVideoFilePath(video, inputVideoFile)
171 // ffmpeg generated a new video file, so update the video duration 172 // ffmpeg generated a new video file, so update the video duration