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