import * as express from 'express'
import { extname } from 'path'
import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared'
-import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
+import { getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
import { logger } from '../../../helpers/logger'
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
-import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
+import { getFormattedObjects } from '../../../helpers/utils'
import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
import {
DEFAULT_AUDIO_RESOLUTION,
VIDEO_CATEGORIES,
VIDEO_LANGUAGES,
VIDEO_LICENCES,
- VIDEO_PRIVACIES,
- VIDEO_TRANSCODING_FPS
+ VIDEO_PRIVACIES
} from '../../../initializers/constants'
-import {
- changeVideoChannelShare,
- federateVideoIfNeeded,
- fetchRemoteVideoDescription,
- getVideoActivityPubUrl
-} from '../../../lib/activitypub'
+import { federateVideoIfNeeded, fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
import { JobQueue } from '../../../lib/job-queue'
import { Redis } from '../../../lib/redis'
import {
paginationValidator,
setDefaultPagination,
setDefaultSort,
+ videoFileMetadataGetValidator,
videosAddValidator,
videosCustomGetValidator,
videosGetValidator,
import { sequelizeTypescript } from '../../../initializers/database'
import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
-import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding'
import { Hooks } from '../../../lib/plugins/hooks'
-import { MVideoDetails, MVideoFullLight } from '@server/typings/models'
+import { MVideoDetails, MVideoFullLight } from '@server/types/models'
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
import { getVideoFilePath } from '@server/lib/video-paths'
+import toInt from 'validator/lib/toInt'
+import { addOptimizeOrMergeAudioJob } from '@server/helpers/video'
+import { getServerActor } from '@server/models/application/application'
+import { changeVideoChannelShare } from '@server/lib/activitypub/share'
+import { getVideoActivityPubUrl } from '@server/lib/activitypub/url'
const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router()
asyncMiddleware(videosGetValidator),
asyncMiddleware(getVideoDescription)
)
+videosRouter.get('/:id/metadata/:videoFileId',
+ asyncMiddleware(videoFileMetadataGetValidator),
+ asyncMiddleware(getVideoFileMetadata)
+)
videosRouter.get('/:id',
optionalAuthenticate,
asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
asyncMiddleware(getVideo)
)
videosRouter.post('/:id/views',
- asyncMiddleware(videosGetValidator),
+ asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
asyncMiddleware(viewVideo)
)
const videoFile = new VideoFileModel({
extname: extname(videoPhysicalFile.filename),
size: videoPhysicalFile.size,
- videoStreamingPlaylistId: null
+ videoStreamingPlaylistId: null,
+ metadata: await getMetadataFromFile<any>(videoPhysicalFile.path)
})
if (videoFile.isAudio()) {
Notifier.Instance.notifyOnNewVideoIfNeeded(videoCreated)
if (video.state === VideoState.TO_TRANSCODE) {
- // Put uuid because we don't have id auto incremented for now
- 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 })
+ await addOptimizeOrMergeAudioJob(videoCreated, videoFile)
}
Hooks.runAction('action:api.video.uploaded', { video: videoCreated })
const hadPrivacyForFederation = videoInstance.hasPrivacyForFederation()
// Process thumbnail or create it from the video
- const thumbnailModel = req.files && req.files['thumbnailfile']
+ const thumbnailModel = req.files?.['thumbnailfile']
? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE, false)
: undefined
- const previewModel = req.files && req.files['previewfile']
+ const previewModel = req.files?.['previewfile']
? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW, false)
: undefined
if (video.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
- .catch(err => logger.error('Cannot create AP refresher job for video %s.', video.url, { err }))
}
return res.json(video.toFormattedDetailsJSON())
}
async function viewVideo (req: express.Request, res: express.Response) {
- const videoInstance = res.locals.videoAll
+ const videoInstance = res.locals.onlyImmutableVideo
const ip = req.ip
const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid)
return res.json({ description })
}
+async function getVideoFileMetadata (req: express.Request, res: express.Response) {
+ const videoFile = await VideoFileModel.loadWithMetadata(toInt(req.params.videoFileId))
+
+ return res.json(videoFile.metadata)
+}
+
async function listVideos (req: express.Request, res: express.Response) {
const countVideos = getCountVideos(req)