]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/modals/video-download.component.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / modals / video-download.component.ts
CommitLineData
3a0fb65c 1import { Component, ElementRef, ViewChild } from '@angular/core'
4635f59d 2import { VideoDetails } from '../../../shared/video/video-details.model'
11b3f14c 3import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'
bb5d7428 4import { I18n } from '@ngx-translate/i18n-polyfill'
f8b2c1b4 5import { Notifier } from '@app/core'
cf02fbfb
C
6
7@Component({
a96aed15
C
8 selector: 'my-video-download',
9 templateUrl: './video-download.component.html',
0727cab0 10 styleUrls: [ './video-download.component.scss' ]
cf02fbfb 11})
3a0fb65c 12export class VideoDownloadComponent {
63347a0f 13 @ViewChild('modal') modal: ElementRef
cf02fbfb 14
5511da62 15 downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
09700934 16 resolutionId: number | string = -1
5f0805d3 17
8dfceec4 18 video: VideoDetails
11b3f14c 19 activeModal: NgbActiveModal
3a0fb65c 20
bb5d7428 21 constructor (
f8b2c1b4 22 private notifier: Notifier,
bb5d7428
RK
23 private modalService: NgbModal,
24 private i18n: I18n
25 ) { }
cf02fbfb 26
3a0fb65c
C
27 show (video: VideoDetails) {
28 this.video = video
29
11b3f14c 30 this.activeModal = this.modalService.open(this.modal)
3a0fb65c 31
09700934 32 this.resolutionId = this.video.files[0].resolution.id
5f0805d3
C
33 }
34
3a0fb65c
C
35 onClose () {
36 this.video = undefined
cf02fbfb 37 }
5f0805d3
C
38
39 download () {
bb5d7428 40 window.location.assign(this.getLink())
11b3f14c 41 this.activeModal.close()
bb5d7428
RK
42 }
43
44 getLink () {
00336945 45 // HTML select send us a string, so convert it to a number
09700934 46 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
00336945 47
09700934 48 const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
5f0805d3 49 if (!file) {
09700934 50 console.error('Could not find file with resolution %d.', this.resolutionId)
5f0805d3
C
51 return
52 }
53
3a0fb65c
C
54 switch (this.downloadType) {
55 case 'direct':
56 return file.fileDownloadUrl
57
58 case 'torrent':
59 return file.torrentDownloadUrl
bb5d7428 60
3a0fb65c
C
61 case 'magnet':
62 return file.magnetUri
63 }
bb5d7428
RK
64 }
65
66 activateCopiedMessage () {
f8b2c1b4 67 this.notifier.success(this.i18n('Copied'))
5f0805d3 68 }
cf02fbfb 69}