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