diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-23 09:32:53 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | 8dc8a34ee8428e7657414115d1c137592efa174d (patch) | |
tree | e9b5ef0d7446d1b7766eac18da5a759edc7a9040 /server/helpers/video.ts | |
parent | 7fed637506043e4432cbebe041ada0625171cceb (diff) | |
download | PeerTube-8dc8a34ee8428e7657414115d1c137592efa174d.tar.gz PeerTube-8dc8a34ee8428e7657414115d1c137592efa174d.tar.zst PeerTube-8dc8a34ee8428e7657414115d1c137592efa174d.zip |
Avoir some circular dependencies
Diffstat (limited to 'server/helpers/video.ts')
-rw-r--r-- | server/helpers/video.ts | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 4fe2a60f0..6f76cbdfc 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,14 +1,21 @@ | |||
1 | import { VideoModel } from '../models/video/video' | 1 | import { VideoModel } from '../models/video/video' |
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | import { | 3 | import { |
4 | isStreamingPlaylist, | ||
5 | MStreamingPlaylistVideo, | ||
6 | MVideo, | ||
4 | MVideoAccountLightBlacklistAllFiles, | 7 | MVideoAccountLightBlacklistAllFiles, |
8 | MVideoFile, | ||
5 | MVideoFullLight, | 9 | MVideoFullLight, |
6 | MVideoIdThumbnail, | 10 | MVideoIdThumbnail, |
11 | MVideoImmutable, | ||
7 | MVideoThumbnail, | 12 | MVideoThumbnail, |
8 | MVideoWithRights, | 13 | MVideoWithRights |
9 | MVideoImmutable | ||
10 | } from '@server/typings/models' | 14 | } from '@server/typings/models' |
11 | import { Response } from 'express' | 15 | import { Response } from 'express' |
16 | import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants' | ||
17 | import { JobQueue } from '@server/lib/job-queue' | ||
18 | import { VideoTranscodingPayload } from '@shared/models' | ||
12 | 19 | ||
13 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | 20 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' |
14 | 21 | ||
@@ -62,10 +69,39 @@ function getVideoWithAttributes (res: Response) { | |||
62 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights | 69 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights |
63 | } | 70 | } |
64 | 71 | ||
72 | function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) { | ||
73 | let dataInput: VideoTranscodingPayload | ||
74 | |||
75 | if (videoFile.isAudio()) { | ||
76 | dataInput = { | ||
77 | type: 'merge-audio' as 'merge-audio', | ||
78 | resolution: DEFAULT_AUDIO_RESOLUTION, | ||
79 | videoUUID: video.uuid, | ||
80 | isNewVideo: true | ||
81 | } | ||
82 | } else { | ||
83 | dataInput = { | ||
84 | type: 'optimize' as 'optimize', | ||
85 | videoUUID: video.uuid, | ||
86 | isNewVideo: true | ||
87 | } | ||
88 | } | ||
89 | |||
90 | return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }) | ||
91 | } | ||
92 | |||
93 | function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { | ||
94 | return isStreamingPlaylist(videoOrPlaylist) | ||
95 | ? videoOrPlaylist.Video | ||
96 | : videoOrPlaylist | ||
97 | } | ||
98 | |||
65 | export { | 99 | export { |
66 | VideoFetchType, | 100 | VideoFetchType, |
67 | VideoFetchByUrlType, | 101 | VideoFetchByUrlType, |
68 | fetchVideo, | 102 | fetchVideo, |
69 | getVideoWithAttributes, | 103 | getVideoWithAttributes, |
70 | fetchVideoByUrl | 104 | fetchVideoByUrl, |
105 | addOptimizeOrMergeAudioJob, | ||
106 | extractVideo | ||
71 | } | 107 | } |