]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
09209296 | 2 | |
09209296 | 3 | import 'mocha' |
bd54ad19 C |
4 | import * as chai from 'chai' |
5 | import { join } from 'path' | |
09209296 C |
6 | import { |
7 | checkDirectoryIsEmpty, | |
bd54ad19 | 8 | checkResolutionsInMasterPlaylist, |
4c280004 | 9 | checkSegmentHash, |
7243f84d C |
10 | checkTmpIsEmpty, |
11 | cleanupTests, | |
09209296 C |
12 | doubleFollow, |
13 | flushAndRunMultipleServers, | |
09209296 | 14 | getPlaylist, |
a1587156 C |
15 | getVideo, |
16 | makeRawRequest, | |
09209296 C |
17 | removeVideo, |
18 | ServerInfo, | |
a1587156 C |
19 | setAccessTokensToServers, |
20 | updateCustomSubConfig, | |
09209296 C |
21 | updateVideo, |
22 | uploadVideo, | |
a1587156 C |
23 | waitJobs, |
24 | webtorrentAdd | |
94565d52 | 25 | } from '../../../../shared/extra-utils' |
09209296 C |
26 | import { VideoDetails } from '../../../../shared/models/videos' |
27 | import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' | |
b345a804 | 28 | import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' |
f2eb23cd | 29 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
09209296 C |
30 | |
31 | const expect = chai.expect | |
32 | ||
d7a25329 | 33 | async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { |
09209296 | 34 | for (const server of servers) { |
d7a25329 C |
35 | const resVideoDetails = await getVideo(server.url, videoUUID) |
36 | const videoDetails: VideoDetails = resVideoDetails.body | |
37 | const baseUrl = `http://${videoDetails.account.host}` | |
09209296 C |
38 | |
39 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | |
40 | ||
41 | const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
42 | expect(hlsPlaylist).to.not.be.undefined | |
43 | ||
d7a25329 C |
44 | const hlsFiles = hlsPlaylist.files |
45 | expect(hlsFiles).to.have.lengthOf(resolutions.length) | |
46 | ||
47 | if (hlsOnly) expect(videoDetails.files).to.have.lengthOf(0) | |
48 | else expect(videoDetails.files).to.have.lengthOf(resolutions.length) | |
49 | ||
50 | for (const resolution of resolutions) { | |
51 | const file = hlsFiles.find(f => f.resolution.id === resolution) | |
52 | expect(file).to.not.be.undefined | |
53 | ||
54 | expect(file.magnetUri).to.have.lengthOf.above(2) | |
90a8bd30 | 55 | expect(file.torrentUrl).to.equal(`http://${server.host}/lazy-static/torrents/${videoDetails.uuid}-${file.resolution.id}-hls.torrent`) |
a1587156 C |
56 | expect(file.fileUrl).to.equal( |
57 | `${baseUrl}/static/streaming-playlists/hls/${videoDetails.uuid}/${videoDetails.uuid}-${file.resolution.id}-fragmented.mp4` | |
58 | ) | |
d7a25329 C |
59 | expect(file.resolution.label).to.equal(resolution + 'p') |
60 | ||
f2eb23cd RK |
61 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
62 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
d7a25329 C |
63 | |
64 | const torrent = await webtorrentAdd(file.magnetUri, true) | |
65 | expect(torrent.files).to.be.an('array') | |
66 | expect(torrent.files.length).to.equal(1) | |
67 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
68 | } | |
69 | ||
09209296 | 70 | { |
bd54ad19 | 71 | await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) |
09209296 | 72 | |
bd54ad19 | 73 | const res = await getPlaylist(hlsPlaylist.playlistUrl) |
d7a25329 | 74 | const masterPlaylist = res.text |
09209296 | 75 | |
09209296 | 76 | for (const resolution of resolutions) { |
52201311 | 77 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
09209296 C |
78 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
79 | } | |
80 | } | |
81 | ||
82 | { | |
83 | for (const resolution of resolutions) { | |
d7a25329 | 84 | const res = await getPlaylist(`${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) |
09209296 | 85 | |
d7a25329 | 86 | const subPlaylist = res.text |
4c280004 | 87 | expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) |
09209296 C |
88 | } |
89 | } | |
90 | ||
91 | { | |
d7a25329 | 92 | const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' |
09209296 | 93 | |
4c280004 | 94 | for (const resolution of resolutions) { |
d7a25329 | 95 | await checkSegmentHash(baseUrlAndPath, baseUrlAndPath, videoUUID, resolution, hlsPlaylist) |
09209296 C |
96 | } |
97 | } | |
98 | } | |
99 | } | |
100 | ||
101 | describe('Test HLS videos', function () { | |
102 | let servers: ServerInfo[] = [] | |
103 | let videoUUID = '' | |
b345a804 | 104 | let videoAudioUUID = '' |
09209296 | 105 | |
d7a25329 C |
106 | function runTestSuite (hlsOnly: boolean) { |
107 | it('Should upload a video and transcode it to HLS', async function () { | |
108 | this.timeout(120000) | |
09209296 | 109 | |
a1587156 | 110 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) |
d7a25329 | 111 | videoUUID = res.body.video.uuid |
09209296 | 112 | |
d7a25329 | 113 | await waitJobs(servers) |
09209296 | 114 | |
d7a25329 C |
115 | await checkHlsPlaylist(servers, videoUUID, hlsOnly) |
116 | }) | |
09209296 | 117 | |
d7a25329 C |
118 | it('Should upload an audio file and transcode it to HLS', async function () { |
119 | this.timeout(120000) | |
09209296 | 120 | |
a1587156 | 121 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) |
d7a25329 | 122 | videoAudioUUID = res.body.video.uuid |
09209296 | 123 | |
d7a25329 | 124 | await waitJobs(servers) |
09209296 | 125 | |
657bba2b | 126 | await checkHlsPlaylist(servers, videoAudioUUID, hlsOnly, [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ]) |
d7a25329 | 127 | }) |
09209296 | 128 | |
d7a25329 C |
129 | it('Should update the video', async function () { |
130 | this.timeout(10000) | |
b345a804 | 131 | |
a1587156 | 132 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) |
b345a804 | 133 | |
d7a25329 | 134 | await waitJobs(servers) |
b345a804 | 135 | |
d7a25329 C |
136 | await checkHlsPlaylist(servers, videoUUID, hlsOnly) |
137 | }) | |
b345a804 | 138 | |
d7a25329 C |
139 | it('Should delete videos', async function () { |
140 | this.timeout(10000) | |
80b8ad2a | 141 | |
a1587156 C |
142 | await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) |
143 | await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) | |
09209296 | 144 | |
d7a25329 | 145 | await waitJobs(servers) |
09209296 | 146 | |
d7a25329 | 147 | for (const server of servers) { |
f2eb23cd RK |
148 | await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) |
149 | await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) | |
d7a25329 C |
150 | } |
151 | }) | |
09209296 | 152 | |
d7a25329 C |
153 | it('Should have the playlists/segment deleted from the disk', async function () { |
154 | for (const server of servers) { | |
155 | await checkDirectoryIsEmpty(server, 'videos') | |
156 | await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls')) | |
157 | } | |
158 | }) | |
80b8ad2a | 159 | |
d7a25329 C |
160 | it('Should have an empty tmp directory', async function () { |
161 | for (const server of servers) { | |
162 | await checkTmpIsEmpty(server) | |
163 | } | |
164 | }) | |
165 | } | |
09209296 | 166 | |
d7a25329 C |
167 | before(async function () { |
168 | this.timeout(120000) | |
09209296 | 169 | |
d7a25329 C |
170 | const configOverride = { |
171 | transcoding: { | |
172 | enabled: true, | |
173 | allow_audio_files: true, | |
174 | hls: { | |
175 | enabled: true | |
176 | } | |
177 | } | |
09209296 | 178 | } |
d7a25329 C |
179 | servers = await flushAndRunMultipleServers(2, configOverride) |
180 | ||
181 | // Get the access tokens | |
182 | await setAccessTokensToServers(servers) | |
183 | ||
184 | // Server 1 and server 2 follow each other | |
185 | await doubleFollow(servers[0], servers[1]) | |
09209296 C |
186 | }) |
187 | ||
d7a25329 C |
188 | describe('With WebTorrent & HLS enabled', function () { |
189 | runTestSuite(false) | |
09209296 C |
190 | }) |
191 | ||
d7a25329 C |
192 | describe('With only HLS enabled', function () { |
193 | ||
194 | before(async function () { | |
195 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
196 | transcoding: { | |
197 | enabled: true, | |
198 | allowAudioFiles: true, | |
199 | resolutions: { | |
200 | '240p': true, | |
201 | '360p': true, | |
202 | '480p': true, | |
203 | '720p': true, | |
204 | '1080p': true, | |
b7085c71 | 205 | '1440p': true, |
d7a25329 C |
206 | '2160p': true |
207 | }, | |
208 | hls: { | |
209 | enabled: true | |
210 | }, | |
211 | webtorrent: { | |
212 | enabled: false | |
213 | } | |
214 | } | |
215 | }) | |
216 | }) | |
217 | ||
218 | runTestSuite(true) | |
09209296 C |
219 | }) |
220 | ||
7c3b7976 C |
221 | after(async function () { |
222 | await cleanupTests(servers) | |
09209296 C |
223 | }) |
224 | }) |