aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/videos/video-studio-command.ts
blob: 9fe467cc292a5ad93ee80d41ac05dd985046cc3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { HttpStatusCode, VideoStudioTask } from '@shared/models'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class VideoStudioCommand extends AbstractCommand {

  static getComplexTask (): VideoStudioTask[] {
    return [
      // Total duration: 2
      {
        name: 'cut',
        options: {
          start: 1,
          end: 3
        }
      },

      // Total duration: 7
      {
        name: 'add-outro',
        options: {
          file: 'video_short.webm'
        }
      },

      {
        name: 'add-watermark',
        options: {
          file: 'thumbnail.png'
        }
      },

      // Total duration: 9
      {
        name: 'add-intro',
        options: {
          file: 'video_very_short_240p.mp4'
        }
      }
    ]
  }

  createEditionTasks (options: OverrideCommandOptions & {
    videoId: number | string
    tasks: VideoStudioTask[]
  }) {
    const path = '/api/v1/videos/' + options.videoId + '/studio/edit'
    const attaches: { [id: string]: any } = {}

    for (let i = 0; i < options.tasks.length; i++) {
      const task = options.tasks[i]

      if (task.name === 'add-intro' || task.name === 'add-outro' || task.name === 'add-watermark') {
        attaches[`tasks[${i}][options][file]`] = task.options.file
      }
    }

    return this.postUploadRequest({
      ...options,

      path,
      attaches,
      fields: { tasks: options.tasks },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }
}