aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-22 14:28:03 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-07-26 11:29:31 +0200
commit83903cb65d531a6b6b91715387493ba8312b264d (patch)
treefd172e26a483331e74f15a062743a9d40d4016d3 /server/tests/api/videos
parentc4fa01f7c45b66b112ebd08abce744b7c4041feb (diff)
downloadPeerTube-83903cb65d531a6b6b91715387493ba8312b264d.tar.gz
PeerTube-83903cb65d531a6b6b91715387493ba8312b264d.tar.zst
PeerTube-83903cb65d531a6b6b91715387493ba8312b264d.zip
Generate random uuid for video files
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/audio-only.ts12
-rw-r--r--server/tests/api/videos/multiple-servers.ts21
-rw-r--r--server/tests/api/videos/resumable-upload.ts8
-rw-r--r--server/tests/api/videos/single-server.ts3
-rw-r--r--server/tests/api/videos/video-captions.ts5
-rw-r--r--server/tests/api/videos/video-change-ownership.ts16
-rw-r--r--server/tests/api/videos/video-hls.ts17
-rw-r--r--server/tests/api/videos/video-transcoder.ts60
8 files changed, 90 insertions, 52 deletions
diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts
index 15c3ae6d6..7fac6e738 100644
--- a/server/tests/api/videos/audio-only.ts
+++ b/server/tests/api/videos/audio-only.ts
@@ -2,7 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path'
6import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' 5import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
7import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 6import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
8 7
@@ -11,6 +10,8 @@ const expect = chai.expect
11describe('Test audio only video transcoding', function () { 10describe('Test audio only video transcoding', function () {
12 let servers: PeerTubeServer[] = [] 11 let servers: PeerTubeServer[] = []
13 let videoUUID: string 12 let videoUUID: string
13 let webtorrentAudioFileUrl: string
14 let fragmentedAudioFileUrl: string
14 15
15 before(async function () { 16 before(async function () {
16 this.timeout(120000) 17 this.timeout(120000)
@@ -63,13 +64,18 @@ describe('Test audio only video transcoding', function () {
63 expect(files[1].resolution.id).to.equal(240) 64 expect(files[1].resolution.id).to.equal(240)
64 expect(files[2].resolution.id).to.equal(0) 65 expect(files[2].resolution.id).to.equal(0)
65 } 66 }
67
68 if (server.serverNumber === 1) {
69 webtorrentAudioFileUrl = video.files[2].fileUrl
70 fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl
71 }
66 } 72 }
67 }) 73 })
68 74
69 it('0p transcoded video should not have video', async function () { 75 it('0p transcoded video should not have video', async function () {
70 const paths = [ 76 const paths = [
71 servers[0].servers.buildDirectory(join('videos', videoUUID + '-0.mp4')), 77 servers[0].servers.buildWebTorrentFilePath(webtorrentAudioFileUrl),
72 servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) 78 servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl)
73 ] 79 ]
74 80
75 for (const path of paths) { 81 for (const path of paths) {
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index d916abb09..f9220e4b3 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -13,6 +13,7 @@ import {
13 dateIsValid, 13 dateIsValid,
14 doubleFollow, 14 doubleFollow,
15 PeerTubeServer, 15 PeerTubeServer,
16 saveVideoInServers,
16 setAccessTokensToServers, 17 setAccessTokensToServers,
17 testImage, 18 testImage,
18 wait, 19 wait,
@@ -661,19 +662,19 @@ describe('Test multiple servers', function () {
661 } 662 }
662 }) 663 })
663 664
664 it('Should remove the videos 3 and 3-2 by asking server 3', async function () { 665 it('Should remove the videos 3 and 3-2 by asking server 3 and correctly delete files', async function () {
665 this.timeout(10000) 666 this.timeout(30000)
666 667
667 await servers[2].videos.remove({ id: toRemove[0].id }) 668 for (const id of [ toRemove[0].id, toRemove[1].id ]) {
668 await servers[2].videos.remove({ id: toRemove[1].id }) 669 await saveVideoInServers(servers, id)
669 670
670 await waitJobs(servers) 671 await servers[2].videos.remove({ id })
671 })
672 672
673 it('Should not have files of videos 3 and 3-2 on each server', async function () { 673 await waitJobs(servers)
674 for (const server of servers) { 674
675 await checkVideoFilesWereRemoved(toRemove[0].uuid, server) 675 for (const server of servers) {
676 await checkVideoFilesWereRemoved(toRemove[1].uuid, server) 676 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
677 }
677 } 678 }
678 }) 679 })
679 680
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index a2d60eeec..c94d92cf2 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -99,8 +99,8 @@ describe('Test resumable upload', function () {
99 this.timeout(30000) 99 this.timeout(30000)
100 100
101 server = await createSingleServer(1) 101 server = await createSingleServer(1)
102 await setAccessTokensToServers([server]) 102 await setAccessTokensToServers([ server ])
103 await setDefaultVideoChannel([server]) 103 await setDefaultVideoChannel([ server ])
104 104
105 const body = await server.users.getMyInfo() 105 const body = await server.users.getMyInfo()
106 rootId = body.id 106 rootId = body.id
@@ -170,13 +170,13 @@ describe('Test resumable upload', function () {
170 170
171 const size = 1000 171 const size = 1000
172 172
173 const contentRangeBuilder = start => `bytes ${start}-${start + size - 1}/${size}` 173 const contentRangeBuilder = (start: number) => `bytes ${start}-${start + size - 1}/${size}`
174 await sendChunks({ pathUploadId: uploadId, expectedStatus: HttpStatusCode.CONFLICT_409, contentRangeBuilder, contentLength: size }) 174 await sendChunks({ pathUploadId: uploadId, expectedStatus: HttpStatusCode.CONFLICT_409, contentRangeBuilder, contentLength: size })
175 await checkFileSize(uploadId, 0) 175 await checkFileSize(uploadId, 0)
176 }) 176 })
177 }) 177 })
178 178
179 after(async function () { 179 after(async function () {
180 await cleanupTests([server]) 180 await cleanupTests([ server ])
181 }) 181 })
182}) 182})
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index c0535be09..29dac6ec1 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -199,9 +199,10 @@ describe('Test a single server', function () {
199 }) 199 })
200 200
201 it('Should remove the video', async function () { 201 it('Should remove the video', async function () {
202 const video = await server.videos.get({ id: videoId })
202 await server.videos.remove({ id: videoId }) 203 await server.videos.remove({ id: videoId })
203 204
204 await checkVideoFilesWereRemoved(videoUUID, server) 205 await checkVideoFilesWereRemoved({ video, server })
205 }) 206 })
206 207
207 it('Should not have videos', async function () { 208 it('Should not have videos', async function () {
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index 4c8e28adf..3bb0d131c 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -178,9 +178,12 @@ describe('Test video captions', function () {
178 }) 178 })
179 179
180 it('Should remove the video, and thus all video captions', async function () { 180 it('Should remove the video, and thus all video captions', async function () {
181 const video = await servers[0].videos.get({ id: videoUUID })
182 const { data: captions } = await servers[0].captions.list({ videoId: videoUUID })
183
181 await servers[0].videos.remove({ id: videoUUID }) 184 await servers[0].videos.remove({ id: videoUUID })
182 185
183 await checkVideoFilesWereRemoved(videoUUID, servers[0]) 186 await checkVideoFilesWereRemoved({ server: servers[0], video, captions })
184 }) 187 })
185 188
186 after(async function () { 189 after(async function () {
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 6ae6d3004..d6665fe4e 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -73,7 +73,7 @@ describe('Test video change ownership - nominal', function () {
73 } 73 }
74 const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes }) 74 const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes })
75 75
76 servers[0].store.video = await servers[0].videos.get({ id }) 76 servers[0].store.videoCreated = await servers[0].videos.get({ id })
77 } 77 }
78 78
79 { 79 {
@@ -109,7 +109,7 @@ describe('Test video change ownership - nominal', function () {
109 it('Should send a request to change ownership of a video', async function () { 109 it('Should send a request to change ownership of a video', async function () {
110 this.timeout(15000) 110 this.timeout(15000)
111 111
112 await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) 112 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
113 }) 113 })
114 114
115 it('Should only return a request to change ownership for the second user', async function () { 115 it('Should only return a request to change ownership for the second user', async function () {
@@ -135,7 +135,7 @@ describe('Test video change ownership - nominal', function () {
135 it('Should accept the same change ownership request without crashing', async function () { 135 it('Should accept the same change ownership request without crashing', async function () {
136 this.timeout(10000) 136 this.timeout(10000)
137 137
138 await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) 138 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
139 }) 139 })
140 140
141 it('Should not create multiple change ownership requests while one is waiting', async function () { 141 it('Should not create multiple change ownership requests while one is waiting', async function () {
@@ -163,7 +163,7 @@ describe('Test video change ownership - nominal', function () {
163 it('Should send a new request to change ownership of a video', async function () { 163 it('Should send a new request to change ownership of a video', async function () {
164 this.timeout(15000) 164 this.timeout(15000)
165 165
166 await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) 166 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
167 }) 167 })
168 168
169 it('Should return two requests to change ownership for the second user', async function () { 169 it('Should return two requests to change ownership for the second user', async function () {
@@ -207,7 +207,7 @@ describe('Test video change ownership - nominal', function () {
207 207
208 it('Should have the channel of the video updated', async function () { 208 it('Should have the channel of the video updated', async function () {
209 for (const server of servers) { 209 for (const server of servers) {
210 const video = await server.videos.get({ id: servers[0].store.video.uuid }) 210 const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid })
211 211
212 expect(video.name).to.equal('my super name') 212 expect(video.name).to.equal('my super name')
213 expect(video.channel.displayName).to.equal('Main second channel') 213 expect(video.channel.displayName).to.equal('Main second channel')
@@ -236,7 +236,7 @@ describe('Test video change ownership - nominal', function () {
236 await waitJobs(servers) 236 await waitJobs(servers)
237 237
238 for (const server of servers) { 238 for (const server of servers) {
239 const video = await server.videos.get({ id: servers[0].store.video.uuid }) 239 const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid })
240 240
241 expect(video.name).to.equal('my super name') 241 expect(video.name).to.equal('my super name')
242 expect(video.channel.displayName).to.equal('Main second channel') 242 expect(video.channel.displayName).to.equal('Main second channel')
@@ -282,13 +282,13 @@ describe('Test video change ownership - quota too small', function () {
282 const { data } = await server.videos.list() 282 const { data } = await server.videos.list()
283 expect(data.length).to.equal(1) 283 expect(data.length).to.equal(1)
284 284
285 server.store.video = data.find(video => video.name === 'my super name') 285 server.store.videoCreated = data.find(video => video.name === 'my super name')
286 }) 286 })
287 287
288 it('Should send a request to change ownership of a video', async function () { 288 it('Should send a request to change ownership of a video', async function () {
289 this.timeout(15000) 289 this.timeout(15000)
290 290
291 await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.video.id, username: secondUser }) 291 await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.videoCreated.id, username: secondUser })
292 }) 292 })
293 293
294 it('Should only return a request to change ownership for the second user', async function () { 294 it('Should only return a request to change ownership for the second user', async function () {
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
index 7845f7334..921d7ce64 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -19,6 +19,8 @@ import {
19} from '@shared/extra-utils' 19} from '@shared/extra-utils'
20import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' 20import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
21import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' 21import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
22import { uuidRegex } from '@shared/core-utils'
23import { basename } from 'path/posix'
22 24
23const expect = chai.expect 25const expect = chai.expect
24 26
@@ -38,14 +40,17 @@ async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, h
38 if (hlsOnly) expect(videoDetails.files).to.have.lengthOf(0) 40 if (hlsOnly) expect(videoDetails.files).to.have.lengthOf(0)
39 else expect(videoDetails.files).to.have.lengthOf(resolutions.length) 41 else expect(videoDetails.files).to.have.lengthOf(resolutions.length)
40 42
43 // Check JSON files
41 for (const resolution of resolutions) { 44 for (const resolution of resolutions) {
42 const file = hlsFiles.find(f => f.resolution.id === resolution) 45 const file = hlsFiles.find(f => f.resolution.id === resolution)
43 expect(file).to.not.be.undefined 46 expect(file).to.not.be.undefined
44 47
45 expect(file.magnetUri).to.have.lengthOf.above(2) 48 expect(file.magnetUri).to.have.lengthOf.above(2)
46 expect(file.torrentUrl).to.equal(`http://${server.host}/lazy-static/torrents/${videoDetails.uuid}-${file.resolution.id}-hls.torrent`) 49 expect(file.torrentUrl).to.match(
47 expect(file.fileUrl).to.equal( 50 new RegExp(`http://${server.host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}-hls.torrent`)
48 `${baseUrl}/static/streaming-playlists/hls/${videoDetails.uuid}/${videoDetails.uuid}-${file.resolution.id}-fragmented.mp4` 51 )
52 expect(file.fileUrl).to.match(
53 new RegExp(`${baseUrl}/static/streaming-playlists/hls/${videoDetails.uuid}/${uuidRegex}-${file.resolution.id}-fragmented.mp4`)
49 ) 54 )
50 expect(file.resolution.label).to.equal(resolution + 'p') 55 expect(file.resolution.label).to.equal(resolution + 'p')
51 56
@@ -58,6 +63,7 @@ async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, h
58 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 63 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
59 } 64 }
60 65
66 // Check master playlist
61 { 67 {
62 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) 68 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
63 69
@@ -69,13 +75,16 @@ async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, h
69 } 75 }
70 } 76 }
71 77
78 // Check resolution playlists
72 { 79 {
73 for (const resolution of resolutions) { 80 for (const resolution of resolutions) {
74 const subPlaylist = await server.streamingPlaylists.get({ 81 const subPlaylist = await server.streamingPlaylists.get({
75 url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` 82 url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`
76 }) 83 })
77 84
78 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) 85 const file = hlsFiles.find(f => f.resolution.id === resolution)
86 expect(subPlaylist).to.match(new RegExp(`${uuidRegex}-${resolution}-fragmented.mp4`))
87 expect(subPlaylist).to.contain(basename(file.fileUrl))
79 } 88 }
80 } 89 }
81 90
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index e4892bb24..2a09e95bf 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -3,7 +3,6 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { join } from 'path'
7import { 6import {
8 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
9 cleanupTests, 8 cleanupTests,
@@ -11,6 +10,7 @@ import {
11 doubleFollow, 10 doubleFollow,
12 generateHighBitrateVideo, 11 generateHighBitrateVideo,
13 generateVideoWithFramerate, 12 generateVideoWithFramerate,
13 getFileSize,
14 makeGetRequest, 14 makeGetRequest,
15 PeerTubeServer, 15 PeerTubeServer,
16 setAccessTokensToServers, 16 setAccessTokensToServers,
@@ -271,7 +271,8 @@ describe('Test video transcoding', function () {
271 271
272 expect(videoDetails.files).to.have.lengthOf(4) 272 expect(videoDetails.files).to.have.lengthOf(4)
273 273
274 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) 274 const file = videoDetails.files.find(f => f.resolution.id === 240)
275 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
275 const probe = await getAudioStream(path) 276 const probe = await getAudioStream(path)
276 277
277 if (probe.audioStream) { 278 if (probe.audioStream) {
@@ -300,8 +301,9 @@ describe('Test video transcoding', function () {
300 const video = data.find(v => v.name === attributes.name) 301 const video = data.find(v => v.name === attributes.name)
301 const videoDetails = await server.videos.get({ id: video.id }) 302 const videoDetails = await server.videos.get({ id: video.id })
302 303
303 expect(videoDetails.files).to.have.lengthOf(4) 304 const file = videoDetails.files.find(f => f.resolution.id === 240)
304 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) 305 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
306
305 const probe = await getAudioStream(path) 307 const probe = await getAudioStream(path)
306 expect(probe).to.not.have.property('audioStream') 308 expect(probe).to.not.have.property('audioStream')
307 } 309 }
@@ -328,7 +330,9 @@ describe('Test video transcoding', function () {
328 330
329 const fixturePath = buildAbsoluteFixturePath(attributes.fixture) 331 const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
330 const fixtureVideoProbe = await getAudioStream(fixturePath) 332 const fixtureVideoProbe = await getAudioStream(fixturePath)
331 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) 333
334 const file = videoDetails.files.find(f => f.resolution.id === 240)
335 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
332 336
333 const videoProbe = await getAudioStream(path) 337 const videoProbe = await getAudioStream(path)
334 338
@@ -485,14 +489,16 @@ describe('Test video transcoding', function () {
485 expect(videoDetails.files[2].fps).to.be.below(31) 489 expect(videoDetails.files[2].fps).to.be.below(31)
486 expect(videoDetails.files[3].fps).to.be.below(31) 490 expect(videoDetails.files[3].fps).to.be.below(31)
487 491
488 for (const resolution of [ '240', '360', '480' ]) { 492 for (const resolution of [ 240, 360, 480 ]) {
489 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) 493 const file = videoDetails.files.find(f => f.resolution.id === resolution)
494 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
490 const fps = await getVideoFileFPS(path) 495 const fps = await getVideoFileFPS(path)
491 496
492 expect(fps).to.be.below(31) 497 expect(fps).to.be.below(31)
493 } 498 }
494 499
495 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) 500 const file = videoDetails.files.find(f => f.resolution.id === 720)
501 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
496 const fps = await getVideoFileFPS(path) 502 const fps = await getVideoFileFPS(path)
497 503
498 expect(fps).to.be.above(58).and.below(62) 504 expect(fps).to.be.above(58).and.below(62)
@@ -524,16 +530,19 @@ describe('Test video transcoding', function () {
524 for (const server of servers) { 530 for (const server of servers) {
525 const { data } = await server.videos.list() 531 const { data } = await server.videos.list()
526 532
527 const video = data.find(v => v.name === attributes.name) 533 const { id } = data.find(v => v.name === attributes.name)
534 const video = await server.videos.get({ id })
528 535
529 { 536 {
530 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) 537 const file = video.files.find(f => f.resolution.id === 240)
538 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
531 const fps = await getVideoFileFPS(path) 539 const fps = await getVideoFileFPS(path)
532 expect(fps).to.be.equal(25) 540 expect(fps).to.be.equal(25)
533 } 541 }
534 542
535 { 543 {
536 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) 544 const file = video.files.find(f => f.resolution.id === 720)
545 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
537 const fps = await getVideoFileFPS(path) 546 const fps = await getVideoFileFPS(path)
538 expect(fps).to.be.equal(59) 547 expect(fps).to.be.equal(59)
539 } 548 }
@@ -542,6 +551,7 @@ describe('Test video transcoding', function () {
542 }) 551 })
543 552
544 describe('Bitrate control', function () { 553 describe('Bitrate control', function () {
554
545 it('Should respect maximum bitrate values', async function () { 555 it('Should respect maximum bitrate values', async function () {
546 this.timeout(160_000) 556 this.timeout(160_000)
547 557
@@ -567,17 +577,19 @@ describe('Test video transcoding', function () {
567 for (const server of servers) { 577 for (const server of servers) {
568 const { data } = await server.videos.list() 578 const { data } = await server.videos.list()
569 579
570 const video = data.find(v => v.name === attributes.name) 580 const { id } = data.find(v => v.name === attributes.name)
581 const video = await server.videos.get({ id })
571 582
572 for (const resolution of [ '240', '360', '480', '720', '1080' ]) { 583 for (const resolution of [ 240, 360, 480, 720, 1080 ]) {
573 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) 584 const file = video.files.find(f => f.resolution.id === resolution)
585 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
574 586
575 const bitrate = await getVideoFileBitrate(path) 587 const bitrate = await getVideoFileBitrate(path)
576 const fps = await getVideoFileFPS(path) 588 const fps = await getVideoFileFPS(path)
577 const resolution2 = await getVideoFileResolution(path) 589 const { videoFileResolution } = await getVideoFileResolution(path)
578 590
579 expect(resolution2.videoFileResolution.toString()).to.equal(resolution) 591 expect(videoFileResolution).to.equal(resolution)
580 expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) 592 expect(bitrate).to.be.below(getMaxBitrate(videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
581 } 593 }
582 } 594 }
583 }) 595 })
@@ -608,14 +620,18 @@ describe('Test video transcoding', function () {
608 fixture: 'low-bitrate.mp4' 620 fixture: 'low-bitrate.mp4'
609 } 621 }
610 622
611 const { uuid } = await servers[1].videos.upload({ attributes }) 623 const { id } = await servers[1].videos.upload({ attributes })
612 624
613 await waitJobs(servers) 625 await waitJobs(servers)
614 626
627 const video = await servers[1].videos.get({ id })
628
615 const resolutions = [ 240, 360, 480, 720, 1080 ] 629 const resolutions = [ 240, 360, 480, 720, 1080 ]
616 for (const r of resolutions) { 630 for (const r of resolutions) {
617 const path = `videos/${uuid}-${r}.mp4` 631 const file = video.files.find(f => f.resolution.id === r)
618 const size = await servers[1].servers.getServerFileSize(path) 632
633 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
634 const size = await getFileSize(path)
619 expect(size, `${path} not below ${60_000}`).to.be.below(60_000) 635 expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
620 } 636 }
621 }) 637 })
@@ -630,7 +646,9 @@ describe('Test video transcoding', function () {
630 await waitJobs(servers) 646 await waitJobs(servers)
631 647
632 { 648 {
633 const path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) 649 const video = await servers[1].videos.get({ id: videoUUID })
650 const file = video.files.find(f => f.resolution.id === 240)
651 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
634 const metadata = await getMetadataFromFile(path) 652 const metadata = await getMetadataFromFile(path)
635 653
636 // expected format properties 654 // expected format properties