+
+async function commonVideoChecksPass (parameters: {
+ req: express.Request
+ res: express.Response
+ user: MUserAccountId
+ videoFileSize: number
+ files: express.UploadFilesForCheck
+}): Promise<boolean> {
+ const { req, res, user, videoFileSize, files } = parameters
+
+ if (areErrorsInScheduleUpdate(req, res)) return false
+
+ if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return false
+
+ if (!isVideoFileMimeTypeValid(files)) {
+ res.fail({
+ status: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
+ message: 'This file is not supported. Please, make sure it is of the following type: ' +
+ CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ')
+ })
+ return false
+ }
+
+ if (!isVideoFileSizeValid(videoFileSize.toString())) {
+ res.fail({
+ status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
+ message: 'This file is too large. It exceeds the maximum file size authorized.',
+ type: ServerErrorCode.MAX_FILE_SIZE_REACHED
+ })
+ return false
+ }
+
+ if (await checkUserQuota(user, videoFileSize, res) === false) return false
+
+ return true
+}
+
+export async function isVideoAccepted (
+ req: express.Request,
+ res: express.Response,
+ videoFile: express.VideoUploadFile
+) {
+ // Check we accept this video
+ const acceptParameters = {
+ videoBody: req.body,
+ videoFile,
+ user: res.locals.oauth.token.User
+ }
+ const acceptedResult = await Hooks.wrapFun(
+ isLocalVideoAccepted,
+ acceptParameters,
+ 'filter:api.video.upload.accept.result'
+ )
+
+ if (!acceptedResult || acceptedResult.accepted !== true) {
+ logger.info('Refused local video.', { acceptedResult, acceptParameters })
+ res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: acceptedResult.errorMessage || 'Refused local video'
+ })
+ return false
+ }
+
+ return true
+}
+
+async function addDurationToVideo (videoFile: { path: string, duration?: number }) {
+ const duration = await getVideoStreamDuration(videoFile.path)
+
+ // FFmpeg may not be able to guess video duration
+ // For example with m2v files: https://trac.ffmpeg.org/ticket/9726#comment:2
+ if (isNaN(duration)) videoFile.duration = 0
+ else videoFile.duration = duration
+}