]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ffprobe helper
authorChocobozzz <me@florianbigard.com>
Thu, 16 Dec 2021 16:00:46 +0000 (17:00 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 16 Dec 2021 16:00:46 +0000 (17:00 +0100)
server/lib/plugins/plugin-helpers-builder.ts
server/tests/fixtures/peertube-plugin-test-four/main.js
server/tests/plugins/plugin-helpers.ts
server/types/plugins/register-server-option.model.ts

index bea0f89592c96d3ec7a8d5975ded5c0847849a4e..78e4a28ad6447cc11971903ab1680e3d9cc50746 100644 (file)
@@ -1,5 +1,6 @@
 import express from 'express'
 import { join } from 'path'
+import { ffprobePromise } from '@server/helpers/ffprobe-utils'
 import { buildLogger } from '@server/helpers/logger'
 import { CONFIG } from '@server/initializers/config'
 import { WEBSERVER } from '@server/initializers/constants'
@@ -88,6 +89,10 @@ function buildVideosHelpers () {
       })
     },
 
+    ffprobe: (path: string) => {
+      return ffprobePromise(path)
+    },
+
     getFiles: async (id: number | string) => {
       const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
       if (!video) return undefined
index edbb883e2c74920e237a61d3e45ed779fdceab25..bff42ff404d2e4070aff3d65257a676b1040250e 100644 (file)
@@ -111,6 +111,13 @@ async function register ({
 
       return res.json(details)
     })
+
+    router.get('/ffprobe', async (req, res) => {
+      const result = await peertubeHelpers.videos.ffprobe(req.query.path)
+      if (!result) return res.sendStatus(404)
+
+      return res.json(result)
+    })
   }
 
 }
index 26f66b0b13958f5947fd2927dde2a10511067240..da84658bbd04908b4509c1bd52a37ac9660910b9 100644 (file)
@@ -224,6 +224,7 @@ describe('Test plugin helpers', function () {
 
   describe('Videos', function () {
     let videoUUID: string
+    let videoPath: string
 
     before(async () => {
       this.timeout(240000)
@@ -260,6 +261,8 @@ describe('Test plugin helpers', function () {
             await makeRawRequest(file.url, HttpStatusCode.OK_200)
           }
         }
+
+        videoPath = body.webtorrent.videoFiles[0].path
       }
 
       // Thumbnails check
@@ -278,6 +281,20 @@ describe('Test plugin helpers', function () {
       }
     })
 
+    it('Should probe a file', async function () {
+      const { body } = await makeGetRequest({
+        url: servers[0].url,
+        path: '/plugins/test-four/router/ffprobe',
+        query: {
+          path: videoPath
+        },
+        expectedStatus: HttpStatusCode.OK_200
+      })
+
+      expect(body.streams).to.be.an('array')
+      expect(body.streams).to.have.lengthOf(2)
+    })
+
     it('Should remove a video after a view', async function () {
       this.timeout(40000)
 
index 473990eb6a2a920f4c50b922fd6708efff5071d2..9f472d900e4367002fff650648bfe977f340c298 100644 (file)
@@ -37,6 +37,8 @@ export type PeerTubeHelpers = {
 
     removeVideo: (videoId: number) => Promise<void>
 
+    ffprobe: (path: string) => Promise<any>
+
     getFiles: (id: number | string) => Promise<{
       webtorrent: {
         videoFiles: {