]>
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' | |
65e6e260 | 6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
09209296 C |
7 | import { |
8 | checkDirectoryIsEmpty, | |
bd54ad19 | 9 | checkResolutionsInMasterPlaylist, |
4c280004 | 10 | checkSegmentHash, |
7243f84d C |
11 | checkTmpIsEmpty, |
12 | cleanupTests, | |
09209296 C |
13 | doubleFollow, |
14 | flushAndRunMultipleServers, | |
a1587156 C |
15 | getVideo, |
16 | makeRawRequest, | |
09209296 C |
17 | removeVideo, |
18 | ServerInfo, | |
a1587156 | 19 | setAccessTokensToServers, |
09209296 C |
20 | updateVideo, |
21 | uploadVideo, | |
a1587156 C |
22 | waitJobs, |
23 | webtorrentAdd | |
94565d52 | 24 | } from '../../../../shared/extra-utils' |
09209296 C |
25 | import { VideoDetails } from '../../../../shared/models/videos' |
26 | import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' | |
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) | |
90a8bd30 | 53 | expect(file.torrentUrl).to.equal(`http://${server.host}/lazy-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 | ||
f2eb23cd RK |
59 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
60 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
d7a25329 C |
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 | { |
57f879a5 | 69 | await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) |
09209296 | 70 | |
57f879a5 | 71 | const masterPlaylist = await server.streamingPlaylistsCommand.get({ url: hlsPlaylist.playlistUrl }) |
09209296 | 72 | |
09209296 | 73 | for (const resolution of resolutions) { |
52201311 | 74 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
09209296 C |
75 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
76 | } | |
77 | } | |
78 | ||
79 | { | |
80 | for (const resolution of resolutions) { | |
57f879a5 C |
81 | const subPlaylist = await server.streamingPlaylistsCommand.get({ |
82 | url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` | |
83 | }) | |
09209296 | 84 | |
4c280004 | 85 | expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) |
09209296 C |
86 | } |
87 | } | |
88 | ||
89 | { | |
d7a25329 | 90 | const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' |
09209296 | 91 | |
4c280004 | 92 | for (const resolution of resolutions) { |
57f879a5 C |
93 | await checkSegmentHash({ |
94 | server, | |
95 | baseUrlPlaylist: baseUrlAndPath, | |
96 | baseUrlSegment: baseUrlAndPath, | |
97 | videoUUID, | |
98 | resolution, | |
99 | hlsPlaylist | |
100 | }) | |
09209296 C |
101 | } |
102 | } | |
103 | } | |
104 | } | |
105 | ||
106 | describe('Test HLS videos', function () { | |
107 | let servers: ServerInfo[] = [] | |
108 | let videoUUID = '' | |
b345a804 | 109 | let videoAudioUUID = '' |
09209296 | 110 | |
d7a25329 | 111 | function runTestSuite (hlsOnly: boolean) { |
dd0ebb71 | 112 | |
d7a25329 C |
113 | it('Should upload a video and transcode it to HLS', async function () { |
114 | this.timeout(120000) | |
09209296 | 115 | |
a1587156 | 116 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) |
d7a25329 | 117 | videoUUID = res.body.video.uuid |
09209296 | 118 | |
d7a25329 | 119 | await waitJobs(servers) |
09209296 | 120 | |
d7a25329 C |
121 | await checkHlsPlaylist(servers, videoUUID, hlsOnly) |
122 | }) | |
09209296 | 123 | |
d7a25329 C |
124 | it('Should upload an audio file and transcode it to HLS', async function () { |
125 | this.timeout(120000) | |
09209296 | 126 | |
a1587156 | 127 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) |
d7a25329 | 128 | videoAudioUUID = res.body.video.uuid |
09209296 | 129 | |
d7a25329 | 130 | await waitJobs(servers) |
09209296 | 131 | |
657bba2b | 132 | await checkHlsPlaylist(servers, videoAudioUUID, hlsOnly, [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ]) |
d7a25329 | 133 | }) |
09209296 | 134 | |
d7a25329 C |
135 | it('Should update the video', async function () { |
136 | this.timeout(10000) | |
b345a804 | 137 | |
a1587156 | 138 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) |
b345a804 | 139 | |
d7a25329 | 140 | await waitJobs(servers) |
b345a804 | 141 | |
d7a25329 C |
142 | await checkHlsPlaylist(servers, videoUUID, hlsOnly) |
143 | }) | |
b345a804 | 144 | |
d7a25329 C |
145 | it('Should delete videos', async function () { |
146 | this.timeout(10000) | |
80b8ad2a | 147 | |
a1587156 C |
148 | await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) |
149 | await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) | |
09209296 | 150 | |
d7a25329 | 151 | await waitJobs(servers) |
09209296 | 152 | |
d7a25329 | 153 | for (const server of servers) { |
f2eb23cd RK |
154 | await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) |
155 | await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) | |
d7a25329 C |
156 | } |
157 | }) | |
09209296 | 158 | |
d7a25329 C |
159 | it('Should have the playlists/segment deleted from the disk', async function () { |
160 | for (const server of servers) { | |
161 | await checkDirectoryIsEmpty(server, 'videos') | |
162 | await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls')) | |
163 | } | |
164 | }) | |
80b8ad2a | 165 | |
d7a25329 C |
166 | it('Should have an empty tmp directory', async function () { |
167 | for (const server of servers) { | |
168 | await checkTmpIsEmpty(server) | |
169 | } | |
170 | }) | |
171 | } | |
09209296 | 172 | |
d7a25329 C |
173 | before(async function () { |
174 | this.timeout(120000) | |
09209296 | 175 | |
d7a25329 C |
176 | const configOverride = { |
177 | transcoding: { | |
178 | enabled: true, | |
179 | allow_audio_files: true, | |
180 | hls: { | |
181 | enabled: true | |
182 | } | |
183 | } | |
09209296 | 184 | } |
d7a25329 C |
185 | servers = await flushAndRunMultipleServers(2, configOverride) |
186 | ||
187 | // Get the access tokens | |
188 | await setAccessTokensToServers(servers) | |
189 | ||
190 | // Server 1 and server 2 follow each other | |
191 | await doubleFollow(servers[0], servers[1]) | |
09209296 C |
192 | }) |
193 | ||
d7a25329 C |
194 | describe('With WebTorrent & HLS enabled', function () { |
195 | runTestSuite(false) | |
09209296 C |
196 | }) |
197 | ||
d7a25329 C |
198 | describe('With only HLS enabled', function () { |
199 | ||
200 | before(async function () { | |
65e6e260 C |
201 | await servers[0].configCommand.updateCustomSubConfig({ |
202 | newConfig: { | |
203 | transcoding: { | |
204 | enabled: true, | |
205 | allowAudioFiles: true, | |
206 | resolutions: { | |
207 | '240p': true, | |
208 | '360p': true, | |
209 | '480p': true, | |
210 | '720p': true, | |
211 | '1080p': true, | |
212 | '1440p': true, | |
213 | '2160p': true | |
214 | }, | |
215 | hls: { | |
216 | enabled: true | |
217 | }, | |
218 | webtorrent: { | |
219 | enabled: false | |
220 | } | |
d7a25329 C |
221 | } |
222 | } | |
223 | }) | |
224 | }) | |
225 | ||
226 | runTestSuite(true) | |
09209296 C |
227 | }) |
228 | ||
7c3b7976 C |
229 | after(async function () { |
230 | await cleanupTests(servers) | |
09209296 C |
231 | }) |
232 | }) |