aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-16 17:00:46 +0100
committerChocobozzz <me@florianbigard.com>2021-12-16 17:00:46 +0100
commit754c52b9b998a825fd830d5ac527a67e0eefeb9a (patch)
tree05c914b34bdc3524ad74a5cb86a834d86663d8be
parent2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481 (diff)
downloadPeerTube-754c52b9b998a825fd830d5ac527a67e0eefeb9a.tar.gz
PeerTube-754c52b9b998a825fd830d5ac527a67e0eefeb9a.tar.zst
PeerTube-754c52b9b998a825fd830d5ac527a67e0eefeb9a.zip
Add ffprobe helper
-rw-r--r--server/lib/plugins/plugin-helpers-builder.ts5
-rw-r--r--server/tests/fixtures/peertube-plugin-test-four/main.js7
-rw-r--r--server/tests/plugins/plugin-helpers.ts17
-rw-r--r--server/types/plugins/register-server-option.model.ts2
4 files changed, 31 insertions, 0 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts
index bea0f8959..78e4a28ad 100644
--- a/server/lib/plugins/plugin-helpers-builder.ts
+++ b/server/lib/plugins/plugin-helpers-builder.ts
@@ -1,5 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { join } from 'path' 2import { join } from 'path'
3import { ffprobePromise } from '@server/helpers/ffprobe-utils'
3import { buildLogger } from '@server/helpers/logger' 4import { buildLogger } from '@server/helpers/logger'
4import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
5import { WEBSERVER } from '@server/initializers/constants' 6import { WEBSERVER } from '@server/initializers/constants'
@@ -88,6 +89,10 @@ function buildVideosHelpers () {
88 }) 89 })
89 }, 90 },
90 91
92 ffprobe: (path: string) => {
93 return ffprobePromise(path)
94 },
95
91 getFiles: async (id: number | string) => { 96 getFiles: async (id: number | string) => {
92 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id) 97 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
93 if (!video) return undefined 98 if (!video) return undefined
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js
index edbb883e2..bff42ff40 100644
--- a/server/tests/fixtures/peertube-plugin-test-four/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-four/main.js
@@ -111,6 +111,13 @@ async function register ({
111 111
112 return res.json(details) 112 return res.json(details)
113 }) 113 })
114
115 router.get('/ffprobe', async (req, res) => {
116 const result = await peertubeHelpers.videos.ffprobe(req.query.path)
117 if (!result) return res.sendStatus(404)
118
119 return res.json(result)
120 })
114 } 121 }
115 122
116} 123}
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index 26f66b0b1..da84658bb 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -224,6 +224,7 @@ describe('Test plugin helpers', function () {
224 224
225 describe('Videos', function () { 225 describe('Videos', function () {
226 let videoUUID: string 226 let videoUUID: string
227 let videoPath: string
227 228
228 before(async () => { 229 before(async () => {
229 this.timeout(240000) 230 this.timeout(240000)
@@ -260,6 +261,8 @@ describe('Test plugin helpers', function () {
260 await makeRawRequest(file.url, HttpStatusCode.OK_200) 261 await makeRawRequest(file.url, HttpStatusCode.OK_200)
261 } 262 }
262 } 263 }
264
265 videoPath = body.webtorrent.videoFiles[0].path
263 } 266 }
264 267
265 // Thumbnails check 268 // Thumbnails check
@@ -278,6 +281,20 @@ describe('Test plugin helpers', function () {
278 } 281 }
279 }) 282 })
280 283
284 it('Should probe a file', async function () {
285 const { body } = await makeGetRequest({
286 url: servers[0].url,
287 path: '/plugins/test-four/router/ffprobe',
288 query: {
289 path: videoPath
290 },
291 expectedStatus: HttpStatusCode.OK_200
292 })
293
294 expect(body.streams).to.be.an('array')
295 expect(body.streams).to.have.lengthOf(2)
296 })
297
281 it('Should remove a video after a view', async function () { 298 it('Should remove a video after a view', async function () {
282 this.timeout(40000) 299 this.timeout(40000)
283 300
diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts
index 473990eb6..9f472d900 100644
--- a/server/types/plugins/register-server-option.model.ts
+++ b/server/types/plugins/register-server-option.model.ts
@@ -37,6 +37,8 @@ export type PeerTubeHelpers = {
37 37
38 removeVideo: (videoId: number) => Promise<void> 38 removeVideo: (videoId: number) => Promise<void>
39 39
40 ffprobe: (path: string) => Promise<any>
41
40 getFiles: (id: number | string) => Promise<{ 42 getFiles: (id: number | string) => Promise<{
41 webtorrent: { 43 webtorrent: {
42 videoFiles: { 44 videoFiles: {