]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/video-studio.ts
Add test on AP hooks
[github/Chocobozzz/PeerTube.git] / server / lib / video-studio.ts
1 import { MVideoFullLight } from '@server/types/models'
2 import { getVideoStreamDuration } from '@shared/extra-utils'
3 import { VideoStudioTask } from '@shared/models'
4
5 function buildTaskFileFieldname (indice: number, fieldName = 'file') {
6 return `tasks[${indice}][options][${fieldName}]`
7 }
8
9 function getTaskFile (files: Express.Multer.File[], indice: number, fieldName = 'file') {
10 return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName))
11 }
12
13 async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) {
14 let additionalDuration = 0
15
16 for (let i = 0; i < tasks.length; i++) {
17 const task = tasks[i]
18
19 if (task.name !== 'add-intro' && task.name !== 'add-outro') continue
20
21 const filePath = fileFinder(i)
22 additionalDuration += await getVideoStreamDuration(filePath)
23 }
24
25 return (video.getMaxQualityFile().size / video.duration) * additionalDuration
26 }
27
28 export {
29 approximateIntroOutroAdditionalSize,
30 buildTaskFileFieldname,
31 getTaskFile
32 }