]>
Commit | Line | Data |
---|---|---|
c729caf6 | 1 | import { expect } from 'chai' |
5e47f6ab | 2 | import { checkPersistentTmpIsEmpty, checkVideoDuration, expectStartWith } from '@server/tests/shared' |
9ab330b9 | 3 | import { areMockObjectStorageTestsDisabled, getAllFiles } from '@shared/core-utils' |
92e66e04 | 4 | import { VideoStudioTask } from '@shared/models' |
c729caf6 C |
5 | import { |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | ObjectStorageCommand, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | setDefaultVideoChannel, | |
92e66e04 | 13 | VideoStudioCommand, |
c729caf6 C |
14 | waitJobs |
15 | } from '@shared/server-commands' | |
16 | ||
92e66e04 | 17 | describe('Test video studio', function () { |
c729caf6 C |
18 | let servers: PeerTubeServer[] = [] |
19 | let videoUUID: string | |
20 | ||
c729caf6 C |
21 | async function renewVideo (fixture = 'video_short.webm') { |
22 | const video = await servers[0].videos.quickUpload({ name: 'video', fixture }) | |
23 | videoUUID = video.uuid | |
24 | ||
25 | await waitJobs(servers) | |
26 | } | |
27 | ||
92e66e04 C |
28 | async function createTasks (tasks: VideoStudioTask[]) { |
29 | await servers[0].videoStudio.createEditionTasks({ videoId: videoUUID, tasks }) | |
c729caf6 C |
30 | await waitJobs(servers) |
31 | } | |
32 | ||
33 | before(async function () { | |
34 | this.timeout(120_000) | |
35 | ||
36 | servers = await createMultipleServers(2) | |
37 | ||
38 | await setAccessTokensToServers(servers) | |
39 | await setDefaultVideoChannel(servers) | |
40 | ||
41 | await doubleFollow(servers[0], servers[1]) | |
42 | ||
43 | await servers[0].config.enableMinimumTranscoding() | |
44 | ||
92e66e04 | 45 | await servers[0].config.enableStudio() |
c729caf6 C |
46 | }) |
47 | ||
48 | describe('Cutting', function () { | |
49 | ||
50 | it('Should cut the beginning of the video', async function () { | |
51 | this.timeout(120_000) | |
52 | ||
53 | await renewVideo() | |
54 | await waitJobs(servers) | |
55 | ||
56 | const beforeTasks = new Date() | |
57 | ||
58 | await createTasks([ | |
59 | { | |
60 | name: 'cut', | |
61 | options: { | |
62 | start: 2 | |
63 | } | |
64 | } | |
65 | ]) | |
66 | ||
67 | for (const server of servers) { | |
5e47f6ab | 68 | await checkVideoDuration(server, videoUUID, 3) |
c729caf6 C |
69 | |
70 | const video = await server.videos.get({ id: videoUUID }) | |
71 | expect(new Date(video.publishedAt)).to.be.below(beforeTasks) | |
72 | } | |
73 | }) | |
74 | ||
75 | it('Should cut the end of the video', async function () { | |
76 | this.timeout(120_000) | |
77 | await renewVideo() | |
78 | ||
79 | await createTasks([ | |
80 | { | |
81 | name: 'cut', | |
82 | options: { | |
83 | end: 2 | |
84 | } | |
85 | } | |
86 | ]) | |
87 | ||
88 | for (const server of servers) { | |
5e47f6ab | 89 | await checkVideoDuration(server, videoUUID, 2) |
c729caf6 C |
90 | } |
91 | }) | |
92 | ||
93 | it('Should cut start/end of the video', async function () { | |
94 | this.timeout(120_000) | |
95 | await renewVideo('video_short1.webm') // 10 seconds video duration | |
96 | ||
97 | await createTasks([ | |
98 | { | |
99 | name: 'cut', | |
100 | options: { | |
101 | start: 2, | |
102 | end: 6 | |
103 | } | |
104 | } | |
105 | ]) | |
106 | ||
107 | for (const server of servers) { | |
5e47f6ab | 108 | await checkVideoDuration(server, videoUUID, 4) |
c729caf6 C |
109 | } |
110 | }) | |
111 | }) | |
112 | ||
113 | describe('Intro/Outro', function () { | |
114 | ||
115 | it('Should add an intro', async function () { | |
116 | this.timeout(120_000) | |
117 | await renewVideo() | |
118 | ||
119 | await createTasks([ | |
120 | { | |
121 | name: 'add-intro', | |
122 | options: { | |
123 | file: 'video_short.webm' | |
124 | } | |
125 | } | |
126 | ]) | |
127 | ||
128 | for (const server of servers) { | |
5e47f6ab | 129 | await checkVideoDuration(server, videoUUID, 10) |
c729caf6 C |
130 | } |
131 | }) | |
132 | ||
133 | it('Should add an outro', async function () { | |
134 | this.timeout(120_000) | |
135 | await renewVideo() | |
136 | ||
137 | await createTasks([ | |
138 | { | |
139 | name: 'add-outro', | |
140 | options: { | |
141 | file: 'video_very_short_240p.mp4' | |
142 | } | |
143 | } | |
144 | ]) | |
145 | ||
146 | for (const server of servers) { | |
5e47f6ab | 147 | await checkVideoDuration(server, videoUUID, 7) |
c729caf6 C |
148 | } |
149 | }) | |
150 | ||
151 | it('Should add an intro/outro', async function () { | |
152 | this.timeout(120_000) | |
153 | await renewVideo() | |
154 | ||
155 | await createTasks([ | |
156 | { | |
157 | name: 'add-intro', | |
158 | options: { | |
159 | file: 'video_very_short_240p.mp4' | |
160 | } | |
161 | }, | |
162 | { | |
163 | name: 'add-outro', | |
164 | options: { | |
165 | // Different frame rate | |
166 | file: 'video_short2.webm' | |
167 | } | |
168 | } | |
169 | ]) | |
170 | ||
171 | for (const server of servers) { | |
5e47f6ab | 172 | await checkVideoDuration(server, videoUUID, 12) |
c729caf6 C |
173 | } |
174 | }) | |
175 | ||
176 | it('Should add an intro to a video without audio', async function () { | |
177 | this.timeout(120_000) | |
178 | await renewVideo('video_short_no_audio.mp4') | |
179 | ||
180 | await createTasks([ | |
181 | { | |
182 | name: 'add-intro', | |
183 | options: { | |
184 | file: 'video_very_short_240p.mp4' | |
185 | } | |
186 | } | |
187 | ]) | |
188 | ||
189 | for (const server of servers) { | |
5e47f6ab | 190 | await checkVideoDuration(server, videoUUID, 7) |
c729caf6 C |
191 | } |
192 | }) | |
193 | ||
194 | it('Should add an outro without audio to a video with audio', async function () { | |
195 | this.timeout(120_000) | |
196 | await renewVideo() | |
197 | ||
198 | await createTasks([ | |
199 | { | |
200 | name: 'add-outro', | |
201 | options: { | |
202 | file: 'video_short_no_audio.mp4' | |
203 | } | |
204 | } | |
205 | ]) | |
206 | ||
207 | for (const server of servers) { | |
5e47f6ab | 208 | await checkVideoDuration(server, videoUUID, 10) |
c729caf6 C |
209 | } |
210 | }) | |
211 | ||
212 | it('Should add an outro without audio to a video with audio', async function () { | |
213 | this.timeout(120_000) | |
214 | await renewVideo('video_short_no_audio.mp4') | |
215 | ||
216 | await createTasks([ | |
217 | { | |
218 | name: 'add-outro', | |
219 | options: { | |
220 | file: 'video_short_no_audio.mp4' | |
221 | } | |
222 | } | |
223 | ]) | |
224 | ||
225 | for (const server of servers) { | |
5e47f6ab | 226 | await checkVideoDuration(server, videoUUID, 10) |
c729caf6 C |
227 | } |
228 | }) | |
229 | }) | |
230 | ||
231 | describe('Watermark', function () { | |
232 | ||
233 | it('Should add a watermark to the video', async function () { | |
234 | this.timeout(120_000) | |
235 | await renewVideo() | |
236 | ||
237 | const video = await servers[0].videos.get({ id: videoUUID }) | |
238 | const oldFileUrls = getAllFiles(video).map(f => f.fileUrl) | |
239 | ||
240 | await createTasks([ | |
241 | { | |
242 | name: 'add-watermark', | |
243 | options: { | |
244 | file: 'thumbnail.png' | |
245 | } | |
246 | } | |
247 | ]) | |
248 | ||
249 | for (const server of servers) { | |
250 | const video = await server.videos.get({ id: videoUUID }) | |
251 | const fileUrls = getAllFiles(video).map(f => f.fileUrl) | |
252 | ||
253 | for (const oldUrl of oldFileUrls) { | |
254 | expect(fileUrls).to.not.include(oldUrl) | |
255 | } | |
256 | } | |
257 | }) | |
258 | }) | |
259 | ||
260 | describe('Complex tasks', function () { | |
261 | it('Should run a complex task', async function () { | |
262 | this.timeout(240_000) | |
263 | await renewVideo() | |
264 | ||
92e66e04 | 265 | await createTasks(VideoStudioCommand.getComplexTask()) |
c729caf6 C |
266 | |
267 | for (const server of servers) { | |
5e47f6ab | 268 | await checkVideoDuration(server, videoUUID, 9) |
c729caf6 C |
269 | } |
270 | }) | |
271 | }) | |
272 | ||
ab14f0e0 | 273 | describe('HLS only studio edition', function () { |
c729caf6 C |
274 | |
275 | before(async function () { | |
276 | // Disable webtorrent | |
277 | await servers[0].config.updateExistingSubConfig({ | |
278 | newConfig: { | |
279 | transcoding: { | |
280 | webtorrent: { | |
281 | enabled: false | |
282 | } | |
283 | } | |
284 | } | |
285 | }) | |
286 | }) | |
287 | ||
288 | it('Should run a complex task on HLS only video', async function () { | |
289 | this.timeout(240_000) | |
290 | await renewVideo() | |
291 | ||
92e66e04 | 292 | await createTasks(VideoStudioCommand.getComplexTask()) |
c729caf6 C |
293 | |
294 | for (const server of servers) { | |
295 | const video = await server.videos.get({ id: videoUUID }) | |
296 | expect(video.files).to.have.lengthOf(0) | |
297 | ||
5e47f6ab | 298 | await checkVideoDuration(server, videoUUID, 9) |
c729caf6 C |
299 | } |
300 | }) | |
301 | }) | |
302 | ||
ab14f0e0 | 303 | describe('Object storage studio edition', function () { |
9ab330b9 | 304 | if (areMockObjectStorageTestsDisabled()) return |
c729caf6 C |
305 | |
306 | before(async function () { | |
9ab330b9 | 307 | await ObjectStorageCommand.prepareDefaultMockBuckets() |
c729caf6 C |
308 | |
309 | await servers[0].kill() | |
9ab330b9 | 310 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig()) |
c729caf6 C |
311 | |
312 | await servers[0].config.enableMinimumTranscoding() | |
313 | }) | |
314 | ||
315 | it('Should run a complex task on a video in object storage', async function () { | |
316 | this.timeout(240_000) | |
317 | await renewVideo() | |
318 | ||
319 | const video = await servers[0].videos.get({ id: videoUUID }) | |
320 | const oldFileUrls = getAllFiles(video).map(f => f.fileUrl) | |
321 | ||
92e66e04 | 322 | await createTasks(VideoStudioCommand.getComplexTask()) |
c729caf6 C |
323 | |
324 | for (const server of servers) { | |
325 | const video = await server.videos.get({ id: videoUUID }) | |
326 | const files = getAllFiles(video) | |
327 | ||
328 | for (const f of files) { | |
329 | expect(oldFileUrls).to.not.include(f.fileUrl) | |
330 | } | |
331 | ||
332 | for (const webtorrentFile of video.files) { | |
9ab330b9 | 333 | expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) |
c729caf6 C |
334 | } |
335 | ||
336 | for (const hlsFile of video.streamingPlaylists[0].files) { | |
9ab330b9 | 337 | expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl()) |
c729caf6 C |
338 | } |
339 | ||
5e47f6ab | 340 | await checkVideoDuration(server, videoUUID, 9) |
c729caf6 C |
341 | } |
342 | }) | |
343 | }) | |
344 | ||
6a490560 C |
345 | describe('Server restart', function () { |
346 | ||
347 | it('Should still be able to run video edition after a server restart', async function () { | |
348 | this.timeout(240_000) | |
349 | ||
350 | await renewVideo() | |
351 | await servers[0].videoStudio.createEditionTasks({ videoId: videoUUID, tasks: VideoStudioCommand.getComplexTask() }) | |
352 | ||
353 | await servers[0].kill() | |
354 | await servers[0].run() | |
355 | ||
356 | await waitJobs(servers) | |
357 | ||
358 | for (const server of servers) { | |
5e47f6ab | 359 | await checkVideoDuration(server, videoUUID, 9) |
6a490560 C |
360 | } |
361 | }) | |
362 | ||
363 | it('Should have an empty persistent tmp directory', async function () { | |
364 | await checkPersistentTmpIsEmpty(servers[0]) | |
365 | }) | |
366 | }) | |
367 | ||
c729caf6 C |
368 | after(async function () { |
369 | await cleanupTests(servers) | |
370 | }) | |
371 | }) |