]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-hls.ts
Remove comment federation by video owner
[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 23import { join } from 'path'
b345a804 24import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
09209296
C
25
26const expect = chai.expect
27
b345a804 28async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, resolutions = [ 240, 360, 480, 720 ]) {
09209296
C
29 for (const server of servers) {
30 const res = await getVideo(server.url, videoUUID)
31 const videoDetails: VideoDetails = res.body
32
33 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
34
35 const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
36 expect(hlsPlaylist).to.not.be.undefined
37
38 {
39 const res2 = await getPlaylist(hlsPlaylist.playlistUrl)
40
41 const masterPlaylist = res2.text
42
09209296 43 for (const resolution of resolutions) {
b345a804 44 expect(masterPlaylist).to.match(new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',FRAME-RATE=\\d+'))
09209296
C
45 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
46 }
47 }
48
49 {
50 for (const resolution of resolutions) {
48f07b4a 51 const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
09209296
C
52
53 const subPlaylist = res2.text
4c280004 54 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
09209296
C
55 }
56 }
57
58 {
48f07b4a 59 const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls'
09209296 60
4c280004
C
61 for (const resolution of resolutions) {
62 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
09209296
C
63 }
64 }
65 }
66}
67
68describe('Test HLS videos', function () {
69 let servers: ServerInfo[] = []
70 let videoUUID = ''
b345a804 71 let videoAudioUUID = ''
09209296
C
72
73 before(async function () {
74 this.timeout(120000)
75
b345a804
C
76 const configOverride = {
77 transcoding: {
78 enabled: true,
79 allow_audio_files: true,
80 hls: {
81 enabled: true
82 }
83 }
84 }
85 servers = await flushAndRunMultipleServers(2, configOverride)
09209296
C
86
87 // Get the access tokens
88 await setAccessTokensToServers(servers)
89
90 // Server 1 and server 2 follow each other
91 await doubleFollow(servers[0], servers[1])
92 })
93
94 it('Should upload a video and transcode it to HLS', async function () {
95 this.timeout(120000)
96
b345a804
C
97 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
98 videoUUID = res.body.video.uuid
09209296
C
99
100 await waitJobs(servers)
101
102 await checkHlsPlaylist(servers, videoUUID)
103 })
104
b345a804
C
105 it('Should upload an audio file and transcode it to HLS', async function () {
106 this.timeout(120000)
107
108 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video audio', fixture: 'sample.ogg' })
109 videoAudioUUID = res.body.video.uuid
110
111 await waitJobs(servers)
112
113 await checkHlsPlaylist(servers, videoAudioUUID, [ DEFAULT_AUDIO_RESOLUTION ])
114 })
115
09209296 116 it('Should update the video', async function () {
80b8ad2a
C
117 this.timeout(10000)
118
09209296
C
119 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
120
121 await waitJobs(servers)
122
123 await checkHlsPlaylist(servers, videoUUID)
124 })
125
b345a804 126 it('Should delete videos', async function () {
80b8ad2a
C
127 this.timeout(10000)
128
09209296 129 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
b345a804 130 await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID)
09209296
C
131
132 await waitJobs(servers)
133
134 for (const server of servers) {
135 await getVideo(server.url, videoUUID, 404)
b345a804 136 await getVideo(server.url, videoAudioUUID, 404)
09209296
C
137 }
138 })
139
140 it('Should have the playlists/segment deleted from the disk', async function () {
141 for (const server of servers) {
142 await checkDirectoryIsEmpty(server, 'videos')
0b16f5f2 143 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
09209296
C
144 }
145 })
146
147 it('Should have an empty tmp directory', async function () {
148 for (const server of servers) {
149 await checkTmpIsEmpty(server)
150 }
151 })
152
7c3b7976
C
153 after(async function () {
154 await cleanupTests(servers)
09209296
C
155 })
156})