ActivityPub-federated video streaming platform using P2P directly in your web browser
Add ability to force transcription
Chocobozzz5ab681802bc0
diff --git a/client/src/app/+admin/overview/videos/video-list.component.ts b/client/src/app/+admin/overview/videos/video-list.component.tsindex 896f3e0e12..98f56af20d 100644--- a/client/src/app/+admin/overview/videos/video-list.component.ts+++ b/client/src/app/+admin/overview/videos/video-list.component.ts@@ -417,7 +417,7 @@ export class VideoListComponent extends RestTable <Video> implements OnInit {}private generateCaption (videos: Video[]) {- this.videoCaptionService.generateCaption(videos.map(v => v.id))+ this.videoCaptionService.generateCaption({ videos }).subscribe({next: result => {if (result.success) {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.tsindex 0499165c12..210b73d9c1 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@@ -1,9 +1,9 @@import { HttpClient } from '@angular/common/http'import { Injectable } from '@angular/core'-import { RestExtractor, ServerService } from '@app/core'+import { ConfirmService, RestExtractor, ServerService } from '@app/core'import { objectToFormData } from '@app/helpers'import { peertubeTranslate, sortBy } from '@peertube/peertube-core-utils'-import { PeerTubeProblemDocument, ResultList, ServerErrorCode, VideoCaption } from '@peertube/peertube-models'+import { PeerTubeProblemDocument, ResultList, ServerErrorCode, Video, VideoCaption, VideoCaptionGenerate } 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'@@ -16,7 +16,8 @@ export class VideoCaptionService {constructor (private authHttp: HttpClient,private serverService: ServerService,- private restExtractor: RestExtractor+ private restExtractor: RestExtractor,+ private confirmService: ConfirmService) {}listCaptions (videoId: string, videoPassword?: string): Observable<ResultList<VideoCaption>> {@@ -75,28 +76,16 @@ export class VideoCaptionService {return this.authHttp.get(environment.originServerUrl + captionPath, { responseType: 'text' })}- generateCaption (videoIds: (number | string)[]) {- return from(videoIds)+ // ---------------------------------------------------------------------------++ generateCaption (options: {+ videos: Video[]+ }): Observable<{ success: number, alreadyHasCaptions: number, alreadyBeingTranscribed: number }> {+ const { videos } = options++ return from(videos).pipe(- 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)- })- )- }),+ concatMap(video => this.generateCaptionOfSpecificVideo({ video, forceTranscription: false })),toArray(),map(data => {return data.reduce((p, c) => {@@ -110,4 +99,47 @@ export class VideoCaptionService {catchError(err => this.restExtractor.handleError(err)))}++ private generateCaptionOfSpecificVideo (options: {+ video: Video+ forceTranscription: boolean+ }): Observable<'success' | 'already-has-captions' | 'already-being-transcribed'> {+ const { video, forceTranscription } = options++ const body: VideoCaptionGenerate = { forceTranscription }++ return this.authHttp.post(`${VideoService.BASE_VIDEO_URL}/${video.id}/captions/generate`, body)+ .pipe(+ map(() => 'success' as 'success'),+ catchError(err => {+ const error: PeerTubeProblemDocument = err.error++ if (error?.code === ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCRIBED && !forceTranscription) {+ const message = $localize`PeerTube considers video "${video.name}" is already being transcripted.` ++ // eslint-disable-next-line max-len+ $localize` If you think PeerTube is wrong (video in broken state after a crash etc.), you can force transcription on this video.` ++ ` Do you still want to run transcription?`++ return from(this.confirmService.confirm(message, $localize`Force transcription`))+ .pipe(+ switchMap(res => {+ if (res === false) return throwError(() => err)++ return this.generateCaptionOfSpecificVideo({ video, forceTranscription: true })+ })+ )+ }++ 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)+ })+ )+ }}diff --git a/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts b/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.tsindex bed2538b6b..d5249e13b8 100644--- a/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts+++ b/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts@@ -354,7 +354,7 @@ export class VideoActionsDropdownComponent implements OnChanges {}generateCaption (video: Video) {- this.videoCaptionService.generateCaption([ video.id ])+ this.videoCaptionService.generateCaption({ videos: [ video ] }).subscribe({next: result => {if (result.success) this.notifier.success($localize`Transcription job created for "${video.name}".`)