aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-hls.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-hls.ts')
-rw-r--r--server/tests/api/videos/video-hls.ts101
1 files changed, 51 insertions, 50 deletions
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
index 03ac3f321..7845f7334 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -9,31 +9,22 @@ import {
9 checkSegmentHash, 9 checkSegmentHash,
10 checkTmpIsEmpty, 10 checkTmpIsEmpty,
11 cleanupTests, 11 cleanupTests,
12 createMultipleServers,
12 doubleFollow, 13 doubleFollow,
13 flushAndRunMultipleServers,
14 getPlaylist,
15 getVideo,
16 makeRawRequest, 14 makeRawRequest,
17 removeVideo, 15 PeerTubeServer,
18 ServerInfo,
19 setAccessTokensToServers, 16 setAccessTokensToServers,
20 updateCustomSubConfig,
21 updateVideo,
22 uploadVideo,
23 waitJobs, 17 waitJobs,
24 webtorrentAdd 18 webtorrentAdd
25} from '../../../../shared/extra-utils' 19} from '@shared/extra-utils'
26import { VideoDetails } from '../../../../shared/models/videos' 20import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
27import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
28import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' 21import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
29import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 22
31const expect = chai.expect 23const expect = chai.expect
32 24
33async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { 25async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) {
34 for (const server of servers) { 26 for (const server of servers) {
35 const resVideoDetails = await getVideo(server.url, videoUUID) 27 const videoDetails = await server.videos.get({ id: videoUUID })
36 const videoDetails: VideoDetails = resVideoDetails.body
37 const baseUrl = `http://${videoDetails.account.host}` 28 const baseUrl = `http://${videoDetails.account.host}`
38 29
39 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) 30 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
@@ -68,10 +59,9 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn
68 } 59 }
69 60
70 { 61 {
71 await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) 62 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
72 63
73 const res = await getPlaylist(hlsPlaylist.playlistUrl) 64 const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl })
74 const masterPlaylist = res.text
75 65
76 for (const resolution of resolutions) { 66 for (const resolution of resolutions) {
77 expect(masterPlaylist).to.contain(`${resolution}.m3u8`) 67 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
@@ -81,9 +71,10 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn
81 71
82 { 72 {
83 for (const resolution of resolutions) { 73 for (const resolution of resolutions) {
84 const res = await getPlaylist(`${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) 74 const subPlaylist = await server.streamingPlaylists.get({
75 url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`
76 })
85 77
86 const subPlaylist = res.text
87 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) 78 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
88 } 79 }
89 } 80 }
@@ -92,23 +83,31 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn
92 const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' 83 const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls'
93 84
94 for (const resolution of resolutions) { 85 for (const resolution of resolutions) {
95 await checkSegmentHash(baseUrlAndPath, baseUrlAndPath, videoUUID, resolution, hlsPlaylist) 86 await checkSegmentHash({
87 server,
88 baseUrlPlaylist: baseUrlAndPath,
89 baseUrlSegment: baseUrlAndPath,
90 videoUUID,
91 resolution,
92 hlsPlaylist
93 })
96 } 94 }
97 } 95 }
98 } 96 }
99} 97}
100 98
101describe('Test HLS videos', function () { 99describe('Test HLS videos', function () {
102 let servers: ServerInfo[] = [] 100 let servers: PeerTubeServer[] = []
103 let videoUUID = '' 101 let videoUUID = ''
104 let videoAudioUUID = '' 102 let videoAudioUUID = ''
105 103
106 function runTestSuite (hlsOnly: boolean) { 104 function runTestSuite (hlsOnly: boolean) {
105
107 it('Should upload a video and transcode it to HLS', async function () { 106 it('Should upload a video and transcode it to HLS', async function () {
108 this.timeout(120000) 107 this.timeout(120000)
109 108
110 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) 109 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
111 videoUUID = res.body.video.uuid 110 videoUUID = uuid
112 111
113 await waitJobs(servers) 112 await waitJobs(servers)
114 113
@@ -118,8 +117,8 @@ describe('Test HLS videos', function () {
118 it('Should upload an audio file and transcode it to HLS', async function () { 117 it('Should upload an audio file and transcode it to HLS', async function () {
119 this.timeout(120000) 118 this.timeout(120000)
120 119
121 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) 120 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
122 videoAudioUUID = res.body.video.uuid 121 videoAudioUUID = uuid
123 122
124 await waitJobs(servers) 123 await waitJobs(servers)
125 124
@@ -129,7 +128,7 @@ describe('Test HLS videos', function () {
129 it('Should update the video', async function () { 128 it('Should update the video', async function () {
130 this.timeout(10000) 129 this.timeout(10000)
131 130
132 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) 131 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video 1 updated' } })
133 132
134 await waitJobs(servers) 133 await waitJobs(servers)
135 134
@@ -139,14 +138,14 @@ describe('Test HLS videos', function () {
139 it('Should delete videos', async function () { 138 it('Should delete videos', async function () {
140 this.timeout(10000) 139 this.timeout(10000)
141 140
142 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 141 await servers[0].videos.remove({ id: videoUUID })
143 await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) 142 await servers[0].videos.remove({ id: videoAudioUUID })
144 143
145 await waitJobs(servers) 144 await waitJobs(servers)
146 145
147 for (const server of servers) { 146 for (const server of servers) {
148 await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) 147 await server.videos.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
149 await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) 148 await server.videos.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
150 } 149 }
151 }) 150 })
152 151
@@ -176,7 +175,7 @@ describe('Test HLS videos', function () {
176 } 175 }
177 } 176 }
178 } 177 }
179 servers = await flushAndRunMultipleServers(2, configOverride) 178 servers = await createMultipleServers(2, configOverride)
180 179
181 // Get the access tokens 180 // Get the access tokens
182 await setAccessTokensToServers(servers) 181 await setAccessTokensToServers(servers)
@@ -192,24 +191,26 @@ describe('Test HLS videos', function () {
192 describe('With only HLS enabled', function () { 191 describe('With only HLS enabled', function () {
193 192
194 before(async function () { 193 before(async function () {
195 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 194 await servers[0].config.updateCustomSubConfig({
196 transcoding: { 195 newConfig: {
197 enabled: true, 196 transcoding: {
198 allowAudioFiles: true, 197 enabled: true,
199 resolutions: { 198 allowAudioFiles: true,
200 '240p': true, 199 resolutions: {
201 '360p': true, 200 '240p': true,
202 '480p': true, 201 '360p': true,
203 '720p': true, 202 '480p': true,
204 '1080p': true, 203 '720p': true,
205 '1440p': true, 204 '1080p': true,
206 '2160p': true 205 '1440p': true,
207 }, 206 '2160p': true
208 hls: { 207 },
209 enabled: true 208 hls: {
210 }, 209 enabled: true
211 webtorrent: { 210 },
212 enabled: false 211 webtorrent: {
212 enabled: false
213 }
213 } 214 }
214 } 215 }
215 }) 216 })