diff options
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r-- | server/lib/video.ts | 63 |
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' | |||
2 | import memoizee from 'memoizee' | 2 | import memoizee from 'memoizee' |
3 | import { Transaction } from 'sequelize/types' | 3 | import { Transaction } from 'sequelize/types' |
4 | import { CONFIG } from '@server/initializers/config' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY, MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants' | 5 | import { MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants' |
6 | import { TagModel } from '@server/models/video/tag' | 6 | import { TagModel } from '@server/models/video/tag' |
7 | import { VideoModel } from '@server/models/video/video' | 7 | import { VideoModel } from '@server/models/video/video' |
8 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' | 8 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' |
9 | import { FilteredModelAttributes } from '@server/types' | 9 | import { FilteredModelAttributes } from '@server/types' |
10 | import { MThumbnail, MUserId, MVideoFile, MVideoFullLight, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' | 10 | import { MThumbnail, MVideoFullLight, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' |
11 | import { ManageVideoTorrentPayload, ThumbnailType, VideoCreate, VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models' | 11 | import { ManageVideoTorrentPayload, ThumbnailType, VideoCreate, VideoPrivacy, VideoState } from '@shared/models' |
12 | import { CreateJobArgument, CreateJobOptions, JobQueue } from './job-queue/job-queue' | 12 | import { CreateJobArgument, JobQueue } from './job-queue/job-queue' |
13 | import { updateVideoMiniatureFromExisting } from './thumbnail' | 13 | import { updateVideoMiniatureFromExisting } from './thumbnail' |
14 | import { moveFilesIfPrivacyChanged } from './video-privacy' | 14 | import { moveFilesIfPrivacyChanged } from './video-privacy' |
15 | 15 | ||
@@ -87,58 +87,6 @@ async function setVideoTags (options: { | |||
87 | 87 | ||
88 | // --------------------------------------------------------------------------- | 88 | // --------------------------------------------------------------------------- |
89 | 89 | ||
90 | async 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 | |||
125 | async 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 | |||
131 | async 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 | |||
142 | async function buildMoveToObjectStorageJob (options: { | 90 | async 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 | } |