1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
6 checkVideoFilesWereRemoved,
8 flushAndRunMultipleServers,
12 } from '../../../../shared/utils'
13 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index'
14 import { waitJobs } from '../../../../shared/utils/server/jobs'
15 import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../../../shared/utils/videos/video-captions'
16 import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
18 const expect = chai.expect
20 describe('Test video captions', function () {
21 let servers: ServerInfo[]
24 before(async function () {
29 servers = await flushAndRunMultipleServers(2)
31 await setAccessTokensToServers(servers)
32 await doubleFollow(servers[0], servers[1])
34 await waitJobs(servers)
36 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' })
37 videoUUID = res.body.video.uuid
39 await waitJobs(servers)
42 it('Should list the captions and return an empty list', async function () {
43 for (const server of servers) {
44 const res = await listVideoCaptions(server.url, videoUUID)
45 expect(res.body.total).to.equal(0)
46 expect(res.body.data).to.have.lengthOf(0)
50 it('Should create two new captions', async function () {
53 await createVideoCaption({
55 accessToken: servers[0].accessToken,
58 fixture: 'subtitle-good1.vtt'
61 await createVideoCaption({
63 accessToken: servers[0].accessToken,
66 fixture: 'subtitle-good2.vtt',
67 mimeType: 'application/octet-stream'
70 await waitJobs(servers)
73 it('Should list these uploaded captions', async function () {
74 for (const server of servers) {
75 const res = await listVideoCaptions(server.url, videoUUID)
76 expect(res.body.total).to.equal(2)
77 expect(res.body.data).to.have.lengthOf(2)
79 const caption1: VideoCaption = res.body.data[0]
80 expect(caption1.language.id).to.equal('ar')
81 expect(caption1.language.label).to.equal('Arabic')
82 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
83 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
85 const caption2: VideoCaption = res.body.data[1]
86 expect(caption2.language.id).to.equal('zh')
87 expect(caption2.language.label).to.equal('Chinese')
88 expect(caption2.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
89 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
93 it('Should replace an existing caption', async function () {
96 await createVideoCaption({
98 accessToken: servers[0].accessToken,
101 fixture: 'subtitle-good2.vtt'
104 await waitJobs(servers)
107 it('Should have this caption updated', async function () {
108 for (const server of servers) {
109 const res = await listVideoCaptions(server.url, videoUUID)
110 expect(res.body.total).to.equal(2)
111 expect(res.body.data).to.have.lengthOf(2)
113 const caption1: VideoCaption = res.body.data[0]
114 expect(caption1.language.id).to.equal('ar')
115 expect(caption1.language.label).to.equal('Arabic')
116 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
117 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
121 it('Should replace an existing caption with a srt file and convert it', async function () {
124 await createVideoCaption({
126 accessToken: servers[0].accessToken,
129 fixture: 'subtitle-good.srt'
132 await waitJobs(servers)
134 // Cache invalidation
138 it('Should have this caption updated and converted', async function () {
139 for (const server of servers) {
140 const res = await listVideoCaptions(server.url, videoUUID)
141 expect(res.body.total).to.equal(2)
142 expect(res.body.data).to.have.lengthOf(2)
144 const caption1: VideoCaption = res.body.data[0]
145 expect(caption1.language.id).to.equal('ar')
146 expect(caption1.language.label).to.equal('Arabic')
147 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
149 const expected = 'WEBVTT FILE\r\n' +
152 '00:00:01.600 --> 00:00:04.200\r\n' +
156 '00:00:05.900 --> 00:00:07.999\r\n' +
157 'This is a subtitle in American English\r\n' +
160 '00:00:10.000 --> 00:00:14.000\r\n' +
161 'Adding subtitles is very easy to do\r\n'
162 await testCaptionFile(server.url, caption1.captionPath, expected)
166 it('Should remove one caption', async function () {
169 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
171 await waitJobs(servers)
174 it('Should only list the caption that was not deleted', async function () {
175 for (const server of servers) {
176 const res = await listVideoCaptions(server.url, videoUUID)
177 expect(res.body.total).to.equal(1)
178 expect(res.body.data).to.have.lengthOf(1)
180 const caption: VideoCaption = res.body.data[0]
182 expect(caption.language.id).to.equal('zh')
183 expect(caption.language.label).to.equal('Chinese')
184 expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
185 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
189 it('Should remove the video, and thus all video captions', async function () {
190 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
192 await checkVideoFilesWereRemoved(videoUUID, 1)
195 after(async function () {
196 killallServers(servers)