]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-studio.ts
feature/ability to disable video history by default (#5728)
[github/Chocobozzz/PeerTube.git] / server / lib / video-studio.ts
CommitLineData
92e66e04
C
1import { MVideoFullLight } from '@server/types/models'
2import { getVideoStreamDuration } from '@shared/extra-utils'
3import { VideoStudioTask } from '@shared/models'
c729caf6
C
4
5function buildTaskFileFieldname (indice: number, fieldName = 'file') {
6 return `tasks[${indice}][options][${fieldName}]`
7}
8
9function getTaskFile (files: Express.Multer.File[], indice: number, fieldName = 'file') {
10 return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName))
11}
12
92e66e04 13async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) {
c729caf6
C
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
28export {
29 approximateIntroOutroAdditionalSize,
30 buildTaskFileFieldname,
31 getTaskFile
32}