]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-hls.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-hls.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 checkDirectoryIsEmpty,
7 checkSegmentHash,
8 checkTmpIsEmpty,
9 cleanupTests,
10 doubleFollow,
11 flushAndRunMultipleServers,
12 getPlaylist,
13 getVideo,
14 removeVideo,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateVideo,
18 uploadVideo,
19 waitJobs
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
25 const expect = chai.expect
26
27 async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) {
28 const resolutions = [ 240, 360, 480, 720 ]
29
30 for (const server of servers) {
31 const res = await getVideo(server.url, videoUUID)
32 const videoDetails: VideoDetails = res.body
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
39 {
40 const res2 = await getPlaylist(hlsPlaylist.playlistUrl)
41
42 const masterPlaylist = res2.text
43
44 expect(masterPlaylist).to.contain('#EXT-X-STREAM-INF:BANDWIDTH=55472,RESOLUTION=640x360,FRAME-RATE=25')
45
46 for (const resolution of resolutions) {
47 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
48 }
49 }
50
51 {
52 for (const resolution of resolutions) {
53 const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
54
55 const subPlaylist = res2.text
56 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
57 }
58 }
59
60 {
61 const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls'
62
63 for (const resolution of resolutions) {
64 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
65 }
66 }
67 }
68 }
69
70 describe('Test HLS videos', function () {
71 let servers: ServerInfo[] = []
72 let videoUUID = ''
73
74 before(async function () {
75 this.timeout(120000)
76
77 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true, hls: { enabled: true } } })
78
79 // Get the access tokens
80 await setAccessTokensToServers(servers)
81
82 // Server 1 and server 2 follow each other
83 await doubleFollow(servers[0], servers[1])
84 })
85
86 it('Should upload a video and transcode it to HLS', async function () {
87 this.timeout(120000)
88
89 {
90 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
91 videoUUID = res.body.video.uuid
92 }
93
94 await waitJobs(servers)
95
96 await checkHlsPlaylist(servers, videoUUID)
97 })
98
99 it('Should update the video', async function () {
100 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
101
102 await waitJobs(servers)
103
104 await checkHlsPlaylist(servers, videoUUID)
105 })
106
107 it('Should delete the video', async function () {
108 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
109
110 await waitJobs(servers)
111
112 for (const server of servers) {
113 await getVideo(server.url, videoUUID, 404)
114 }
115 })
116
117 it('Should have the playlists/segment deleted from the disk', async function () {
118 for (const server of servers) {
119 await checkDirectoryIsEmpty(server, 'videos')
120 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
121 }
122 })
123
124 it('Should have an empty tmp directory', async function () {
125 for (const server of servers) {
126 await checkTmpIsEmpty(server)
127 }
128 })
129
130 after(async function () {
131 await cleanupTests(servers)
132 })
133 })