aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r--server/lib/video.ts63
1 files changed, 4 insertions, 59 deletions
diff --git a/server/lib/video.ts b/server/lib/video.ts
index aacc41a7a..588dc553f 100644
--- a/server/lib/video.ts
+++ b/server/lib/video.ts
@@ -2,14 +2,14 @@ import { UploadFiles } from 'express'
2import memoizee from 'memoizee' 2import memoizee from 'memoizee'
3import { Transaction } from 'sequelize/types' 3import { Transaction } from 'sequelize/types'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY, MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants' 5import { MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants'
6import { TagModel } from '@server/models/video/tag' 6import { TagModel } from '@server/models/video/tag'
7import { VideoModel } from '@server/models/video/video' 7import { VideoModel } from '@server/models/video/video'
8import { VideoJobInfoModel } from '@server/models/video/video-job-info' 8import { VideoJobInfoModel } from '@server/models/video/video-job-info'
9import { FilteredModelAttributes } from '@server/types' 9import { FilteredModelAttributes } from '@server/types'
10import { MThumbnail, MUserId, MVideoFile, MVideoFullLight, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' 10import { MThumbnail, MVideoFullLight, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models'
11import { ManageVideoTorrentPayload, ThumbnailType, VideoCreate, VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models' 11import { ManageVideoTorrentPayload, ThumbnailType, VideoCreate, VideoPrivacy, VideoState } from '@shared/models'
12import { CreateJobArgument, CreateJobOptions, JobQueue } from './job-queue/job-queue' 12import { CreateJobArgument, JobQueue } from './job-queue/job-queue'
13import { updateVideoMiniatureFromExisting } from './thumbnail' 13import { updateVideoMiniatureFromExisting } from './thumbnail'
14import { moveFilesIfPrivacyChanged } from './video-privacy' 14import { moveFilesIfPrivacyChanged } from './video-privacy'
15 15
@@ -87,58 +87,6 @@ async function setVideoTags (options: {
87 87
88// --------------------------------------------------------------------------- 88// ---------------------------------------------------------------------------
89 89
90async function buildOptimizeOrMergeAudioJob (options: {
91 video: MVideoUUID
92 videoFile: MVideoFile
93 user: MUserId
94 isNewVideo?: boolean // Default true
95}) {
96 const { video, videoFile, user, isNewVideo } = options
97
98 let payload: VideoTranscodingPayload
99
100 if (videoFile.isAudio()) {
101 payload = {
102 type: 'merge-audio-to-webtorrent',
103 resolution: DEFAULT_AUDIO_RESOLUTION,
104 videoUUID: video.uuid,
105 createHLSIfNeeded: true,
106 isNewVideo
107 }
108 } else {
109 payload = {
110 type: 'optimize-to-webtorrent',
111 videoUUID: video.uuid,
112 isNewVideo
113 }
114 }
115
116 await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode')
117
118 return {
119 type: 'video-transcoding' as 'video-transcoding',
120 priority: await getTranscodingJobPriority(user),
121 payload
122 }
123}
124
125async function buildTranscodingJob (payload: VideoTranscodingPayload, options: CreateJobOptions = {}) {
126 await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode')
127
128 return { type: 'video-transcoding' as 'video-transcoding', payload, ...options }
129}
130
131async function getTranscodingJobPriority (user: MUserId) {
132 const now = new Date()
133 const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
134
135 const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
136
137 return JOB_PRIORITY.TRANSCODING + videoUploadedByUser
138}
139
140// ---------------------------------------------------------------------------
141
142async function buildMoveToObjectStorageJob (options: { 90async function buildMoveToObjectStorageJob (options: {
143 video: MVideoUUID 91 video: MVideoUUID
144 previousVideoState: VideoState 92 previousVideoState: VideoState
@@ -235,10 +183,7 @@ export {
235 buildLocalVideoFromReq, 183 buildLocalVideoFromReq,
236 buildVideoThumbnailsFromReq, 184 buildVideoThumbnailsFromReq,
237 setVideoTags, 185 setVideoTags,
238 buildOptimizeOrMergeAudioJob,
239 buildTranscodingJob,
240 buildMoveToObjectStorageJob, 186 buildMoveToObjectStorageJob,
241 getTranscodingJobPriority,
242 addVideoJobsAfterUpdate, 187 addVideoJobsAfterUpdate,
243 getCachedVideoDuration 188 getCachedVideoDuration
244} 189}