1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
12 setAccessTokensToServers,
14 } from '../../../shared/extra-utils'
15 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
16 import { VideoDetails } from '../../../shared/models/videos'
18 const expect = chai.expect
20 describe('Test create transcoding jobs', function () {
21 let servers: ServerInfo[] = []
22 const videosUUID: string[] = []
42 before(async function () {
45 // Run server 2 to have transcoding enabled
46 servers = await flushAndRunMultipleServers(2)
47 await setAccessTokensToServers(servers)
49 await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
51 await doubleFollow(servers[0], servers[1])
53 for (let i = 1; i <= 5; i++) {
54 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' + i })
55 videosUUID.push(res.body.video.uuid)
58 await waitJobs(servers)
61 it('Should have two video files on each server', async function () {
64 for (const server of servers) {
65 const res = await getVideosList(server.url)
66 const videos = res.body.data
67 expect(videos).to.have.lengthOf(videosUUID.length)
69 for (const video of videos) {
70 const res2 = await getVideo(server.url, video.uuid)
71 const videoDetail: VideoDetails = res2.body
72 expect(videoDetail.files).to.have.lengthOf(1)
73 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
78 it('Should run a transcoding job on video 2', async function () {
81 await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`)
82 await waitJobs(servers)
84 for (const server of servers) {
85 const res = await getVideosList(server.url)
86 const videos = res.body.data
88 let infoHashes: { [id: number]: string }
90 for (const video of videos) {
91 const res2 = await getVideo(server.url, video.uuid)
92 const videoDetail: VideoDetails = res2.body
94 if (video.uuid === videosUUID[1]) {
95 expect(videoDetail.files).to.have.lengthOf(4)
96 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
101 for (const file of videoDetail.files) {
102 infoHashes[file.resolution.id.toString()] = file.magnetUri
105 for (const resolution of Object.keys(infoHashes)) {
106 const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
107 expect(file.magnetUri).to.equal(infoHashes[resolution])
111 expect(videoDetail.files).to.have.lengthOf(1)
112 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
118 it('Should run a transcoding job on video 1 with resolution', async function () {
121 await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`)
123 await waitJobs(servers)
125 for (const server of servers) {
126 const res = await getVideosList(server.url)
127 const videos = res.body.data
128 expect(videos).to.have.lengthOf(videosUUID.length)
130 const res2 = await getVideo(server.url, videosUUID[0])
131 const videoDetail: VideoDetails = res2.body
133 expect(videoDetail.files).to.have.lengthOf(2)
134 expect(videoDetail.files[0].resolution.id).to.equal(720)
135 expect(videoDetail.files[1].resolution.id).to.equal(480)
137 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
141 it('Should generate an HLS resolution', async function () {
144 await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
146 await waitJobs(servers)
148 for (const server of servers) {
149 const res = await getVideo(server.url, videosUUID[2])
150 const videoDetail: VideoDetails = res.body
152 expect(videoDetail.files).to.have.lengthOf(1)
153 expect(videoDetail.streamingPlaylists).to.have.lengthOf(1)
155 const files = videoDetail.streamingPlaylists[0].files
156 expect(files).to.have.lengthOf(1)
157 expect(files[0].resolution.id).to.equal(480)
161 it('Should not duplicate an HLS resolution', async function () {
164 await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
166 await waitJobs(servers)
168 for (const server of servers) {
169 const res = await getVideo(server.url, videosUUID[2])
170 const videoDetail: VideoDetails = res.body
172 const files = videoDetail.streamingPlaylists[0].files
173 expect(files).to.have.lengthOf(1)
174 expect(files[0].resolution.id).to.equal(480)
178 it('Should generate all HLS resolutions', async function () {
181 await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`)
183 await waitJobs(servers)
185 for (const server of servers) {
186 const res = await getVideo(server.url, videosUUID[3])
187 const videoDetail: VideoDetails = res.body
189 expect(videoDetail.files).to.have.lengthOf(1)
190 expect(videoDetail.streamingPlaylists).to.have.lengthOf(1)
192 const files = videoDetail.streamingPlaylists[0].files
193 expect(files).to.have.lengthOf(4)
197 it('Should optimize the video file and generate HLS videos if enabled in config', async function () {
200 config.transcoding.hls.enabled = true
201 await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
203 await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`)
205 await waitJobs(servers)
207 for (const server of servers) {
208 const res = await getVideo(server.url, videosUUID[4])
209 const videoDetail: VideoDetails = res.body
211 expect(videoDetail.files).to.have.lengthOf(4)
212 expect(videoDetail.streamingPlaylists).to.have.lengthOf(1)
213 expect(videoDetail.streamingPlaylists[0].files).to.have.lengthOf(4)
217 after(async function () {
218 await cleanupTests(servers)