1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Integrate transcription in PeerTube

This commit is contained in:
Chocobozzz 2024-06-13 09:23:12 +02:00
parent ef14cf4a5c
commit 1bfb791e05
No known key found for this signature in database
GPG key ID: 583A612D890159BE
172 changed files with 2674 additions and 945 deletions

View file

@ -5,9 +5,6 @@ import {
AcceptRunnerJobResult,
ErrorRunnerJobBody,
HttpStatusCode,
isHLSTranscodingPayloadSuccess,
isLiveRTMPHLSTranscodingUpdatePayload,
isWebVideoOrAudioMergeTranscodingPayloadSuccess,
ListRunnerJobsQuery,
RequestRunnerJobBody,
RequestRunnerJobResult,
@ -22,8 +19,13 @@ import {
RunnerJobType,
RunnerJobUpdateBody,
RunnerJobVODPayload,
TranscriptionSuccess,
VODHLSTranscodingSuccess,
VODWebVideoTranscodingSuccess
VODWebVideoTranscodingSuccess,
isHLSTranscodingPayloadSuccess,
isLiveRTMPHLSTranscodingUpdatePayload,
isTranscriptionPayloadSuccess,
isWebVideoOrAudioMergeTranscodingPayloadSuccess
} from '@peertube/peertube-models'
import { unwrapBody } from '../requests/index.js'
import { waitJobs } from '../server/jobs.js'
@ -196,6 +198,12 @@ export class RunnerJobsCommand extends AbstractCommand {
payloadWithoutFiles = omit(payloadWithoutFiles as VODHLSTranscodingSuccess, [ 'resolutionPlaylistFile' ])
}
if (isTranscriptionPayloadSuccess(payload) && payload.vttFile) {
attaches[`payload[vttFile]`] = payload.vttFile
payloadWithoutFiles = omit(payloadWithoutFiles as TranscriptionSuccess, [ 'vttFile' ])
}
return this.postUploadRequest({
...options,

View file

@ -355,6 +355,29 @@ export class ConfigCommand extends AbstractCommand {
// ---------------------------------------------------------------------------
enableTranscription ({ remote = false }: { remote?: boolean } = {}) {
return this.setTranscriptionEnabled(true, remote)
}
disableTranscription () {
return this.setTranscriptionEnabled(false, false)
}
private setTranscriptionEnabled (enabled: boolean, remoteEnabled: boolean) {
return this.updateExistingConfig({
newConfig: {
videoTranscription: {
enabled,
remoteRunners: {
enabled: remoteEnabled
}
}
}
})
}
// ---------------------------------------------------------------------------
getConfig (options: OverrideCommandOptions = {}) {
const path = '/api/v1/config'

View file

@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
import { isAbsolute } from 'path'
import { HttpStatusCode, HttpStatusCodeType } from '@peertube/peertube-models'
import { buildAbsoluteFixturePath, getFileSize } from '@peertube/peertube-node-utils'
import { expect } from 'chai'
import got, { Response as GotResponse } from 'got'
import { isAbsolute } from 'path'
import {
makeDeleteRequest,
makeGetRequest,
@ -11,12 +14,9 @@ import {
unwrapBody,
unwrapText
} from '../requests/requests.js'
import { expect } from 'chai'
import got, { Response as GotResponse } from 'got'
import { HttpStatusCode, HttpStatusCodeType } from '@peertube/peertube-models'
import type { PeerTubeServer } from '../server/server.js'
import { createReadStream } from 'fs'
import type { PeerTubeServer } from '../server/server.js'
export interface OverrideCommandOptions {
token?: string

View file

@ -1,3 +1,4 @@
import { pick } from '@peertube/peertube-core-utils'
import { HttpStatusCode, ResultList, VideoCaption } from '@peertube/peertube-models'
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
@ -32,6 +33,23 @@ export class CaptionsCommand extends AbstractCommand {
})
}
runGenerate (options: OverrideCommandOptions & {
videoId: string | number
forceTranscription?: boolean
}) {
const { videoId } = options
const path = '/api/v1/videos/' + videoId + '/captions/generate'
return this.postBodyRequest({
...options,
path,
fields: pick(options, [ 'forceTranscription' ]),
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
list (options: OverrideCommandOptions & {
videoId: string | number
videoPassword?: string

View file

@ -4,12 +4,19 @@ import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
export class VideoImportsCommand extends AbstractCommand {
importVideo (options: OverrideCommandOptions & {
attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string })
async importVideo (options: OverrideCommandOptions & {
attributes: (Partial<VideoImportCreate> | { torrentfile?: string, previewfile?: string, thumbnailfile?: string })
}) {
const { attributes } = options
const path = '/api/v1/videos/imports'
let defaultChannelId = 1
try {
const { videoChannels } = await this.server.users.getMyInfo({ token: options.token })
defaultChannelId = videoChannels[0].id
} catch (e) { /* empty */ }
let attaches: any = {}
if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile }
@ -20,7 +27,11 @@ export class VideoImportsCommand extends AbstractCommand {
path,
attaches,
fields: options.attributes,
fields: {
channelId: defaultChannelId,
...options.attributes
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))