1
0
Fork 0
peertube/client/src/app/videos/+video-watch/video-download.component.ts

45 lines
1 KiB
TypeScript
Raw Normal View History

2017-12-20 11:49:58 -05:00
import { Component, Input, OnInit, ViewChild } from '@angular/core'
import { ModalDirective } from 'ngx-bootstrap/modal'
2017-12-01 12:56:26 -05:00
import { VideoDetails } from '../../shared/video/video-details.model'
@Component({
selector: 'my-video-download',
templateUrl: './video-download.component.html',
2017-12-07 04:27:33 -05:00
styleUrls: [ './video-download.component.scss' ]
})
2017-12-20 11:49:58 -05:00
export class VideoDownloadComponent implements OnInit {
2017-10-25 10:43:19 -04:00
@Input() video: VideoDetails = null
@ViewChild('modal') modal: ModalDirective
2017-12-20 11:49:58 -05:00
downloadType: 'direct' | 'torrent' = 'torrent'
resolution = -1
constructor () {
// empty
}
2017-12-20 11:49:58 -05:00
ngOnInit () {
this.resolution = this.video.files[0].resolution
}
show () {
this.modal.show()
}
hide () {
this.modal.hide()
}
2017-12-20 11:49:58 -05:00
download () {
const file = this.video.files.find(f => f.resolution === this.resolution)
if (!file) {
console.error('Could not find file with resolution %d.', this.resolution)
return
}
const link = this.downloadType === 'direct' ? file.fileUrl : file.torrentUrl
window.open(link)
}
}