]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
09209296
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 checkDirectoryIsEmpty,
4c280004 7 checkSegmentHash,
7243f84d
C
8 checkTmpIsEmpty,
9 cleanupTests,
09209296
C
10 doubleFollow,
11 flushAndRunMultipleServers,
09209296 12 getPlaylist,
09209296 13 getVideo,
09209296
C
14 removeVideo,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateVideo,
18 uploadVideo,
19 waitJobs
94565d52 20} from '../../../../shared/extra-utils'
09209296
C
21import { VideoDetails } from '../../../../shared/models/videos'
22import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
09209296
C
23import { join } from 'path'
24
25const expect = chai.expect
26
27async 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) {
48f07b4a 53 const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
09209296
C
54
55 const subPlaylist = res2.text
4c280004 56 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
09209296
C
57 }
58 }
59
60 {
48f07b4a 61 const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls'
09209296 62
4c280004
C
63 for (const resolution of resolutions) {
64 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
09209296
C
65 }
66 }
67 }
68}
69
70describe('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')
0b16f5f2 120 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
09209296
C
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
7c3b7976
C
130 after(async function () {
131 await cleanupTests(servers)
09209296
C
132 })
133})