diff options
author | Chocobozzz <me@florianbigard.com> | 2019-05-21 10:05:12 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-05-21 10:05:12 +0200 |
commit | 73b3aa6429dfb2e31628fa09a479dce318289d7d (patch) | |
tree | 88cf5c7c49ba89c18633a4a64a4acfc8d40b4a50 /server/controllers/api/videos/index.ts | |
parent | fd822c1c699fb89bb1c3218e047e1d842bc1ba1a (diff) | |
parent | 618750486ee2732e0ad3525349e4d42f29e1803e (diff) | |
download | PeerTube-73b3aa6429dfb2e31628fa09a479dce318289d7d.tar.gz PeerTube-73b3aa6429dfb2e31628fa09a479dce318289d7d.tar.zst PeerTube-73b3aa6429dfb2e31628fa09a479dce318289d7d.zip |
Merge branch 'feature/audio-upload' into develop
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 1a18a8ae8..40a2c972b 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -6,7 +6,14 @@ import { logger } from '../../../helpers/logger' | |||
6 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 6 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
7 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' | 7 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' |
8 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | 8 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' |
9 | import { MIMETYPES, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' | 9 | import { |
10 | DEFAULT_AUDIO_RESOLUTION, | ||
11 | MIMETYPES, | ||
12 | VIDEO_CATEGORIES, | ||
13 | VIDEO_LANGUAGES, | ||
14 | VIDEO_LICENCES, | ||
15 | VIDEO_PRIVACIES | ||
16 | } from '../../../initializers/constants' | ||
10 | import { | 17 | import { |
11 | changeVideoChannelShare, | 18 | changeVideoChannelShare, |
12 | federateVideoIfNeeded, | 19 | federateVideoIfNeeded, |
@@ -54,6 +61,7 @@ import { CONFIG } from '../../../initializers/config' | |||
54 | import { sequelizeTypescript } from '../../../initializers/database' | 61 | import { sequelizeTypescript } from '../../../initializers/database' |
55 | import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' | 62 | import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' |
56 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 63 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
64 | import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' | ||
57 | 65 | ||
58 | const auditLogger = auditLoggerFactory('videos') | 66 | const auditLogger = auditLoggerFactory('videos') |
59 | const videosRouter = express.Router() | 67 | const videosRouter = express.Router() |
@@ -191,18 +199,19 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
191 | const video = new VideoModel(videoData) | 199 | const video = new VideoModel(videoData) |
192 | video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object | 200 | video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object |
193 | 201 | ||
194 | // Build the file object | ||
195 | const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path) | ||
196 | const fps = await getVideoFileFPS(videoPhysicalFile.path) | ||
197 | |||
198 | const videoFileData = { | 202 | const videoFileData = { |
199 | extname: extname(videoPhysicalFile.filename), | 203 | extname: extname(videoPhysicalFile.filename), |
200 | resolution: videoFileResolution, | 204 | size: videoPhysicalFile.size |
201 | size: videoPhysicalFile.size, | ||
202 | fps | ||
203 | } | 205 | } |
204 | const videoFile = new VideoFileModel(videoFileData) | 206 | const videoFile = new VideoFileModel(videoFileData) |
205 | 207 | ||
208 | if (!videoFile.isAudio()) { | ||
209 | videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path) | ||
210 | videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).videoFileResolution | ||
211 | } else { | ||
212 | videoFile.resolution = DEFAULT_AUDIO_RESOLUTION | ||
213 | } | ||
214 | |||
206 | // Move physical file | 215 | // Move physical file |
207 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR | 216 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR |
208 | const destination = join(videoDir, video.getVideoFilename(videoFile)) | 217 | const destination = join(videoDir, video.getVideoFilename(videoFile)) |
@@ -279,9 +288,21 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
279 | 288 | ||
280 | if (video.state === VideoState.TO_TRANSCODE) { | 289 | if (video.state === VideoState.TO_TRANSCODE) { |
281 | // Put uuid because we don't have id auto incremented for now | 290 | // Put uuid because we don't have id auto incremented for now |
282 | const dataInput = { | 291 | let dataInput: VideoTranscodingPayload |
283 | videoUUID: videoCreated.uuid, | 292 | |
284 | isNewVideo: true | 293 | if (videoFile.isAudio()) { |
294 | dataInput = { | ||
295 | type: 'merge-audio' as 'merge-audio', | ||
296 | resolution: DEFAULT_AUDIO_RESOLUTION, | ||
297 | videoUUID: videoCreated.uuid, | ||
298 | isNewVideo: true | ||
299 | } | ||
300 | } else { | ||
301 | dataInput = { | ||
302 | type: 'optimize' as 'optimize', | ||
303 | videoUUID: videoCreated.uuid, | ||
304 | isNewVideo: true | ||
305 | } | ||
285 | } | 306 | } |
286 | 307 | ||
287 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) | 308 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) |