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.ts44
1 files changed, 41 insertions, 3 deletions
diff --git a/server/lib/video.ts b/server/lib/video.ts
index d03ab0452..6b75fadb0 100644
--- a/server/lib/video.ts
+++ b/server/lib/video.ts
@@ -1,11 +1,13 @@
1import { Transaction } from 'sequelize/types' 1import { Transaction } from 'sequelize/types'
2import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY } from '@server/initializers/constants'
2import { sequelizeTypescript } from '@server/initializers/database' 3import { sequelizeTypescript } from '@server/initializers/database'
3import { TagModel } from '@server/models/video/tag' 4import { TagModel } from '@server/models/video/tag'
4import { VideoModel } from '@server/models/video/video' 5import { VideoModel } from '@server/models/video/video'
5import { FilteredModelAttributes } from '@server/types' 6import { FilteredModelAttributes } from '@server/types'
6import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' 7import { MTag, MThumbnail, MUserId, MVideo, MVideoFile, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models'
7import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' 8import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } from '@shared/models'
8import { federateVideoIfNeeded } from './activitypub/videos' 9import { federateVideoIfNeeded } from './activitypub/videos'
10import { JobQueue } from './job-queue/job-queue'
9import { Notifier } from './notifier' 11import { Notifier } from './notifier'
10import { createVideoMiniatureFromExisting } from './thumbnail' 12import { createVideoMiniatureFromExisting } from './thumbnail'
11 13
@@ -104,11 +106,47 @@ async function publishAndFederateIfNeeded (video: MVideoUUID, wasLive = false) {
104 } 106 }
105} 107}
106 108
109async function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile, user: MUserId) {
110 let dataInput: VideoTranscodingPayload
111
112 if (videoFile.isAudio()) {
113 dataInput = {
114 type: 'merge-audio-to-webtorrent',
115 resolution: DEFAULT_AUDIO_RESOLUTION,
116 videoUUID: video.uuid,
117 isNewVideo: true
118 }
119 } else {
120 dataInput = {
121 type: 'optimize-to-webtorrent',
122 videoUUID: video.uuid,
123 isNewVideo: true
124 }
125 }
126
127 const jobOptions = {
128 priority: JOB_PRIORITY.TRANSCODING.OPTIMIZER + await getJobTranscodingPriorityMalus(user)
129 }
130
131 return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }, jobOptions)
132}
133
134async function getJobTranscodingPriorityMalus (user: MUserId) {
135 const now = new Date()
136 const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
137
138 const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
139
140 return videoUploadedByUser
141}
142
107// --------------------------------------------------------------------------- 143// ---------------------------------------------------------------------------
108 144
109export { 145export {
110 buildLocalVideoFromReq, 146 buildLocalVideoFromReq,
111 publishAndFederateIfNeeded, 147 publishAndFederateIfNeeded,
112 buildVideoThumbnailsFromReq, 148 buildVideoThumbnailsFromReq,
113 setVideoTags 149 setVideoTags,
150 addOptimizeOrMergeAudioJob,
151 getJobTranscodingPriorityMalus
114} 152}