1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
6 checkVideoFilesWereRemoved,
8 flushAndRunMultipleServers,
12 } from '../../../../shared/extra-utils'
13 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
14 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 } from '../../../../shared/extra-utils/videos/video-captions'
21 import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
23 const expect = chai.expect
25 describe('Test video captions', function () {
26 let servers: ServerInfo[]
29 before(async function () {
34 servers = await flushAndRunMultipleServers(2)
36 await setAccessTokensToServers(servers)
37 await doubleFollow(servers[0], servers[1])
39 await waitJobs(servers)
41 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' })
42 videoUUID = res.body.video.uuid
44 await waitJobs(servers)
47 it('Should list the captions and return an empty list', async function () {
48 for (const server of servers) {
49 const res = await listVideoCaptions(server.url, videoUUID)
50 expect(res.body.total).to.equal(0)
51 expect(res.body.data).to.have.lengthOf(0)
55 it('Should create two new captions', async function () {
58 await createVideoCaption({
60 accessToken: servers[0].accessToken,
63 fixture: 'subtitle-good1.vtt'
66 await createVideoCaption({
68 accessToken: servers[0].accessToken,
71 fixture: 'subtitle-good2.vtt',
72 mimeType: 'application/octet-stream'
75 await waitJobs(servers)
78 it('Should list these uploaded captions', async function () {
79 for (const server of servers) {
80 const res = await listVideoCaptions(server.url, videoUUID)
81 expect(res.body.total).to.equal(2)
82 expect(res.body.data).to.have.lengthOf(2)
84 const caption1: VideoCaption = res.body.data[0]
85 expect(caption1.language.id).to.equal('ar')
86 expect(caption1.language.label).to.equal('Arabic')
87 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
88 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
90 const caption2: VideoCaption = res.body.data[1]
91 expect(caption2.language.id).to.equal('zh')
92 expect(caption2.language.label).to.equal('Chinese')
93 expect(caption2.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
94 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
98 it('Should replace an existing caption', async function () {
101 await createVideoCaption({
103 accessToken: servers[0].accessToken,
106 fixture: 'subtitle-good2.vtt'
109 await waitJobs(servers)
112 it('Should have this caption updated', async function () {
113 for (const server of servers) {
114 const res = await listVideoCaptions(server.url, videoUUID)
115 expect(res.body.total).to.equal(2)
116 expect(res.body.data).to.have.lengthOf(2)
118 const caption1: VideoCaption = res.body.data[0]
119 expect(caption1.language.id).to.equal('ar')
120 expect(caption1.language.label).to.equal('Arabic')
121 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
122 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
126 it('Should replace an existing caption with a srt file and convert it', async function () {
129 await createVideoCaption({
131 accessToken: servers[0].accessToken,
134 fixture: 'subtitle-good.srt'
137 await waitJobs(servers)
139 // Cache invalidation
143 it('Should have this caption updated and converted', async function () {
144 for (const server of servers) {
145 const res = await listVideoCaptions(server.url, videoUUID)
146 expect(res.body.total).to.equal(2)
147 expect(res.body.data).to.have.lengthOf(2)
149 const caption1: VideoCaption = res.body.data[0]
150 expect(caption1.language.id).to.equal('ar')
151 expect(caption1.language.label).to.equal('Arabic')
152 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
154 const expected = 'WEBVTT FILE\r\n' +
157 '00:00:01.600 --> 00:00:04.200\r\n' +
161 '00:00:05.900 --> 00:00:07.999\r\n' +
162 'This is a subtitle in American English\r\n' +
165 '00:00:10.000 --> 00:00:14.000\r\n' +
166 'Adding subtitles is very easy to do\r\n'
167 await testCaptionFile(server.url, caption1.captionPath, expected)
171 it('Should remove one caption', async function () {
174 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
176 await waitJobs(servers)
179 it('Should only list the caption that was not deleted', async function () {
180 for (const server of servers) {
181 const res = await listVideoCaptions(server.url, videoUUID)
182 expect(res.body.total).to.equal(1)
183 expect(res.body.data).to.have.lengthOf(1)
185 const caption: VideoCaption = res.body.data[0]
187 expect(caption.language.id).to.equal('zh')
188 expect(caption.language.label).to.equal('Chinese')
189 expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
190 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
194 it('Should remove the video, and thus all video captions', async function () {
195 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
197 await checkVideoFilesWereRemoved(videoUUID, 1)
200 after(async function () {
201 killallServers(servers)