]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/transcoding/hls.ts
Stop testing broken youtube-dl
[github/Chocobozzz/PeerTube.git] / server / tests / api / transcoding / hls.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { join } from 'path'
4 import { checkDirectoryIsEmpty, checkTmpIsEmpty, completeCheckHlsPlaylist } from '@server/tests/shared'
5 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
7 import {
8 cleanupTests,
9 createMultipleServers,
10 doubleFollow,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
15 } from '@shared/server-commands'
16 import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
17
18 describe('Test HLS videos', function () {
19 let servers: PeerTubeServer[] = []
20
21 function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) {
22 const videoUUIDs: string[] = []
23
24 it('Should upload a video and transcode it to HLS', async function () {
25 this.timeout(120000)
26
27 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
28 videoUUIDs.push(uuid)
29
30 await waitJobs(servers)
31
32 await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
33 })
34
35 it('Should upload an audio file and transcode it to HLS', async function () {
36 this.timeout(120000)
37
38 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
39 videoUUIDs.push(uuid)
40
41 await waitJobs(servers)
42
43 await completeCheckHlsPlaylist({
44 servers,
45 videoUUID: uuid,
46 hlsOnly,
47 resolutions: [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ],
48 objectStorageBaseUrl
49 })
50 })
51
52 it('Should update the video', async function () {
53 this.timeout(30000)
54
55 await servers[0].videos.update({ id: videoUUIDs[0], attributes: { name: 'video 1 updated' } })
56
57 await waitJobs(servers)
58
59 await completeCheckHlsPlaylist({ servers, videoUUID: videoUUIDs[0], hlsOnly, objectStorageBaseUrl })
60 })
61
62 it('Should delete videos', async function () {
63 this.timeout(10000)
64
65 for (const uuid of videoUUIDs) {
66 await servers[0].videos.remove({ id: uuid })
67 }
68
69 await waitJobs(servers)
70
71 for (const server of servers) {
72 for (const uuid of videoUUIDs) {
73 await server.videos.get({ id: uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
74 }
75 }
76 })
77
78 it('Should have the playlists/segment deleted from the disk', async function () {
79 for (const server of servers) {
80 await checkDirectoryIsEmpty(server, 'videos', [ 'private' ])
81 await checkDirectoryIsEmpty(server, join('videos', 'private'))
82
83 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'), [ 'private' ])
84 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls', 'private'))
85 }
86 })
87
88 it('Should have an empty tmp directory', async function () {
89 for (const server of servers) {
90 await checkTmpIsEmpty(server)
91 }
92 })
93 }
94
95 before(async function () {
96 this.timeout(120000)
97
98 const configOverride = {
99 transcoding: {
100 enabled: true,
101 allow_audio_files: true,
102 hls: {
103 enabled: true
104 }
105 }
106 }
107 servers = await createMultipleServers(2, configOverride)
108
109 // Get the access tokens
110 await setAccessTokensToServers(servers)
111
112 // Server 1 and server 2 follow each other
113 await doubleFollow(servers[0], servers[1])
114 })
115
116 describe('With WebTorrent & HLS enabled', function () {
117 runTestSuite(false)
118 })
119
120 describe('With only HLS enabled', function () {
121
122 before(async function () {
123 await servers[0].config.updateCustomSubConfig({
124 newConfig: {
125 transcoding: {
126 enabled: true,
127 allowAudioFiles: true,
128 resolutions: {
129 '144p': false,
130 '240p': true,
131 '360p': true,
132 '480p': true,
133 '720p': true,
134 '1080p': true,
135 '1440p': true,
136 '2160p': true
137 },
138 hls: {
139 enabled: true
140 },
141 webtorrent: {
142 enabled: false
143 }
144 }
145 }
146 })
147 })
148
149 runTestSuite(true)
150 })
151
152 describe('With object storage enabled', function () {
153 if (areMockObjectStorageTestsDisabled()) return
154
155 before(async function () {
156 this.timeout(120000)
157
158 const configOverride = ObjectStorageCommand.getDefaultMockConfig()
159 await ObjectStorageCommand.prepareDefaultMockBuckets()
160
161 await servers[0].kill()
162 await servers[0].run(configOverride)
163 })
164
165 runTestSuite(true, ObjectStorageCommand.getMockPlaylistBaseUrl())
166 })
167
168 after(async function () {
169 await cleanupTests(servers)
170 })
171 })