1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
11 flushAndRunMultipleServers,
16 setAccessTokensToServers,
20 } from '../../../../shared/extra-utils'
21 import { VideoDetails } from '../../../../shared/models/videos'
22 import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
23 import { join } from 'path'
24 import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
26 const expect = chai.expect
28 async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, resolutions = [ 240, 360, 480, 720 ]) {
29 for (const server of servers) {
30 const res = await getVideo(server.url, videoUUID)
31 const videoDetails: VideoDetails = res.body
33 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
35 const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
36 expect(hlsPlaylist).to.not.be.undefined
39 const res2 = await getPlaylist(hlsPlaylist.playlistUrl)
41 const masterPlaylist = res2.text
43 for (const resolution of resolutions) {
44 expect(masterPlaylist).to.match(new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',FRAME-RATE=\\d+'))
45 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
50 for (const resolution of resolutions) {
51 const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
53 const subPlaylist = res2.text
54 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
59 const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls'
61 for (const resolution of resolutions) {
62 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
68 describe('Test HLS videos', function () {
69 let servers: ServerInfo[] = []
71 let videoAudioUUID = ''
73 before(async function () {
76 const configOverride = {
79 allow_audio_files: true,
85 servers = await flushAndRunMultipleServers(2, configOverride)
87 // Get the access tokens
88 await setAccessTokensToServers(servers)
90 // Server 1 and server 2 follow each other
91 await doubleFollow(servers[0], servers[1])
94 it('Should upload a video and transcode it to HLS', async function () {
97 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
98 videoUUID = res.body.video.uuid
100 await waitJobs(servers)
102 await checkHlsPlaylist(servers, videoUUID)
105 it('Should upload an audio file and transcode it to HLS', async function () {
108 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video audio', fixture: 'sample.ogg' })
109 videoAudioUUID = res.body.video.uuid
111 await waitJobs(servers)
113 await checkHlsPlaylist(servers, videoAudioUUID, [ DEFAULT_AUDIO_RESOLUTION ])
116 it('Should update the video', async function () {
119 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
121 await waitJobs(servers)
123 await checkHlsPlaylist(servers, videoUUID)
126 it('Should delete videos', async function () {
129 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
130 await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID)
132 await waitJobs(servers)
134 for (const server of servers) {
135 await getVideo(server.url, videoUUID, 404)
136 await getVideo(server.url, videoAudioUUID, 404)
140 it('Should have the playlists/segment deleted from the disk', async function () {
141 for (const server of servers) {
142 await checkDirectoryIsEmpty(server, 'videos')
143 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
147 it('Should have an empty tmp directory', async function () {
148 for (const server of servers) {
149 await checkTmpIsEmpty(server)
153 after(async function () {
154 await cleanupTests(servers)