diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-03-10 14:39:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 14:39:40 +0100 |
commit | 8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4 (patch) | |
tree | 1f87041b2cd76222844960602cdc9f52fe206c7b /server/controllers/api/videos | |
parent | edb868655e52f934a71141175cf9dc6cb4753e11 (diff) | |
download | PeerTube-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')
-rw-r--r-- | server/controllers/api/videos/index.ts | 18 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { extname } from 'path' | 2 | import { extname } from 'path' |
3 | import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' | 3 | import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' |
4 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 4 | import { getVideoFileFPS, getVideoFileResolution, getMetadataFromFile } from '../../../helpers/ffmpeg-utils' |
5 | import { logger } from '../../../helpers/logger' | 5 | 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' |
@@ -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' |
42 | import { TagModel } from '../../../models/video/tag' | 43 | import { TagModel } from '../../../models/video/tag' |
43 | import { VideoModel } from '../../../models/video/video' | 44 | import { VideoModel } from '../../../models/video/video' |
@@ -66,6 +67,7 @@ import { Hooks } from '../../../lib/plugins/hooks' | |||
66 | import { MVideoDetails, MVideoFullLight } from '@server/typings/models' | 67 | import { MVideoDetails, MVideoFullLight } from '@server/typings/models' |
67 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | 68 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
68 | import { getVideoFilePath } from '@server/lib/video-paths' | 69 | import { getVideoFilePath } from '@server/lib/video-paths' |
70 | import toInt from 'validator/lib/toInt' | ||
69 | 71 | ||
70 | const auditLogger = auditLoggerFactory('videos') | 72 | const auditLogger = auditLoggerFactory('videos') |
71 | const videosRouter = express.Router() | 73 | const 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 | ) |
133 | videosRouter.get('/:id/metadata/:videoFileId', | ||
134 | asyncMiddleware(videoFileMetadataGetValidator), | ||
135 | asyncMiddleware(getVideoFileMetadata) | ||
136 | ) | ||
131 | videosRouter.get('/:id', | 137 | videosRouter.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 | ||
503 | async 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 | |||
496 | async function listVideos (req: express.Request, res: express.Response) { | 508 | async function listVideos (req: express.Request, res: express.Response) { |
497 | const countVideos = getCountVideos(req) | 509 | const countVideos = getCountVideos(req) |
498 | 510 | ||