diff options
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r-- | server/lib/video.ts | 44 |
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 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY } from '@server/initializers/constants' | ||
2 | import { sequelizeTypescript } from '@server/initializers/database' | 3 | import { sequelizeTypescript } from '@server/initializers/database' |
3 | import { TagModel } from '@server/models/video/tag' | 4 | import { TagModel } from '@server/models/video/tag' |
4 | import { VideoModel } from '@server/models/video/video' | 5 | import { VideoModel } from '@server/models/video/video' |
5 | import { FilteredModelAttributes } from '@server/types' | 6 | import { FilteredModelAttributes } from '@server/types' |
6 | import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' | 7 | import { MTag, MThumbnail, MUserId, MVideo, MVideoFile, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' |
7 | import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' | 8 | import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } from '@shared/models' |
8 | import { federateVideoIfNeeded } from './activitypub/videos' | 9 | import { federateVideoIfNeeded } from './activitypub/videos' |
10 | import { JobQueue } from './job-queue/job-queue' | ||
9 | import { Notifier } from './notifier' | 11 | import { Notifier } from './notifier' |
10 | import { createVideoMiniatureFromExisting } from './thumbnail' | 12 | import { createVideoMiniatureFromExisting } from './thumbnail' |
11 | 13 | ||
@@ -104,11 +106,47 @@ async function publishAndFederateIfNeeded (video: MVideoUUID, wasLive = false) { | |||
104 | } | 106 | } |
105 | } | 107 | } |
106 | 108 | ||
109 | async 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 | |||
134 | async 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 | ||
109 | export { | 145 | export { |
110 | buildLocalVideoFromReq, | 146 | buildLocalVideoFromReq, |
111 | publishAndFederateIfNeeded, | 147 | publishAndFederateIfNeeded, |
112 | buildVideoThumbnailsFromReq, | 148 | buildVideoThumbnailsFromReq, |
113 | setVideoTags | 149 | setVideoTags, |
150 | addOptimizeOrMergeAudioJob, | ||
151 | getJobTranscodingPriorityMalus | ||
114 | } | 152 | } |