diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index a67e528c6..1e97cc6ca 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -2,7 +2,7 @@ import * as chai from 'chai' import 'mocha' -import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos' +import { VideoDetails, VideoImport, VideoPrivacy, VideoCaption } from '../../../../shared/models/videos' import { cleanupTests, doubleFollow, @@ -11,6 +11,8 @@ import { getMyVideos, getVideo, getVideosList, + listVideoCaptions, + testCaptionFile, immutableAssign, ServerInfo, setAccessTokensToServers @@ -110,6 +112,46 @@ describe('Test video imports', function () { const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) expect(res.body.video.name).to.equal('small video - youtube') + + const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) + const videoCaptions: VideoCaption[] = resCaptions.body + expect(videoCaptions).to.have.lengthOf(2) + + const enCaption = videoCaptions.filter(caption => caption.language.label === 'en')[0] + expect(enCaption).to.not(undefined) + expect(enCaption.language.label).to.equal('en') + expect(enCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`) + await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT + + 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`) + + const frCaption = videoCaptions.filter(caption => caption.language.label === 'fr')[0] + expect(frCaption).to.not(undefined) + expect(frCaption.language.label).to.equal('fr') + expect(frCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`) + await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT + + 1 + 00:00:01,600 --> 00:00:04.200 + Français (FR) + + 2 + 00:00:05,900 --> 00:00:07.999 + C'est un sous-titre français + + 3 + 00:00:10,000 --> 00:00:14.000 + Ajouter un sous-titre est vraiment facile`) } { diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 78acf72aa..fd8fef5dc 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -18,6 +18,7 @@ export * from './users/users' export * from './users/accounts' export * from './videos/video-abuses' export * from './videos/video-blacklist' +export * from './videos/video-captions' export * from './videos/video-channels' export * from './videos/video-comments' export * from './videos/video-streaming-playlists'