aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/modals/video-download.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-01-07 16:53:57 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-01-07 17:09:21 +0100
commit8ba9c205ba239fed18741bed36ad2fb2032cd5b2 (patch)
treefd695eb21a2802e1d4afc6ffd19de75e83910c80 /client/src/app/shared/video/modals/video-download.component.ts
parent9b7668f527fce8981f4684ed0459b62e740b4b82 (diff)
downloadPeerTube-8ba9c205ba239fed18741bed36ad2fb2032cd5b2.tar.gz
PeerTube-8ba9c205ba239fed18741bed36ad2fb2032cd5b2.tar.zst
PeerTube-8ba9c205ba239fed18741bed36ad2fb2032cd5b2.zip
Add option to download subtitles in download modal
Diffstat (limited to 'client/src/app/shared/video/modals/video-download.component.ts')
-rw-r--r--client/src/app/shared/video/modals/video-download.component.ts33
1 files changed, 31 insertions, 2 deletions
diff --git a/client/src/app/shared/video/modals/video-download.component.ts b/client/src/app/shared/video/modals/video-download.component.ts
index 712740086..c1ceca263 100644
--- a/client/src/app/shared/video/modals/video-download.component.ts
+++ b/client/src/app/shared/video/modals/video-download.component.ts
@@ -3,7 +3,9 @@ import { VideoDetails } from '../../../shared/video/video-details.model'
3import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap' 3import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'
4import { I18n } from '@ngx-translate/i18n-polyfill' 4import { I18n } from '@ngx-translate/i18n-polyfill'
5import { AuthService, Notifier } from '@app/core' 5import { AuthService, Notifier } from '@app/core'
6import { VideoPrivacy } from '@shared/models' 6import { VideoPrivacy, VideoCaption } from '@shared/models'
7
8type DownloadType = 'video' | 'subtitles'
7 9
8@Component({ 10@Component({
9 selector: 'my-video-download', 11 selector: 'my-video-download',
@@ -15,10 +17,14 @@ export class VideoDownloadComponent {
15 17
16 downloadType: 'direct' | 'torrent' = 'torrent' 18 downloadType: 'direct' | 'torrent' = 'torrent'
17 resolutionId: number | string = -1 19 resolutionId: number | string = -1
20 subtitleLanguageId: string
18 21
19 video: VideoDetails 22 video: VideoDetails
23 videoCaptions: VideoCaption[]
20 activeModal: NgbActiveModal 24 activeModal: NgbActiveModal
21 25
26 type: DownloadType = 'video'
27
22 constructor ( 28 constructor (
23 private notifier: Notifier, 29 private notifier: Notifier,
24 private modalService: NgbModal, 30 private modalService: NgbModal,
@@ -26,22 +32,31 @@ export class VideoDownloadComponent {
26 private i18n: I18n 32 private i18n: I18n
27 ) { } 33 ) { }
28 34
35 get typeText () {
36 return this.type === 'video'
37 ? this.i18n('video')
38 : this.i18n('subtitles')
39 }
40
29 getVideoFiles () { 41 getVideoFiles () {
30 if (!this.video) return [] 42 if (!this.video) return []
31 43
32 return this.video.getFiles() 44 return this.video.getFiles()
33 } 45 }
34 46
35 show (video: VideoDetails) { 47 show (video: VideoDetails, videoCaptions?: VideoCaption[]) {
36 this.video = video 48 this.video = video
49 this.videoCaptions = videoCaptions && videoCaptions.length ? videoCaptions : undefined
37 50
38 this.activeModal = this.modalService.open(this.modal) 51 this.activeModal = this.modalService.open(this.modal)
39 52
40 this.resolutionId = this.getVideoFiles()[0].resolution.id 53 this.resolutionId = this.getVideoFiles()[0].resolution.id
54 if (this.videoCaptions) this.subtitleLanguageId = this.videoCaptions[0].language.id
41 } 55 }
42 56
43 onClose () { 57 onClose () {
44 this.video = undefined 58 this.video = undefined
59 this.videoCaptions = undefined
45 } 60 }
46 61
47 download () { 62 download () {
@@ -50,6 +65,12 @@ export class VideoDownloadComponent {
50 } 65 }
51 66
52 getLink () { 67 getLink () {
68 return this.type === 'subtitles' && this.videoCaptions
69 ? this.getSubtitlesLink()
70 : this.getVideoLink()
71 }
72
73 getVideoLink () {
53 // HTML select send us a string, so convert it to a number 74 // HTML select send us a string, so convert it to a number
54 this.resolutionId = parseInt(this.resolutionId.toString(), 10) 75 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
55 76
@@ -72,7 +93,15 @@ export class VideoDownloadComponent {
72 } 93 }
73 } 94 }
74 95
96 getSubtitlesLink () {
97 return window.location.origin + this.videoCaptions.find(caption => caption.language.id === this.subtitleLanguageId).captionPath
98 }
99
75 activateCopiedMessage () { 100 activateCopiedMessage () {
76 this.notifier.success(this.i18n('Copied')) 101 this.notifier.success(this.i18n('Copied'))
77 } 102 }
103
104 switchToType (type: DownloadType) {
105 this.type = type
106 }
78} 107}