From f4001cf408a99049d01a356bfb20a62342de06ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 Jul 2018 14:22:16 +0200 Subject: Handle .srt subtitles --- server/tests/api/check-params/video-captions.ts | 35 +++++++++++++++- server/tests/api/videos/video-captions.ts | 53 ++++++++++++++++++++++++- server/tests/fixtures/subtitle-bad.txt | 11 +++++ server/tests/fixtures/subtitle-good.srt | 11 +++++ server/tests/utils/videos/videos.ts | 2 +- 5 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 server/tests/fixtures/subtitle-bad.txt create mode 100644 server/tests/fixtures/subtitle-good.srt (limited to 'server/tests') diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 12f890db8..a3d7ac35d 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -1,6 +1,5 @@ /* tslint:disable:no-unused-expression */ -import * as chai from 'chai' import 'mocha' import { createUser, @@ -127,6 +126,40 @@ describe('Test video captions API validator', function () { }) }) + it('Should fail with an invalid captionfile extension', async function () { + const attaches = { + 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt') + } + + const captionPath = path + videoUUID + '/captions/fr' + await makeUploadRequest({ + method: 'PUT', + url: server.url, + path: captionPath, + token: server.accessToken, + fields, + attaches, + statusCodeExpected: 400 + }) + }) + + // it('Should fail with an invalid captionfile srt', async function () { + // const attaches = { + // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt') + // } + // + // const captionPath = path + videoUUID + '/captions/fr' + // await makeUploadRequest({ + // method: 'PUT', + // url: server.url, + // path: captionPath, + // token: server.accessToken, + // fields, + // attaches, + // statusCodeExpected: 500 + // }) + // }) + it('Should success with the correct parameters', async function () { const captionPath = path + videoUUID + '/captions/fr' await makeUploadRequest({ diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index cbf5268f0..eb73c5baf 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -2,7 +2,7 @@ import * as chai from 'chai' import 'mocha' -import { doubleFollow, flushAndRunMultipleServers, uploadVideo } from '../../utils' +import { checkVideoFilesWereRemoved, doubleFollow, flushAndRunMultipleServers, removeVideo, uploadVideo, wait } from '../../utils' import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' import { waitJobs } from '../../utils/server/jobs' import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions' @@ -110,6 +110,51 @@ describe('Test video captions', function () { } }) + it('Should replace an existing caption with a srt file and convert it', async function () { + this.timeout(30000) + + await createVideoCaption({ + url: servers[0].url, + accessToken: servers[0].accessToken, + 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) { + const res = await listVideoCaptions(server.url, videoUUID) + expect(res.body.total).to.equal(2) + expect(res.body.data).to.have.lengthOf(2) + + const caption1: VideoCaption = res.body.data[0] + expect(caption1.language.id).to.equal('ar') + expect(caption1.language.label).to.equal('Arabic') + expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt') + + 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) + } + }) + it('Should remove one caption', async function () { this.timeout(30000) @@ -133,6 +178,12 @@ describe('Test video captions', function () { } }) + 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) + }) + after(async function () { killallServers(servers) }) diff --git a/server/tests/fixtures/subtitle-bad.txt b/server/tests/fixtures/subtitle-bad.txt new file mode 100644 index 000000000..a2a30ae47 --- /dev/null +++ b/server/tests/fixtures/subtitle-bad.txt @@ -0,0 +1,11 @@ +1 +00:00:01,600 --> 00:00:04,200 +English (US) + +2 +00:00:05,900 --> 00:00:07,999 +This is a subtitle in American English + +3 +00:00:10,000 --> 00:00:14,000 +Adding subtitles is very easy to do \ No newline at end of file diff --git a/server/tests/fixtures/subtitle-good.srt b/server/tests/fixtures/subtitle-good.srt new file mode 100644 index 000000000..a2a30ae47 --- /dev/null +++ b/server/tests/fixtures/subtitle-good.srt @@ -0,0 +1,11 @@ +1 +00:00:01,600 --> 00:00:04,200 +English (US) + +2 +00:00:05,900 --> 00:00:07,999 +This is a subtitle in American English + +3 +00:00:10,000 --> 00:00:14,000 +Adding subtitles is very easy to do \ No newline at end of file diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 4f7ce6d6b..74bf7354e 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -301,7 +301,7 @@ function searchVideoWithSort (url: string, search: string, sort: string) { async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) { const testDirectory = 'test' + serverNumber - for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews' ]) { + for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) { const directoryPath = join(root(), testDirectory, directory) const directoryExists = existsSync(directoryPath) -- cgit v1.2.3