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