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

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-12-20 16:49:58 +00:00
import { Component, Input, OnInit, ViewChild } from '@angular/core'
import { ModalDirective } from 'ngx-bootstrap/modal'
2017-12-27 15:11:53 +00:00
import { VideoDetails } from '../../../shared/video/video-details.model'
@Component({
selector: 'my-video-download',
templateUrl: './video-download.component.html',
2017-12-07 09:27:33 +00:00
styleUrls: [ './video-download.component.scss' ]
})
2017-12-20 16:49:58 +00:00
export class VideoDownloadComponent implements OnInit {
2017-10-25 14:43:19 +00:00
@Input() video: VideoDetails = null
@ViewChild('modal') modal: ModalDirective
2017-12-20 16:49:58 +00:00
downloadType: 'direct' | 'torrent' = 'torrent'
resolutionId: number | string = -1
2017-12-20 16:49:58 +00:00
constructor () {
// empty
}
2017-12-20 16:49:58 +00:00
ngOnInit () {
this.resolutionId = this.video.files[0].resolution.id
2017-12-20 16:49:58 +00:00
}
show () {
this.modal.show()
}
hide () {
this.modal.hide()
}
2017-12-20 16:49:58 +00:00
download () {
2018-02-07 10:05:59 +00:00
// HTML select send us a string, so convert it to a number
this.resolutionId = parseInt(this.resolutionId.toString(), 10)
2018-02-07 10:05:59 +00:00
const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
2017-12-20 16:49:58 +00:00
if (!file) {
console.error('Could not find file with resolution %d.', this.resolutionId)
2017-12-20 16:49:58 +00:00
return
}
2018-05-29 16:30:11 +00:00
const link = this.downloadType === 'direct' ? file.fileDownloadUrl : file.torrentDownloadUrl
window.location.assign(link)
2017-12-20 16:49:58 +00:00
}
}