import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
-import { MIMETYPES, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants'
+import {
+ DEFAULT_AUDIO_RESOLUTION,
+ MIMETYPES,
+ VIDEO_CATEGORIES,
+ VIDEO_LANGUAGES,
+ VIDEO_LICENCES,
+ VIDEO_PRIVACIES
+} from '../../../initializers/constants'
import {
changeVideoChannelShare,
federateVideoIfNeeded,
import { sendView } from '../../../lib/activitypub/send/send-view'
import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database'
-import { createVideoThumbnailFromExisting, generateVideoThumbnail } from '../../../lib/thumbnail'
+import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
+import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding'
const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router()
nsfw: videoInfo.nsfw || false,
description: videoInfo.description,
support: videoInfo.support,
- privacy: videoInfo.privacy,
+ privacy: videoInfo.privacy || VideoPrivacy.PRIVATE,
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
channelId: res.locals.videoChannel.id,
originallyPublishedAt: videoInfo.originallyPublishedAt
const video = new VideoModel(videoData)
video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
- // Build the file object
- const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
- const fps = await getVideoFileFPS(videoPhysicalFile.path)
-
const videoFileData = {
extname: extname(videoPhysicalFile.filename),
- resolution: videoFileResolution,
- size: videoPhysicalFile.size,
- fps
+ size: videoPhysicalFile.size
}
const videoFile = new VideoFileModel(videoFileData)
+ if (!videoFile.isAudio()) {
+ videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path)
+ videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).videoFileResolution
+ } else {
+ videoFile.resolution = DEFAULT_AUDIO_RESOLUTION
+ }
+
// Move physical file
const videoDir = CONFIG.STORAGE.VIDEOS_DIR
const destination = join(videoDir, video.getVideoFilename(videoFile))
// Process thumbnail or create it from the video
const thumbnailField = req.files['thumbnailfile']
const thumbnailModel = thumbnailField
- ? await createVideoThumbnailFromExisting(thumbnailField[0].path, video, ThumbnailType.THUMBNAIL)
- : await generateVideoThumbnail(video, videoFile, ThumbnailType.THUMBNAIL)
+ ? await createVideoMiniatureFromExisting(thumbnailField[0].path, video, ThumbnailType.MINIATURE)
+ : await generateVideoMiniature(video, videoFile, ThumbnailType.MINIATURE)
// Process preview or create it from the video
const previewField = req.files['previewfile']
const previewModel = previewField
- ? await createVideoThumbnailFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW)
- : await generateVideoThumbnail(video, videoFile, ThumbnailType.PREVIEW)
+ ? await createVideoMiniatureFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW)
+ : await generateVideoMiniature(video, videoFile, ThumbnailType.PREVIEW)
// Create the torrent file
await video.createTorrentAndSetInfoHash(videoFile)
const videoCreated = await video.save(sequelizeOptions)
- thumbnailModel.videoId = videoCreated.id
- previewModel.videoId = videoCreated.id
-
- videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t }))
- videoCreated.addThumbnail(await previewModel.save({ transaction: t }))
+ await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
+ await videoCreated.addAndSaveThumbnail(previewModel, t)
// Do not forget to add video channel information to the created video
videoCreated.VideoChannel = res.locals.videoChannel
if (video.state === VideoState.TO_TRANSCODE) {
// Put uuid because we don't have id auto incremented for now
- const dataInput = {
- videoUUID: videoCreated.uuid,
- isNewVideo: true
+ let dataInput: VideoTranscodingPayload
+
+ if (videoFile.isAudio()) {
+ dataInput = {
+ type: 'merge-audio' as 'merge-audio',
+ resolution: DEFAULT_AUDIO_RESOLUTION,
+ videoUUID: videoCreated.uuid,
+ isNewVideo: true
+ }
+ } else {
+ dataInput = {
+ type: 'optimize' as 'optimize',
+ videoUUID: videoCreated.uuid,
+ isNewVideo: true
+ }
}
await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput })
// Process thumbnail or create it from the video
const thumbnailModel = req.files && req.files['thumbnailfile']
- ? await createVideoThumbnailFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.THUMBNAIL)
+ ? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE)
: undefined
const previewModel = req.files && req.files['previewfile']
- ? await createVideoThumbnailFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW)
+ ? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW)
: undefined
try {
if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled)
if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
- videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt)
+ videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt)
}
if (videoInfoToUpdate.privacy !== undefined) {
const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
- videoInstance.set('privacy', newPrivacy)
+ videoInstance.privacy = newPrivacy
if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
- videoInstance.set('publishedAt', new Date())
+ videoInstance.publishedAt = new Date()
}
}
const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
- if (thumbnailModel) {
- thumbnailModel.videoId = videoInstanceUpdated.id
- videoInstanceUpdated.addThumbnail(await thumbnailModel.save({ transaction: t }))
- }
- if (previewModel) {
- previewModel.videoId = videoInstanceUpdated.id
- videoInstanceUpdated.addThumbnail(await previewModel.save({ transaction: t }))
- }
+ if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t)
+ if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t)
// Video tags update?
if (videoInfoToUpdate.tags !== undefined) {