diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-22 14:35:04 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-22 16:25:14 +0100 |
commit | 1808a1f8e4b7b102823492a2007a46929aebf189 (patch) | |
tree | a345140ec9a7a20c222ace3cda18ac999277c8c3 /server/lib/job-queue/handlers/video-edition.ts | |
parent | 348c2ce3ff3fe2f25a31f08bfb36c88723a0ce46 (diff) | |
download | PeerTube-1808a1f8e4b7b102823492a2007a46929aebf189.tar.gz PeerTube-1808a1f8e4b7b102823492a2007a46929aebf189.tar.zst PeerTube-1808a1f8e4b7b102823492a2007a46929aebf189.zip |
Add video edition finished notification
Diffstat (limited to 'server/lib/job-queue/handlers/video-edition.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-edition.ts | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/server/lib/job-queue/handlers/video-edition.ts b/server/lib/job-queue/handlers/video-edition.ts index c5ba0452f..d2d2a4f65 100644 --- a/server/lib/job-queue/handlers/video-edition.ts +++ b/server/lib/job-queue/handlers/video-edition.ts | |||
@@ -8,10 +8,9 @@ import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | |||
8 | import { generateWebTorrentVideoFilename } from '@server/lib/paths' | 8 | import { generateWebTorrentVideoFilename } from '@server/lib/paths' |
9 | import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' | 9 | import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' |
10 | import { isAbleToUploadVideo } from '@server/lib/user' | 10 | import { isAbleToUploadVideo } from '@server/lib/user' |
11 | import { addMoveToObjectStorageJob, addOptimizeOrMergeAudioJob } from '@server/lib/video' | 11 | import { addOptimizeOrMergeAudioJob } from '@server/lib/video' |
12 | import { approximateIntroOutroAdditionalSize } from '@server/lib/video-editor' | 12 | import { approximateIntroOutroAdditionalSize } from '@server/lib/video-editor' |
13 | import { VideoPathManager } from '@server/lib/video-path-manager' | 13 | import { VideoPathManager } from '@server/lib/video-path-manager' |
14 | import { buildNextVideoState } from '@server/lib/video-state' | ||
15 | import { UserModel } from '@server/models/user/user' | 14 | import { UserModel } from '@server/models/user/user' |
16 | import { VideoModel } from '@server/models/video/video' | 15 | import { VideoModel } from '@server/models/video/video' |
17 | import { VideoFileModel } from '@server/models/video/video-file' | 16 | import { VideoFileModel } from '@server/models/video/video-file' |
@@ -33,8 +32,7 @@ import { | |||
33 | VideoEditorTaskCutPayload, | 32 | VideoEditorTaskCutPayload, |
34 | VideoEditorTaskIntroPayload, | 33 | VideoEditorTaskIntroPayload, |
35 | VideoEditorTaskOutroPayload, | 34 | VideoEditorTaskOutroPayload, |
36 | VideoEditorTaskWatermarkPayload, | 35 | VideoEditorTaskWatermarkPayload |
37 | VideoState | ||
38 | } from '@shared/models' | 36 | } from '@shared/models' |
39 | import { logger, loggerTagsFactory } from '../../../helpers/logger' | 37 | import { logger, loggerTagsFactory } from '../../../helpers/logger' |
40 | 38 | ||
@@ -42,14 +40,15 @@ const lTagsBase = loggerTagsFactory('video-edition') | |||
42 | 40 | ||
43 | async function processVideoEdition (job: Job) { | 41 | async function processVideoEdition (job: Job) { |
44 | const payload = job.data as VideoEditionPayload | 42 | const payload = job.data as VideoEditionPayload |
43 | const lTags = lTagsBase(payload.videoUUID) | ||
45 | 44 | ||
46 | logger.info('Process video edition of %s in job %d.', payload.videoUUID, job.id) | 45 | logger.info('Process video edition of %s in job %d.', payload.videoUUID, job.id, lTags) |
47 | 46 | ||
48 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID) | 47 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID) |
49 | 48 | ||
50 | // No video, maybe deleted? | 49 | // No video, maybe deleted? |
51 | if (!video) { | 50 | if (!video) { |
52 | logger.info('Can\'t process job %d, video does not exist.', job.id, lTagsBase(payload.videoUUID)) | 51 | logger.info('Can\'t process job %d, video does not exist.', job.id, lTags) |
53 | return undefined | 52 | return undefined |
54 | } | 53 | } |
55 | 54 | ||
@@ -69,7 +68,8 @@ async function processVideoEdition (job: Job) { | |||
69 | inputPath: tmpInputFilePath ?? originalFilePath, | 68 | inputPath: tmpInputFilePath ?? originalFilePath, |
70 | video, | 69 | video, |
71 | outputPath, | 70 | outputPath, |
72 | task | 71 | task, |
72 | lTags | ||
73 | }) | 73 | }) |
74 | 74 | ||
75 | if (tmpInputFilePath) await remove(tmpInputFilePath) | 75 | if (tmpInputFilePath) await remove(tmpInputFilePath) |
@@ -81,7 +81,7 @@ async function processVideoEdition (job: Job) { | |||
81 | return outputPath | 81 | return outputPath |
82 | }) | 82 | }) |
83 | 83 | ||
84 | logger.info('Video edition ended for video %s.', video.uuid) | 84 | logger.info('Video edition ended for video %s.', video.uuid, lTags) |
85 | 85 | ||
86 | const newFile = await buildNewFile(video, editionResultPath) | 86 | const newFile = await buildNewFile(video, editionResultPath) |
87 | 87 | ||
@@ -94,19 +94,13 @@ async function processVideoEdition (job: Job) { | |||
94 | 94 | ||
95 | await newFile.save() | 95 | await newFile.save() |
96 | 96 | ||
97 | video.state = buildNextVideoState() | ||
98 | video.duration = await getVideoStreamDuration(outputPath) | 97 | video.duration = await getVideoStreamDuration(outputPath) |
99 | await video.save() | 98 | await video.save() |
100 | 99 | ||
101 | await federateVideoIfNeeded(video, false, undefined) | 100 | await federateVideoIfNeeded(video, false, undefined) |
102 | 101 | ||
103 | if (video.state === VideoState.TO_TRANSCODE) { | 102 | const user = await UserModel.loadByVideoId(video.id) |
104 | const user = await UserModel.loadByVideoId(video.id) | 103 | await addOptimizeOrMergeAudioJob({ video, videoFile: newFile, user, isNewVideo: false }) |
105 | |||
106 | await addOptimizeOrMergeAudioJob(video, newFile, user, false) | ||
107 | } else if (video.state === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) { | ||
108 | await addMoveToObjectStorageJob(video, false) | ||
109 | } | ||
110 | } | 104 | } |
111 | 105 | ||
112 | // --------------------------------------------------------------------------- | 106 | // --------------------------------------------------------------------------- |
@@ -122,6 +116,7 @@ type TaskProcessorOptions <T extends VideoEditionTaskPayload = VideoEditionTaskP | |||
122 | outputPath: string | 116 | outputPath: string |
123 | video: MVideo | 117 | video: MVideo |
124 | task: T | 118 | task: T |
119 | lTags: { tags: string[] } | ||
125 | } | 120 | } |
126 | 121 | ||
127 | const taskProcessors: { [id in VideoEditorTask['name']]: (options: TaskProcessorOptions) => Promise<any> } = { | 122 | const taskProcessors: { [id in VideoEditorTask['name']]: (options: TaskProcessorOptions) => Promise<any> } = { |
@@ -134,7 +129,7 @@ const taskProcessors: { [id in VideoEditorTask['name']]: (options: TaskProcessor | |||
134 | async function processTask (options: TaskProcessorOptions) { | 129 | async function processTask (options: TaskProcessorOptions) { |
135 | const { video, task } = options | 130 | const { video, task } = options |
136 | 131 | ||
137 | logger.info('Processing %s task for video %s.', task.name, video.uuid, { task }) | 132 | logger.info('Processing %s task for video %s.', task.name, video.uuid, { task, ...options.lTags }) |
138 | 133 | ||
139 | const processor = taskProcessors[options.task.name] | 134 | const processor = taskProcessors[options.task.name] |
140 | if (!process) throw new Error('Unknown task ' + task.name) | 135 | if (!process) throw new Error('Unknown task ' + task.name) |