aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/video.ts')
-rw-r--r--server/helpers/video.ts42
1 files changed, 39 insertions, 3 deletions
diff --git a/server/helpers/video.ts b/server/helpers/video.ts
index 4fe2a60f0..6f76cbdfc 100644
--- a/server/helpers/video.ts
+++ b/server/helpers/video.ts
@@ -1,14 +1,21 @@
1import { VideoModel } from '../models/video/video' 1import { VideoModel } from '../models/video/video'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { 3import {
4 isStreamingPlaylist,
5 MStreamingPlaylistVideo,
6 MVideo,
4 MVideoAccountLightBlacklistAllFiles, 7 MVideoAccountLightBlacklistAllFiles,
8 MVideoFile,
5 MVideoFullLight, 9 MVideoFullLight,
6 MVideoIdThumbnail, 10 MVideoIdThumbnail,
11 MVideoImmutable,
7 MVideoThumbnail, 12 MVideoThumbnail,
8 MVideoWithRights, 13 MVideoWithRights
9 MVideoImmutable
10} from '@server/typings/models' 14} from '@server/typings/models'
11import { Response } from 'express' 15import { Response } from 'express'
16import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
17import { JobQueue } from '@server/lib/job-queue'
18import { VideoTranscodingPayload } from '@shared/models'
12 19
13type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' 20type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
14 21
@@ -62,10 +69,39 @@ function getVideoWithAttributes (res: Response) {
62 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights 69 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
63} 70}
64 71
72function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) {
73 let dataInput: VideoTranscodingPayload
74
75 if (videoFile.isAudio()) {
76 dataInput = {
77 type: 'merge-audio' as 'merge-audio',
78 resolution: DEFAULT_AUDIO_RESOLUTION,
79 videoUUID: video.uuid,
80 isNewVideo: true
81 }
82 } else {
83 dataInput = {
84 type: 'optimize' as 'optimize',
85 videoUUID: video.uuid,
86 isNewVideo: true
87 }
88 }
89
90 return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput })
91}
92
93function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
94 return isStreamingPlaylist(videoOrPlaylist)
95 ? videoOrPlaylist.Video
96 : videoOrPlaylist
97}
98
65export { 99export {
66 VideoFetchType, 100 VideoFetchType,
67 VideoFetchByUrlType, 101 VideoFetchByUrlType,
68 fetchVideo, 102 fetchVideo,
69 getVideoWithAttributes, 103 getVideoWithAttributes,
70 fetchVideoByUrl 104 fetchVideoByUrl,
105 addOptimizeOrMergeAudioJob,
106 extractVideo
71} 107}