Introduce captions command

This commit is contained in:
Chocobozzz
2021-07-08 11:49:38 +02:00
parent e3d15a6a9a
commit a2470c9f4b
11 changed files with 149 additions and 164 deletions

View File

@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import { VideoCreateResult } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { HttpStatusCode } from '@shared/core-utils'
import {
buildAbsoluteFixturePath,
cleanupTests,
@@ -15,8 +14,8 @@ import {
setAccessTokensToServers,
uploadVideo,
userLogin
} from '../../../../shared/extra-utils'
import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
} from '@shared/extra-utils'
import { VideoCreateResult } from '@shared/models'
describe('Test video captions API validator', function () {
const path = '/api/v1/videos/'
@@ -159,9 +158,7 @@ describe('Test video captions API validator', function () {
// })
it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
await createVideoCaption({
url: server.url,
accessToken: server.accessToken,
await server.captionsCommand.createVideoCaption({
language: 'zh',
videoId: video.uuid,
fixture: 'subtitle-good.srt',

View File

@@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
createVideoCaption,
flushAndRunServer,
immutableAssign,
SearchCommand,
@@ -54,18 +53,14 @@ describe('Test videos search', function () {
const videoId = res.body.video.id
videoUUID = res.body.video.uuid
await createVideoCaption({
url: server.url,
accessToken: server.accessToken,
await server.captionsCommand.createVideoCaption({
language: 'en',
videoId,
fixture: 'subtitle-good2.vtt',
mimeType: 'application/octet-stream'
})
await createVideoCaption({
url: server.url,
accessToken: server.accessToken,
await server.captionsCommand.createVideoCaption({
language: 'aa',
videoId,
fixture: 'subtitle-good2.vtt',

View File

@@ -8,7 +8,6 @@ import {
cleanupTests,
completeVideoCheck,
createUser,
createVideoCaption,
dateIsValid,
deleteVideoComment,
expectAccountFollows,
@@ -17,7 +16,6 @@ import {
getVideoCommentThreads,
getVideosList,
getVideoThreadComments,
listVideoCaptions,
rateVideo,
ServerInfo,
setAccessTokensToServers,
@@ -26,7 +24,7 @@ import {
userLogin,
waitJobs
} from '@shared/extra-utils'
import { Video, VideoCaption, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
import { Video, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
const expect = chai.expect
@@ -385,9 +383,7 @@ describe('Test follows', function () {
}
{
await createVideoCaption({
url: servers[2].url,
accessToken: servers[2].accessToken,
await servers[2].captionsCommand.createVideoCaption({
language: 'ar',
videoId: video4.id,
fixture: 'subtitle-good2.vtt'
@@ -543,11 +539,11 @@ describe('Test follows', function () {
})
it('Should have propagated captions', async function () {
const res = await listVideoCaptions(servers[0].url, video4.id)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
const body = await servers[0].captionsCommand.listVideoCaptions({ videoId: video4.id })
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
const caption1: VideoCaption = res.body.data[0]
const caption1 = body.data[0]
expect(caption1.language.id).to.equal('ar')
expect(caption1.language.label).to.equal('Arabic')
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/.+-ar.vtt$'))

View File

@@ -1,25 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import {
checkVideoFilesWereRemoved,
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
removeVideo,
ServerInfo,
setAccessTokensToServers,
testCaptionFile,
uploadVideo,
wait
} from '../../../../shared/extra-utils'
import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import {
createVideoCaption,
deleteVideoCaption,
listVideoCaptions,
testCaptionFile
} from '../../../../shared/extra-utils/videos/video-captions'
import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
wait,
waitJobs
} from '@shared/extra-utils'
const expect = chai.expect
@@ -47,26 +42,22 @@ describe('Test video captions', function () {
it('Should list the captions and return an empty list', async function () {
for (const server of servers) {
const res = await listVideoCaptions(server.url, videoUUID)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
}
})
it('Should create two new captions', async function () {
this.timeout(30000)
await createVideoCaption({
url: servers[0].url,
accessToken: servers[0].accessToken,
await servers[0].captionsCommand.createVideoCaption({
language: 'ar',
videoId: videoUUID,
fixture: 'subtitle-good1.vtt'
})
await createVideoCaption({
url: servers[0].url,
accessToken: servers[0].accessToken,
await servers[0].captionsCommand.createVideoCaption({
language: 'zh',
videoId: videoUUID,
fixture: 'subtitle-good2.vtt',
@@ -78,17 +69,17 @@ describe('Test video captions', function () {
it('Should list these uploaded captions', 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 body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
expect(body.total).to.equal(2)
expect(body.data).to.have.lengthOf(2)
const caption1: VideoCaption = res.body.data[0]
const caption1 = body.data[0]
expect(caption1.language.id).to.equal('ar')
expect(caption1.language.label).to.equal('Arabic')
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
const caption2: VideoCaption = res.body.data[1]
const caption2 = body.data[1]
expect(caption2.language.id).to.equal('zh')
expect(caption2.language.label).to.equal('Chinese')
expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
@@ -99,9 +90,7 @@ describe('Test video captions', function () {
it('Should replace an existing caption', async function () {
this.timeout(30000)
await createVideoCaption({
url: servers[0].url,
accessToken: servers[0].accessToken,
await servers[0].captionsCommand.createVideoCaption({
language: 'ar',
videoId: videoUUID,
fixture: 'subtitle-good2.vtt'
@@ -112,11 +101,11 @@ describe('Test video captions', function () {
it('Should have this caption updated', 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 body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
expect(body.total).to.equal(2)
expect(body.data).to.have.lengthOf(2)
const caption1: VideoCaption = res.body.data[0]
const caption1 = body.data[0]
expect(caption1.language.id).to.equal('ar')
expect(caption1.language.label).to.equal('Arabic')
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -127,9 +116,7 @@ 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,
await servers[0].captionsCommand.createVideoCaption({
language: 'ar',
videoId: videoUUID,
fixture: 'subtitle-good.srt'
@@ -143,11 +130,11 @@ describe('Test video captions', function () {
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 body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
expect(body.total).to.equal(2)
expect(body.data).to.have.lengthOf(2)
const caption1: VideoCaption = res.body.data[0]
const caption1 = body.data[0]
expect(caption1.language.id).to.equal('ar')
expect(caption1.language.label).to.equal('Arabic')
expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -172,18 +159,18 @@ describe('Test video captions', function () {
it('Should remove one caption', async function () {
this.timeout(30000)
await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' })
await waitJobs(servers)
})
it('Should only list the caption that was not deleted', async function () {
for (const server of servers) {
const res = await listVideoCaptions(server.url, videoUUID)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
const caption: VideoCaption = res.body.data[0]
const caption = body.data[0]
expect(caption.language.id).to.equal('zh')
expect(caption.language.label).to.equal('Chinese')

View File

@@ -11,7 +11,6 @@ import {
getVideo,
getVideosList,
immutableAssign,
listVideoCaptions,
ServerInfo,
setAccessTokensToServers,
testCaptionFile
@@ -25,7 +24,7 @@ import {
getYoutubeVideoUrl,
importVideo
} from '../../../../shared/extra-utils/videos/video-imports'
import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
const expect = chai.expect
@@ -36,8 +35,8 @@ describe('Test video imports', function () {
if (areHttpImportTestsDisabled()) return
async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
const resHttp = await getVideo(url, idHttp)
async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) {
const resHttp = await getVideo(server.url, idHttp)
const videoHttp: VideoDetails = resHttp.body
expect(videoHttp.name).to.equal('small video - youtube')
@@ -55,9 +54,9 @@ describe('Test video imports', function () {
expect(originallyPublishedAt.getMonth()).to.equal(0)
expect(originallyPublishedAt.getFullYear()).to.equal(2019)
const resMagnet = await getVideo(url, idMagnet)
const resMagnet = await getVideo(server.url, idMagnet)
const videoMagnet: VideoDetails = resMagnet.body
const resTorrent = await getVideo(url, idTorrent)
const resTorrent = await getVideo(server.url, idTorrent)
const videoTorrent: VideoDetails = resTorrent.body
for (const video of [ videoMagnet, videoTorrent ]) {
@@ -73,12 +72,12 @@ describe('Test video imports', function () {
expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
expect(videoMagnet.name).to.contain('super peertube2 video')
const resCaptions = await listVideoCaptions(url, idHttp)
expect(resCaptions.body.total).to.equal(2)
const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp })
expect(bodyCaptions.total).to.equal(2)
}
async function checkVideoServer2 (url: string, id: number | string) {
const res = await getVideo(url, id)
async function checkVideoServer2 (server: ServerInfo, id: number | string) {
const res = await getVideo(server.url, id)
const video: VideoDetails = res.body
expect(video.name).to.equal('my super name')
@@ -91,8 +90,8 @@ describe('Test video imports', function () {
expect(video.files).to.have.lengthOf(1)
const resCaptions = await listVideoCaptions(url, id)
expect(resCaptions.body.total).to.equal(2)
const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id })
expect(bodyCaptions.total).to.equal(2)
}
before(async function () {
@@ -135,8 +134,8 @@ describe('Test video imports', function () {
await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
const videoCaptions: VideoCaption[] = resCaptions.body.data
const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id })
const videoCaptions = bodyCaptions.data
expect(videoCaptions).to.have.lengthOf(2)
const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
@@ -241,7 +240,7 @@ Ajouter un sous-titre est vraiment facile`)
expect(res.body.data).to.have.lengthOf(3)
const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
}
})
@@ -273,10 +272,10 @@ Ajouter un sous-titre est vraiment facile`)
expect(res.body.total).to.equal(4)
expect(res.body.data).to.have.lengthOf(4)
await checkVideoServer2(server.url, res.body.data[0].uuid)
await checkVideoServer2(server, res.body.data[0].uuid)
const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
}
})