2019-04-05 04:52:27 -04:00
|
|
|
import { Component, ElementRef, ViewChild } from '@angular/core'
|
2017-12-27 10:11:53 -05:00
|
|
|
import { VideoDetails } from '../../../shared/video/video-details.model'
|
2018-08-09 08:55:06 -04:00
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
2018-09-23 13:43:41 -04:00
|
|
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
2018-12-19 10:04:34 -05:00
|
|
|
import { Notifier } from '@app/core'
|
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
|
|
|
})
|
2019-04-05 04:52:27 -04:00
|
|
|
export class VideoDownloadComponent {
|
2018-08-09 08:55:06 -04:00
|
|
|
@ViewChild('modal') modal: ElementRef
|
2016-11-20 10:09:38 -05:00
|
|
|
|
2018-06-22 10:29:01 -04:00
|
|
|
downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
|
2018-03-19 06:04:40 -04:00
|
|
|
resolutionId: number | string = -1
|
2017-12-20 11:49:58 -05:00
|
|
|
|
2019-04-05 04:52:27 -04:00
|
|
|
private video: VideoDetails
|
|
|
|
|
2018-09-23 13:43:41 -04:00
|
|
|
constructor (
|
2018-12-19 10:04:34 -05:00
|
|
|
private notifier: Notifier,
|
2018-09-23 13:43:41 -04:00
|
|
|
private modalService: NgbModal,
|
|
|
|
private i18n: I18n
|
|
|
|
) { }
|
2016-11-20 10:09:38 -05:00
|
|
|
|
2019-04-05 04:52:27 -04:00
|
|
|
show (video: VideoDetails) {
|
|
|
|
this.video = video
|
|
|
|
|
|
|
|
const m = this.modalService.open(this.modal)
|
|
|
|
m.result.then(() => this.onClose())
|
|
|
|
.catch(() => this.onClose())
|
|
|
|
|
2018-03-19 06:04:40 -04:00
|
|
|
this.resolutionId = this.video.files[0].resolution.id
|
2017-12-20 11:49:58 -05:00
|
|
|
}
|
|
|
|
|
2019-04-05 04:52:27 -04:00
|
|
|
onClose () {
|
|
|
|
this.video = undefined
|
2016-11-20 10:09:38 -05:00
|
|
|
}
|
2017-12-20 11:49:58 -05:00
|
|
|
|
|
|
|
download () {
|
2018-09-23 13:43:41 -04:00
|
|
|
window.location.assign(this.getLink())
|
|
|
|
}
|
|
|
|
|
|
|
|
getLink () {
|
2018-02-07 05:05:59 -05:00
|
|
|
// HTML select send us a string, so convert it to a number
|
2018-03-19 06:04:40 -04:00
|
|
|
this.resolutionId = parseInt(this.resolutionId.toString(), 10)
|
2018-02-07 05:05:59 -05:00
|
|
|
|
2018-03-19 06:04:40 -04:00
|
|
|
const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
|
2017-12-20 11:49:58 -05:00
|
|
|
if (!file) {
|
2018-03-19 06:04:40 -04:00
|
|
|
console.error('Could not find file with resolution %d.', this.resolutionId)
|
2017-12-20 11:49:58 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-05 04:52:27 -04:00
|
|
|
switch (this.downloadType) {
|
|
|
|
case 'direct':
|
|
|
|
return file.fileDownloadUrl
|
|
|
|
|
|
|
|
case 'torrent':
|
|
|
|
return file.torrentDownloadUrl
|
2018-09-23 13:43:41 -04:00
|
|
|
|
2019-04-05 04:52:27 -04:00
|
|
|
case 'magnet':
|
|
|
|
return file.magnetUri
|
|
|
|
}
|
2018-09-23 13:43:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
activateCopiedMessage () {
|
2018-12-19 10:04:34 -05:00
|
|
|
this.notifier.success(this.i18n('Copied'))
|
2017-12-20 11:49:58 -05:00
|
|
|
}
|
2016-11-20 10:09:38 -05:00
|
|
|
}
|