diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-12 19:02:00 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-16 11:50:08 +0200 |
commit | 40e87e9ecc54e3513fb586928330a7855eb192c6 (patch) | |
tree | af1111ecba85f9cd8286811ff332a67cf21be2f6 /client/src/app/shared/video-caption | |
parent | d4557fd3ecc8d4ed4fb0e5c868929bc36c959ed2 (diff) | |
download | PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.gz PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.zst PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.zip |
Implement captions/subtitles
Diffstat (limited to 'client/src/app/shared/video-caption')
3 files changed, 71 insertions, 0 deletions
diff --git a/client/src/app/shared/video-caption/index.ts b/client/src/app/shared/video-caption/index.ts new file mode 100644 index 000000000..c48a70558 --- /dev/null +++ b/client/src/app/shared/video-caption/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './video-caption.service' | |||
diff --git a/client/src/app/shared/video-caption/video-caption-edit.model.ts b/client/src/app/shared/video-caption/video-caption-edit.model.ts new file mode 100644 index 000000000..732f20158 --- /dev/null +++ b/client/src/app/shared/video-caption/video-caption-edit.model.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | export interface VideoCaptionEdit { | ||
2 | language: { | ||
3 | id: string | ||
4 | label?: string | ||
5 | } | ||
6 | |||
7 | action?: 'CREATE' | 'REMOVE' | ||
8 | captionfile?: any | ||
9 | } | ||
diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts new file mode 100644 index 000000000..4ae8ebd0a --- /dev/null +++ b/client/src/app/shared/video-caption/video-caption.service.ts | |||
@@ -0,0 +1,61 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | ||
2 | import { HttpClient } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { forkJoin, Observable } from 'rxjs' | ||
5 | import { ResultList } from '../../../../../shared' | ||
6 | import { RestExtractor, RestService } from '../rest' | ||
7 | import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model' | ||
8 | import { VideoService } from '@app/shared/video/video.service' | ||
9 | import { objectToFormData } from '@app/shared/misc/utils' | ||
10 | import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' | ||
11 | |||
12 | @Injectable() | ||
13 | export class VideoCaptionService { | ||
14 | constructor ( | ||
15 | private authHttp: HttpClient, | ||
16 | private restService: RestService, | ||
17 | private restExtractor: RestExtractor | ||
18 | ) {} | ||
19 | |||
20 | listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { | ||
21 | return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') | ||
22 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
23 | } | ||
24 | |||
25 | removeCaption (videoId: number | string, language: string) { | ||
26 | return this.authHttp.delete(VideoService.BASE_VIDEO_URL + videoId + '/captions/' + language) | ||
27 | .pipe( | ||
28 | map(this.restExtractor.extractDataBool), | ||
29 | catchError(res => this.restExtractor.handleError(res)) | ||
30 | ) | ||
31 | } | ||
32 | |||
33 | addCaption (videoId: number | string, language: string, captionfile: File) { | ||
34 | const body = { captionfile } | ||
35 | const data = objectToFormData(body) | ||
36 | |||
37 | return this.authHttp.put(VideoService.BASE_VIDEO_URL + videoId + '/captions/' + language, data) | ||
38 | .pipe( | ||
39 | map(this.restExtractor.extractDataBool), | ||
40 | catchError(res => this.restExtractor.handleError(res)) | ||
41 | ) | ||
42 | } | ||
43 | |||
44 | updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) { | ||
45 | const observables: Observable<any>[] = [] | ||
46 | |||
47 | for (const videoCaption of videoCaptions) { | ||
48 | if (videoCaption.action === 'CREATE') { | ||
49 | observables.push( | ||
50 | this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile) | ||
51 | ) | ||
52 | } else if (videoCaption.action === 'REMOVE') { | ||
53 | observables.push( | ||
54 | this.removeCaption(videoId, videoCaption.language.id) | ||
55 | ) | ||
56 | } | ||
57 | } | ||
58 | |||
59 | return forkJoin(observables) | ||
60 | } | ||
61 | } | ||