Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Correctly handle transcription conflicts

Chocobozzz3a71086e3539
diff --git a/client/src/app/+admin/overview/videos/video-list.component.ts b/client/src/app/+admin/overview/videos/video-list.component.ts
index f7d88b752d..298bffd528 100644
--- a/client/src/app/+admin/overview/videos/video-list.component.ts
+++ b/client/src/app/+admin/overview/videos/video-list.component.ts
@@ -419,8 +419,36 @@ export class VideoListComponent extends RestTable <Video> implements OnInit {
private generateCaption (videos: Video[]) {
this.videoCaptionService.generateCaption(videos.map(v => v.id))
.subscribe({
- next: () => {
- this.notifier.success($localize`Transcription jobs created.`)
+ next: result => {
+ const messages: string[] = []
+
+ if (result.success) {
+ this.notifier.success(
+ formatICU(
+ $localize`{count, plural, =1 {1 transcription job created.} other {{count} transcription jobs created.}}`,
+ { count: result.success }
+ )
+ )
+ }
+
+ if (result.alreadyHasCaptions) {
+ this.notifier.info(
+ formatICU(
+ $localize`{count, plural, =1 {1 video already has captions.} other {{count} videos already have captions.}}`,
+ { count: result.alreadyHasCaptions }
+ )
+ )
+ }
+
+ if (result.alreadyBeingTranscribed) {
+ this.notifier.info(
+ formatICU(
+ // eslint-disable-next-line max-len
+ $localize`{count, plural, =1 {1 video is already being transcribed.} other {{count} videos are already being transcribed.}}`,
+ { count: result.alreadyBeingTranscribed }
+ )
+ )
+ }
},
error: err => this.notifier.error(err.message)
diff --git a/client/src/app/shared/shared-main/video-caption/video-caption.service.ts b/client/src/app/shared/shared-main/video-caption/video-caption.service.ts
index 4cd3105acb..0499165c12 100644
--- a/client/src/app/shared/shared-main/video-caption/video-caption.service.ts
+++ b/client/src/app/shared/shared-main/video-caption/video-caption.service.ts
@@ -3,8 +3,8 @@ import { Injectable } from '@angular/core'
import { RestExtractor, ServerService } from '@app/core'
import { objectToFormData } from '@app/helpers'
import { peertubeTranslate, sortBy } from '@peertube/peertube-core-utils'
-import { ResultList, VideoCaption } from '@peertube/peertube-models'
-import { Observable, from, of } from 'rxjs'
+import { PeerTubeProblemDocument, ResultList, ServerErrorCode, VideoCaption } from '@peertube/peertube-models'
+import { Observable, from, of, throwError } from 'rxjs'
import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
import { environment } from '../../../../environments/environment'
import { VideoPasswordService } from '../video/video-password.service'
@@ -78,8 +78,35 @@ export class VideoCaptionService {
generateCaption (videoIds: (number | string)[]) {
return from(videoIds)
.pipe(
- concatMap(videoId => this.authHttp.post(`${VideoService.BASE_VIDEO_URL}/${videoId}/captions/generate`, {})),
+ concatMap(videoId => {
+ return this.authHttp.post(`${VideoService.BASE_VIDEO_URL}/${videoId}/captions/generate`, {})
+ .pipe(
+ map(() => 'success' as 'success'),
+ catchError(err => {
+ const error: PeerTubeProblemDocument = err.error
+
+ if (error?.code === ServerErrorCode.VIDEO_ALREADY_HAS_CAPTIONS) {
+ return of('already-has-captions' as 'already-has-captions')
+ }
+
+ if (error?.code === ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCRIBED) {
+ return of('already-being-transcribed' as 'already-being-transcribed')
+ }
+
+ return throwError(() => err)
+ })
+ )
+ }),
toArray(),
+ map(data => {
+ return data.reduce((p, c) => {
+ if (c === 'success') p.success += 1
+ if (c === 'already-has-captions') p.alreadyHasCaptions += 1
+ if (c === 'already-being-transcribed') p.alreadyBeingTranscribed += 1
+
+ return p
+ }, { success: 0, alreadyHasCaptions: 0, alreadyBeingTranscribed: 0 })
+ }),
catchError(err => this.restExtractor.handleError(err))
)
}
diff --git a/packages/models/src/server/server-error-code.enum.ts b/packages/models/src/server/server-error-code.enum.ts
index 53811d55cf..74713c559f 100644
--- a/packages/models/src/server/server-error-code.enum.ts
+++ b/packages/models/src/server/server-error-code.enum.ts
@@ -56,6 +56,7 @@ export const ServerErrorCode = {
VIDEO_ALREADY_BEING_TRANSCODED: 'video_already_being_transcoded',
VIDEO_ALREADY_BEING_TRANSCRIBED: 'video_already_being_transcribed',
+ VIDEO_ALREADY_HAS_CAPTIONS: 'video_already_has_captions',
MAX_USER_VIDEO_QUOTA_EXCEEDED_FOR_USER_EXPORT: 'max_user_video_quota_exceeded_for_user_export'
} as const
diff --git a/server/core/middlewares/validators/videos/video-captions.ts b/server/core/middlewares/validators/videos/video-captions.ts
index 74ad1e8aa7..0f8af23726 100644
--- a/server/core/middlewares/validators/videos/video-captions.ts
+++ b/server/core/middlewares/validators/videos/video-captions.ts
@@ -83,6 +83,7 @@ export const generateVideoCaptionValidator = [
if (captions.length !== 0) {
return res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
+ type: ServerErrorCode.VIDEO_ALREADY_HAS_CAPTIONS,
message: 'This video already has captions'
})
}