1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
6 checkVideoFilesWereRemoved,
9 flushAndRunMultipleServers,
13 } from '../../../../shared/extra-utils'
14 import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
15 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 } from '../../../../shared/extra-utils/videos/video-captions'
22 import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
24 const expect = chai.expect
26 describe('Test video captions', function () {
27 let servers: ServerInfo[]
30 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
36 await doubleFollow(servers[0], servers[1])
38 await waitJobs(servers)
40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' })
41 videoUUID = res.body.video.uuid
43 await waitJobs(servers)
46 it('Should list the captions and return an empty list', async function () {
47 for (const server of servers) {
48 const res = await listVideoCaptions(server.url, videoUUID)
49 expect(res.body.total).to.equal(0)
50 expect(res.body.data).to.have.lengthOf(0)
54 it('Should create two new captions', async function () {
57 await createVideoCaption({
59 accessToken: servers[0].accessToken,
62 fixture: 'subtitle-good1.vtt'
65 await createVideoCaption({
67 accessToken: servers[0].accessToken,
70 fixture: 'subtitle-good2.vtt',
71 mimeType: 'application/octet-stream'
74 await waitJobs(servers)
77 it('Should list these uploaded captions', async function () {
78 for (const server of servers) {
79 const res = await listVideoCaptions(server.url, videoUUID)
80 expect(res.body.total).to.equal(2)
81 expect(res.body.data).to.have.lengthOf(2)
83 const caption1: VideoCaption = res.body.data[0]
84 expect(caption1.language.id).to.equal('ar')
85 expect(caption1.language.label).to.equal('Arabic')
86 expect(caption1.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-ar.vtt')
87 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
89 const caption2: VideoCaption = res.body.data[1]
90 expect(caption2.language.id).to.equal('zh')
91 expect(caption2.language.label).to.equal('Chinese')
92 expect(caption2.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-zh.vtt')
93 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
97 it('Should replace an existing caption', async function () {
100 await createVideoCaption({
102 accessToken: servers[0].accessToken,
105 fixture: 'subtitle-good2.vtt'
108 await waitJobs(servers)
111 it('Should have this caption updated', async function () {
112 for (const server of servers) {
113 const res = await listVideoCaptions(server.url, videoUUID)
114 expect(res.body.total).to.equal(2)
115 expect(res.body.data).to.have.lengthOf(2)
117 const caption1: VideoCaption = res.body.data[0]
118 expect(caption1.language.id).to.equal('ar')
119 expect(caption1.language.label).to.equal('Arabic')
120 expect(caption1.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-ar.vtt')
121 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
125 it('Should replace an existing caption with a srt file and convert it', async function () {
128 await createVideoCaption({
130 accessToken: servers[0].accessToken,
133 fixture: 'subtitle-good.srt'
136 await waitJobs(servers)
138 // Cache invalidation
142 it('Should have this caption updated and converted', async function () {
143 for (const server of servers) {
144 const res = await listVideoCaptions(server.url, videoUUID)
145 expect(res.body.total).to.equal(2)
146 expect(res.body.data).to.have.lengthOf(2)
148 const caption1: VideoCaption = res.body.data[0]
149 expect(caption1.language.id).to.equal('ar')
150 expect(caption1.language.label).to.equal('Arabic')
151 expect(caption1.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-ar.vtt')
153 const expected = 'WEBVTT FILE\r\n' +
156 '00:00:01.600 --> 00:00:04.200\r\n' +
160 '00:00:05.900 --> 00:00:07.999\r\n' +
161 'This is a subtitle in American English\r\n' +
164 '00:00:10.000 --> 00:00:14.000\r\n' +
165 'Adding subtitles is very easy to do\r\n'
166 await testCaptionFile(server.url, caption1.captionPath, expected)
170 it('Should remove one caption', async function () {
173 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
175 await waitJobs(servers)
178 it('Should only list the caption that was not deleted', async function () {
179 for (const server of servers) {
180 const res = await listVideoCaptions(server.url, videoUUID)
181 expect(res.body.total).to.equal(1)
182 expect(res.body.data).to.have.lengthOf(1)
184 const caption: VideoCaption = res.body.data[0]
186 expect(caption.language.id).to.equal('zh')
187 expect(caption.language.label).to.equal('Chinese')
188 expect(caption.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-zh.vtt')
189 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
193 it('Should remove the video, and thus all video captions', async function () {
194 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
196 await checkVideoFilesWereRemoved(videoUUID, 1)
199 after(async function () {
200 await cleanupTests(servers)