2017-12-20 16:49:58 +00:00
|
|
|
import { Component, Input, OnInit, ViewChild } from '@angular/core'
|
2017-06-16 12:32:15 +00:00
|
|
|
import { ModalDirective } from 'ngx-bootstrap/modal'
|
2017-12-27 15:11:53 +00:00
|
|
|
import { VideoDetails } from '../../../shared/video/video-details.model'
|
2016-11-20 15:09:38 +00:00
|
|
|
|
|
|
|
@Component({
|
2017-10-19 12:58:28 +00:00
|
|
|
selector: 'my-video-download',
|
|
|
|
templateUrl: './video-download.component.html',
|
2017-12-07 09:27:33 +00:00
|
|
|
styleUrls: [ './video-download.component.scss' ]
|
2016-11-20 15:09:38 +00:00
|
|
|
})
|
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
|
2016-11-20 15:09:38 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
@ViewChild('modal') modal: ModalDirective
|
2016-11-20 15:09:38 +00:00
|
|
|
|
2017-12-20 16:49:58 +00:00
|
|
|
downloadType: 'direct' | 'torrent' = 'torrent'
|
2018-02-07 10:05:59 +00:00
|
|
|
resolution: number | string = -1
|
2017-12-20 16:49:58 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
constructor () {
|
2016-11-20 15:09:38 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:49:58 +00:00
|
|
|
ngOnInit () {
|
|
|
|
this.resolution = this.video.files[0].resolution
|
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
show () {
|
|
|
|
this.modal.show()
|
2016-11-20 15:09:38 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
hide () {
|
|
|
|
this.modal.hide()
|
2016-11-20 15:09:38 +00:00
|
|
|
}
|
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.resolution = parseInt(this.resolution.toString(), 10)
|
|
|
|
|
2017-12-20 16:49:58 +00:00
|
|
|
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)
|
|
|
|
}
|
2016-11-20 15:09:38 +00:00
|
|
|
}
|