-async function addOptimizeOrMergeAudioJob (options: {
- video: MVideoUUID
- videoFile: MVideoFile
- user: MUserId
- isNewVideo?: boolean // Default true
-}) {
- const { video, videoFile, user, isNewVideo } = options
-
- let dataInput: VideoTranscodingPayload
-
- if (videoFile.isAudio()) {
- dataInput = {
- type: 'merge-audio-to-webtorrent',
- resolution: DEFAULT_AUDIO_RESOLUTION,
- videoUUID: video.uuid,
- createHLSIfNeeded: true,
- isNewVideo
- }
- } else {
- dataInput = {
- type: 'optimize-to-webtorrent',
- videoUUID: video.uuid,
- isNewVideo
- }
- }
-
- const jobOptions = {
- priority: await getTranscodingJobPriority(user)
- }
-
- return addTranscodingJob(dataInput, jobOptions)
-}
-
-async function addTranscodingJob (payload: VideoTranscodingPayload, options: CreateJobOptions = {}) {
- await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode')
-
- return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: payload }, options)
-}
-
-async function getTranscodingJobPriority (user: MUserId) {
- const now = new Date()
- const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
-
- const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
-
- return JOB_PRIORITY.TRANSCODING + videoUploadedByUser
-}
-
-// ---------------------------------------------------------------------------
-
-async function addMoveToObjectStorageJob (options: {