2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-07-12 12:02:00 -05:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-08 04:49:38 -05:00
|
|
|
import * as chai from 'chai'
|
2018-10-29 11:48:31 -05:00
|
|
|
import {
|
2020-01-31 09:56:52 -06:00
|
|
|
checkVideoFilesWereRemoved,
|
|
|
|
cleanupTests,
|
2018-10-29 11:48:31 -05:00
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
|
|
|
removeVideo,
|
2021-07-08 04:49:38 -05:00
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
testCaptionFile,
|
2018-10-29 11:48:31 -05:00
|
|
|
uploadVideo,
|
2021-07-08 04:49:38 -05:00
|
|
|
wait,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
2018-07-12 12:02:00 -05:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test video captions', function () {
|
2021-02-15 07:08:16 -06:00
|
|
|
const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
|
|
|
|
|
2018-07-12 12:02:00 -05:00
|
|
|
let servers: ServerInfo[]
|
|
|
|
let videoUUID: string
|
|
|
|
|
|
|
|
before(async function () {
|
2020-12-11 03:36:05 -06:00
|
|
|
this.timeout(60000)
|
2018-07-12 12:02:00 -05:00
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2020-01-31 09:56:52 -06:00
|
|
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' })
|
2018-07-12 12:02:00 -05:00
|
|
|
videoUUID = res.body.video.uuid
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the captions and return an empty list', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-08 04:49:38 -05:00
|
|
|
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
|
|
|
|
expect(body.total).to.equal(0)
|
|
|
|
expect(body.data).to.have.lengthOf(0)
|
2018-07-12 12:02:00 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should create two new captions', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
await servers[0].captionsCommand.createVideoCaption({
|
2018-07-12 12:02:00 -05:00
|
|
|
language: 'ar',
|
|
|
|
videoId: videoUUID,
|
|
|
|
fixture: 'subtitle-good1.vtt'
|
|
|
|
})
|
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
await servers[0].captionsCommand.createVideoCaption({
|
2018-07-12 12:02:00 -05:00
|
|
|
language: 'zh',
|
|
|
|
videoId: videoUUID,
|
2018-08-06 04:45:24 -05:00
|
|
|
fixture: 'subtitle-good2.vtt',
|
|
|
|
mimeType: 'application/octet-stream'
|
2018-07-12 12:02:00 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list these uploaded captions', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-08 04:49:38 -05:00
|
|
|
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
|
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.have.lengthOf(2)
|
2018-07-12 12:02:00 -05:00
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
const caption1 = body.data[0]
|
2018-07-12 12:02:00 -05:00
|
|
|
expect(caption1.language.id).to.equal('ar')
|
|
|
|
expect(caption1.language.label).to.equal('Arabic')
|
2021-02-15 07:08:16 -06:00
|
|
|
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
|
2018-07-12 12:02:00 -05:00
|
|
|
await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
|
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
const caption2 = body.data[1]
|
2018-07-12 12:02:00 -05:00
|
|
|
expect(caption2.language.id).to.equal('zh')
|
|
|
|
expect(caption2.language.label).to.equal('Chinese')
|
2021-02-15 07:08:16 -06:00
|
|
|
expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
|
2018-07-12 12:02:00 -05:00
|
|
|
await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should replace an existing caption', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
await servers[0].captionsCommand.createVideoCaption({
|
2018-07-12 12:02:00 -05:00
|
|
|
language: 'ar',
|
|
|
|
videoId: videoUUID,
|
|
|
|
fixture: 'subtitle-good2.vtt'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have this caption updated', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-08 04:49:38 -05:00
|
|
|
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
|
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.have.lengthOf(2)
|
2018-07-12 12:02:00 -05:00
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
const caption1 = body.data[0]
|
2018-07-12 12:02:00 -05:00
|
|
|
expect(caption1.language.id).to.equal('ar')
|
|
|
|
expect(caption1.language.label).to.equal('Arabic')
|
2021-02-15 07:08:16 -06:00
|
|
|
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
|
2018-07-12 12:02:00 -05:00
|
|
|
await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-07-16 07:22:16 -05:00
|
|
|
it('Should replace an existing caption with a srt file and convert it', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
await servers[0].captionsCommand.createVideoCaption({
|
2018-07-16 07:22:16 -05:00
|
|
|
language: 'ar',
|
|
|
|
videoId: videoUUID,
|
|
|
|
fixture: 'subtitle-good.srt'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
// Cache invalidation
|
|
|
|
await wait(3000)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have this caption updated and converted', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-08 04:49:38 -05:00
|
|
|
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
|
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.have.lengthOf(2)
|
2018-07-16 07:22:16 -05:00
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
const caption1 = body.data[0]
|
2018-07-16 07:22:16 -05:00
|
|
|
expect(caption1.language.id).to.equal('ar')
|
|
|
|
expect(caption1.language.label).to.equal('Arabic')
|
2021-02-15 07:08:16 -06:00
|
|
|
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
|
2018-07-16 07:22:16 -05:00
|
|
|
|
|
|
|
const expected = 'WEBVTT FILE\r\n' +
|
|
|
|
'\r\n' +
|
|
|
|
'1\r\n' +
|
|
|
|
'00:00:01.600 --> 00:00:04.200\r\n' +
|
|
|
|
'English (US)\r\n' +
|
|
|
|
'\r\n' +
|
|
|
|
'2\r\n' +
|
|
|
|
'00:00:05.900 --> 00:00:07.999\r\n' +
|
|
|
|
'This is a subtitle in American English\r\n' +
|
|
|
|
'\r\n' +
|
|
|
|
'3\r\n' +
|
|
|
|
'00:00:10.000 --> 00:00:14.000\r\n' +
|
|
|
|
'Adding subtitles is very easy to do\r\n'
|
|
|
|
await testCaptionFile(server.url, caption1.captionPath, expected)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-07-12 12:02:00 -05:00
|
|
|
it('Should remove one caption', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' })
|
2018-07-12 12:02:00 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should only list the caption that was not deleted', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-08 04:49:38 -05:00
|
|
|
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
|
|
|
|
expect(body.total).to.equal(1)
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
2018-07-12 12:02:00 -05:00
|
|
|
|
2021-07-08 04:49:38 -05:00
|
|
|
const caption = body.data[0]
|
2018-07-12 12:02:00 -05:00
|
|
|
|
|
|
|
expect(caption.language.id).to.equal('zh')
|
|
|
|
expect(caption.language.label).to.equal('Chinese')
|
2021-02-15 07:08:16 -06:00
|
|
|
expect(caption.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
|
2018-07-12 12:02:00 -05:00
|
|
|
await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-07-16 07:22:16 -05:00
|
|
|
it('Should remove the video, and thus all video captions', async function () {
|
|
|
|
await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
|
|
|
|
|
|
|
|
await checkVideoFilesWereRemoved(videoUUID, 1)
|
|
|
|
})
|
|
|
|
|
2019-04-24 08:10:37 -05:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-07-12 12:02:00 -05:00
|
|
|
})
|
|
|
|
})
|