import {
addVideoCommentReply,
addVideoCommentThread,
- createVideoCaption,
flushAndRunServer,
getVideosList,
killallServers,
}
for (const caption of [ 'ar', 'fr', 'en', 'zh' ]) {
- await createVideoCaption({
- url: server.url,
- accessToken: server.accessToken,
+ await server.captionsCommand.createVideoCaption({
language: caption,
videoId: video.id,
fixture: 'subtitle-good2.vtt'
/* 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,
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/'
// })
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',
import * as chai from 'chai'
import {
cleanupTests,
- createVideoCaption,
flushAndRunServer,
immutableAssign,
SearchCommand,
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',
cleanupTests,
completeVideoCheck,
createUser,
- createVideoCaption,
dateIsValid,
deleteVideoComment,
expectAccountFollows,
getVideoCommentThreads,
getVideosList,
getVideoThreadComments,
- listVideoCaptions,
rateVideo,
ServerInfo,
setAccessTokensToServers,
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
}
{
- await createVideoCaption({
- url: servers[2].url,
- accessToken: servers[2].accessToken,
+ await servers[2].captionsCommand.createVideoCaption({
language: 'ar',
videoId: video4.id,
fixture: 'subtitle-good2.vtt'
})
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$'))
/* 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
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',
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$'))
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'
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$'))
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'
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$'))
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')
getVideo,
getVideosList,
immutableAssign,
- listVideoCaptions,
ServerInfo,
setAccessTokensToServers,
testCaptionFile
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
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')
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 ]) {
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')
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 () {
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')
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)
}
})
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)
}
})
import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket'
import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
-import { LiveCommand, ServicesCommand, BlacklistCommand } from '../videos'
+import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos'
import { ConfigCommand } from './config-command'
import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command'
liveCommand?: LiveCommand
servicesCommand?: ServicesCommand
blacklistCommand?: BlacklistCommand
+ captionsCommand?: CaptionsCommand
}
function parallelTests () {
server.liveCommand = new LiveCommand(server)
server.servicesCommand = new ServicesCommand(server)
server.blacklistCommand = new BlacklistCommand(server)
+ server.captionsCommand = new CaptionsCommand(server)
res(server)
})
--- /dev/null
+import { ResultList, VideoCaption } from '@shared/models'
+import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
+import { buildAbsoluteFixturePath } from '../miscs/miscs'
+import { AbstractCommand, OverrideCommandOptions } from '../shared'
+
+export class CaptionsCommand extends AbstractCommand {
+
+ createVideoCaption (options: OverrideCommandOptions & {
+ videoId: string | number
+ language: string
+ fixture: string
+ mimeType?: string
+ }) {
+ const { videoId, language, fixture, mimeType } = options
+
+ const path = '/api/v1/videos/' + videoId + '/captions/' + language
+
+ const captionfile = buildAbsoluteFixturePath(fixture)
+ const captionfileAttach = mimeType
+ ? [ captionfile, { contentType: mimeType } ]
+ : captionfile
+
+ return this.putUploadRequest({
+ ...options,
+
+ path,
+ fields: {},
+ attaches: {
+ captionfile: captionfileAttach
+ },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ listVideoCaptions (options: OverrideCommandOptions & {
+ videoId: string | number
+ }) {
+ const { videoId } = options
+ const path = '/api/v1/videos/' + videoId + '/captions'
+
+ return this.getRequestBody<ResultList<VideoCaption>>({
+ ...options,
+
+ path,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ deleteVideoCaption (options: OverrideCommandOptions & {
+ videoId: string | number
+ language: string
+ }) {
+ const { videoId, language } = options
+ const path = '/api/v1/videos/' + videoId + '/captions/' + language
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+}
--- /dev/null
+import { expect } from 'chai'
+import * as request from 'supertest'
+import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
+
+async function testCaptionFile (url: string, captionPath: string, containsString: string) {
+ const res = await request(url)
+ .get(captionPath)
+ .expect(HttpStatusCode.OK_200)
+
+ expect(res.text).to.contain(containsString)
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ testCaptionFile
+}
export * from './blacklist-command'
+export * from './captions'
+export * from './captions-command'
export * from './live-command'
export * from './live'
export * from './services-command'
-export * from './video-captions'
export * from './video-change-ownership'
export * from './video-channels'
export * from './video-comments'
+++ /dev/null
-import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests'
-import * as request from 'supertest'
-import * as chai from 'chai'
-import { buildAbsoluteFixturePath } from '../miscs/miscs'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
-
-const expect = chai.expect
-
-function createVideoCaption (args: {
- url: string
- accessToken: string
- videoId: string | number
- language: string
- fixture: string
- mimeType?: string
- statusCodeExpected?: number
-}) {
- const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
-
- const captionfile = buildAbsoluteFixturePath(args.fixture)
- const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
-
- return makeUploadRequest({
- method: 'PUT',
- url: args.url,
- path,
- token: args.accessToken,
- fields: {},
- attaches: {
- captionfile: captionfileAttach
- },
- statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
- })
-}
-
-function listVideoCaptions (url: string, videoId: string | number) {
- const path = '/api/v1/videos/' + videoId + '/captions'
-
- return makeGetRequest({
- url,
- path,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
- const path = '/api/v1/videos/' + videoId + '/captions/' + language
-
- return makeDeleteRequest({
- url,
- token,
- path,
- statusCodeExpected: HttpStatusCode.NO_CONTENT_204
- })
-}
-
-async function testCaptionFile (url: string, captionPath: string, containsString: string) {
- const res = await request(url)
- .get(captionPath)
- .expect(HttpStatusCode.OK_200)
-
- expect(res.text).to.contain(containsString)
-}
-
-// ---------------------------------------------------------------------------
-
-export {
- createVideoCaption,
- listVideoCaptions,
- testCaptionFile,
- deleteVideoCaption
-}