aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video-caption
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video-caption')
-rw-r--r--client/src/app/shared/video-caption/video-caption.service.ts27
1 files changed, 21 insertions, 6 deletions
diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts
index 9c29bc052..994882451 100644
--- a/client/src/app/shared/video-caption/video-caption.service.ts
+++ b/client/src/app/shared/video-caption/video-caption.service.ts
@@ -1,29 +1,44 @@
1import { catchError, map } from 'rxjs/operators' 1import { catchError, map, switchMap } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http' 2import { HttpClient } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { forkJoin, Observable, of } from 'rxjs' 4import { forkJoin, Observable, of } from 'rxjs'
5import { ResultList } from '../../../../../shared' 5import { peertubeTranslate, ResultList } from '../../../../../shared'
6import { RestExtractor, RestService } from '../rest' 6import { RestExtractor, RestService } from '../rest'
7import { VideoService } from '@app/shared/video/video.service' 7import { VideoService } from '@app/shared/video/video.service'
8import { objectToFormData, sortBy } from '@app/shared/misc/utils' 8import { objectToFormData, sortBy } from '@app/shared/misc/utils'
9import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' 9import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
10import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model' 10import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model'
11import { ServerService } from '@app/core'
11 12
12@Injectable() 13@Injectable()
13export class VideoCaptionService { 14export class VideoCaptionService {
14 constructor ( 15 constructor (
15 private authHttp: HttpClient, 16 private authHttp: HttpClient,
17 private serverService: ServerService,
16 private restService: RestService, 18 private restService: RestService,
17 private restExtractor: RestExtractor 19 private restExtractor: RestExtractor
18 ) {} 20 ) {}
19 21
20 listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { 22 listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> {
21 return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') 23 return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions')
22 .pipe(map(res => { 24 .pipe(
23 sortBy(res.data, 'language', 'label') 25 switchMap(captionsResult => {
26 return this.serverService.localeObservable
27 .pipe(map(translations => ({ captionsResult, translations })))
28 }),
29 map(({ captionsResult, translations }) => {
30 for (const c of captionsResult.data) {
31 c.language.label = peertubeTranslate(c.language.label, translations)
32 }
33
34 return captionsResult
35 }),
36 map(captionsResult => {
37 sortBy(captionsResult.data, 'language', 'label')
24 38
25 return res 39 return captionsResult
26 })) 40 })
41 )
27 .pipe(catchError(res => this.restExtractor.handleError(res))) 42 .pipe(catchError(res => this.restExtractor.handleError(res)))
28 } 43 }
29 44