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