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 () {
32 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
35 await doubleFollow(servers[0], servers[1])
37 await waitJobs(servers)
39 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' })
40 videoUUID = res.body.video.uuid
42 await waitJobs(servers)
45 it('Should list the captions and return an empty list', async function () {
46 for (const server of servers) {
47 const res = await listVideoCaptions(server.url, videoUUID)
48 expect(res.body.total).to.equal(0)
49 expect(res.body.data).to.have.lengthOf(0)
53 it('Should create two new captions', async function () {
56 await createVideoCaption({
58 accessToken: servers[0].accessToken,
61 fixture: 'subtitle-good1.vtt'
64 await createVideoCaption({
66 accessToken: servers[0].accessToken,
69 fixture: 'subtitle-good2.vtt',
70 mimeType: 'application/octet-stream'
73 await waitJobs(servers)
76 it('Should list these uploaded captions', async function () {
77 for (const server of servers) {
78 const res = await listVideoCaptions(server.url, videoUUID)
79 expect(res.body.total).to.equal(2)
80 expect(res.body.data).to.have.lengthOf(2)
82 const caption1: VideoCaption = res.body.data[0]
83 expect(caption1.language.id).to.equal('ar')
84 expect(caption1.language.label).to.equal('Arabic')
85 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
86 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
88 const caption2: VideoCaption = res.body.data[1]
89 expect(caption2.language.id).to.equal('zh')
90 expect(caption2.language.label).to.equal('Chinese')
91 expect(caption2.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
92 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
96 it('Should replace an existing caption', async function () {
99 await createVideoCaption({
101 accessToken: servers[0].accessToken,
104 fixture: 'subtitle-good2.vtt'
107 await waitJobs(servers)
110 it('Should have this caption updated', async function () {
111 for (const server of servers) {
112 const res = await listVideoCaptions(server.url, videoUUID)
113 expect(res.body.total).to.equal(2)
114 expect(res.body.data).to.have.lengthOf(2)
116 const caption1: VideoCaption = res.body.data[0]
117 expect(caption1.language.id).to.equal('ar')
118 expect(caption1.language.label).to.equal('Arabic')
119 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
120 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
124 it('Should replace an existing caption with a srt file and convert it', async function () {
127 await createVideoCaption({
129 accessToken: servers[0].accessToken,
132 fixture: 'subtitle-good.srt'
135 await waitJobs(servers)
137 // Cache invalidation
141 it('Should have this caption updated and converted', async function () {
142 for (const server of servers) {
143 const res = await listVideoCaptions(server.url, videoUUID)
144 expect(res.body.total).to.equal(2)
145 expect(res.body.data).to.have.lengthOf(2)
147 const caption1: VideoCaption = res.body.data[0]
148 expect(caption1.language.id).to.equal('ar')
149 expect(caption1.language.label).to.equal('Arabic')
150 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
152 const expected = 'WEBVTT FILE\r\n' +
155 '00:00:01.600 --> 00:00:04.200\r\n' +
159 '00:00:05.900 --> 00:00:07.999\r\n' +
160 'This is a subtitle in American English\r\n' +
163 '00:00:10.000 --> 00:00:14.000\r\n' +
164 'Adding subtitles is very easy to do\r\n'
165 await testCaptionFile(server.url, caption1.captionPath, expected)
169 it('Should remove one caption', async function () {
172 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
174 await waitJobs(servers)
177 it('Should only list the caption that was not deleted', async function () {
178 for (const server of servers) {
179 const res = await listVideoCaptions(server.url, videoUUID)
180 expect(res.body.total).to.equal(1)
181 expect(res.body.data).to.have.lengthOf(1)
183 const caption: VideoCaption = res.body.data[0]
185 expect(caption.language.id).to.equal('zh')
186 expect(caption.language.label).to.equal('Chinese')
187 expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
188 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
192 it('Should remove the video, and thus all video captions', async function () {
193 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
195 await checkVideoFilesWereRemoved(videoUUID, 1)
199 killallServers(servers)