aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-01-21 16:57:21 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-01-25 14:38:52 +0100
commit77d7e851dccf17dcc89e8fcc2db3f655d1e63f95 (patch)
treed09e045dfabe7ab1e170d1b0caa9decda8a7d39c /server/helpers/video.ts
parent92c871b40554d5285232eb4392cebb63d127704a (diff)
downloadPeerTube-77d7e851dccf17dcc89e8fcc2db3f655d1e63f95.tar.gz
PeerTube-77d7e851dccf17dcc89e8fcc2db3f655d1e63f95.tar.zst
PeerTube-77d7e851dccf17dcc89e8fcc2db3f655d1e63f95.zip
Add priority to transcoding jobs
(1 = highest priority) 100 for new resolutions 10 for original file optimization Add a malus for transcoding jobs depending on how many uploads the user did in the last 7 days
Diffstat (limited to 'server/helpers/video.ts')
-rw-r--r--server/helpers/video.ts28
1 files changed, 1 insertions, 27 deletions
diff --git a/server/helpers/video.ts b/server/helpers/video.ts
index bfd5a9627..7c510f474 100644
--- a/server/helpers/video.ts
+++ b/server/helpers/video.ts
@@ -1,20 +1,17 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { CONFIG } from '@server/initializers/config' 2import { CONFIG } from '@server/initializers/config'
3import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
4import { JobQueue } from '@server/lib/job-queue'
5import { 3import {
6 isStreamingPlaylist, 4 isStreamingPlaylist,
7 MStreamingPlaylistVideo, 5 MStreamingPlaylistVideo,
8 MVideo, 6 MVideo,
9 MVideoAccountLightBlacklistAllFiles, 7 MVideoAccountLightBlacklistAllFiles,
10 MVideoFile,
11 MVideoFullLight, 8 MVideoFullLight,
12 MVideoIdThumbnail, 9 MVideoIdThumbnail,
13 MVideoImmutable, 10 MVideoImmutable,
14 MVideoThumbnail, 11 MVideoThumbnail,
15 MVideoWithRights 12 MVideoWithRights
16} from '@server/types/models' 13} from '@server/types/models'
17import { VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models' 14import { VideoPrivacy, VideoState } from '@shared/models'
18import { VideoModel } from '../models/video/video' 15import { VideoModel } from '../models/video/video'
19 16
20type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' 17type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
@@ -69,27 +66,6 @@ function getVideoWithAttributes (res: Response) {
69 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights 66 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
70} 67}
71 68
72function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) {
73 let dataInput: VideoTranscodingPayload
74
75 if (videoFile.isAudio()) {
76 dataInput = {
77 type: 'merge-audio-to-webtorrent',
78 resolution: DEFAULT_AUDIO_RESOLUTION,
79 videoUUID: video.uuid,
80 isNewVideo: true
81 }
82 } else {
83 dataInput = {
84 type: 'optimize-to-webtorrent',
85 videoUUID: video.uuid,
86 isNewVideo: true
87 }
88 }
89
90 return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput })
91}
92
93function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { 69function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
94 return isStreamingPlaylist(videoOrPlaylist) 70 return isStreamingPlaylist(videoOrPlaylist)
95 ? videoOrPlaylist.Video 71 ? videoOrPlaylist.Video
@@ -107,7 +83,6 @@ function isStateForFederation (state: VideoState) {
107 const castedState = parseInt(state + '', 10) 83 const castedState = parseInt(state + '', 10)
108 84
109 return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED 85 return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED
110
111} 86}
112 87
113function getPrivaciesForFederation () { 88function getPrivaciesForFederation () {
@@ -130,7 +105,6 @@ export {
130 fetchVideo, 105 fetchVideo,
131 getVideoWithAttributes, 106 getVideoWithAttributes,
132 fetchVideoByUrl, 107 fetchVideoByUrl,
133 addOptimizeOrMergeAudioJob,
134 extractVideo, 108 extractVideo,
135 getExtFromMimetype, 109 getExtFromMimetype,
136 isStateForFederation, 110 isStateForFederation,