aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-03-10 14:39:40 +0100
committerGitHub <noreply@github.com>2020-03-10 14:39:40 +0100
commit8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4 (patch)
tree1f87041b2cd76222844960602cdc9f52fe206c7b /server/controllers/api/videos/index.ts
parentedb868655e52f934a71141175cf9dc6cb4753e11 (diff)
downloadPeerTube-8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4.tar.gz
PeerTube-8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4.tar.zst
PeerTube-8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4.zip
Add video file metadata to download modal, via ffprobe (#2411)
* Add video file metadata via ffprobe * Federate video file metadata * Add tests for file metadata generation * Complete tests for videoFile metadata federation * Lint migration and video-file for metadata * Objectify metadata from getter in ffmpeg-utils * Add metadataUrl to all videoFiles * Simplify metadata API middleware * Load playlist in videoFile when requesting metadata
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index eb46ea01f..9b19c394d 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { extname } from 'path' 2import { extname } from 'path'
3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' 3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared'
4import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 4import { getVideoFileFPS, getVideoFileResolution, getMetadataFromFile } from '../../../helpers/ffmpeg-utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 6import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
7import { getFormattedObjects, getServerActor } from '../../../helpers/utils' 7import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
@@ -37,7 +37,8 @@ import {
37 videosGetValidator, 37 videosGetValidator,
38 videosRemoveValidator, 38 videosRemoveValidator,
39 videosSortValidator, 39 videosSortValidator,
40 videosUpdateValidator 40 videosUpdateValidator,
41 videoFileMetadataGetValidator
41} from '../../../middlewares' 42} from '../../../middlewares'
42import { TagModel } from '../../../models/video/tag' 43import { TagModel } from '../../../models/video/tag'
43import { VideoModel } from '../../../models/video/video' 44import { VideoModel } from '../../../models/video/video'
@@ -66,6 +67,7 @@ import { Hooks } from '../../../lib/plugins/hooks'
66import { MVideoDetails, MVideoFullLight } from '@server/typings/models' 67import { MVideoDetails, MVideoFullLight } from '@server/typings/models'
67import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 68import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
68import { getVideoFilePath } from '@server/lib/video-paths' 69import { getVideoFilePath } from '@server/lib/video-paths'
70import toInt from 'validator/lib/toInt'
69 71
70const auditLogger = auditLoggerFactory('videos') 72const auditLogger = auditLoggerFactory('videos')
71const videosRouter = express.Router() 73const videosRouter = express.Router()
@@ -128,6 +130,10 @@ videosRouter.get('/:id/description',
128 asyncMiddleware(videosGetValidator), 130 asyncMiddleware(videosGetValidator),
129 asyncMiddleware(getVideoDescription) 131 asyncMiddleware(getVideoDescription)
130) 132)
133videosRouter.get('/:id/metadata/:videoFileId',
134 asyncMiddleware(videoFileMetadataGetValidator),
135 asyncMiddleware(getVideoFileMetadata)
136)
131videosRouter.get('/:id', 137videosRouter.get('/:id',
132 optionalAuthenticate, 138 optionalAuthenticate,
133 asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), 139 asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
@@ -206,7 +212,8 @@ async function addVideo (req: express.Request, res: express.Response) {
206 const videoFile = new VideoFileModel({ 212 const videoFile = new VideoFileModel({
207 extname: extname(videoPhysicalFile.filename), 213 extname: extname(videoPhysicalFile.filename),
208 size: videoPhysicalFile.size, 214 size: videoPhysicalFile.size,
209 videoStreamingPlaylistId: null 215 videoStreamingPlaylistId: null,
216 metadata: await getMetadataFromFile<any>(videoPhysicalFile.path)
210 }) 217 })
211 218
212 if (videoFile.isAudio()) { 219 if (videoFile.isAudio()) {
@@ -493,6 +500,11 @@ async function getVideoDescription (req: express.Request, res: express.Response)
493 return res.json({ description }) 500 return res.json({ description })
494} 501}
495 502
503async function getVideoFileMetadata (req: express.Request, res: express.Response) {
504 const videoFile = await VideoFileModel.loadWithMetadata(toInt(req.params.videoFileId))
505 return res.json(videoFile.metadata)
506}
507
496async function listVideos (req: express.Request, res: express.Response) { 508async function listVideos (req: express.Request, res: express.Response) {
497 const countVideos = getCountVideos(req) 509 const countVideos = getCountVideos(req)
498 510