1 import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'
2 import { VideoDetails } from '../../../shared/video/video-details.model'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { NotificationsService } from 'angular2-notifications'
8 selector: 'my-video-download',
9 templateUrl: './video-download.component.html',
10 styleUrls: [ './video-download.component.scss' ]
12 export class VideoDownloadComponent implements OnInit {
13 @Input() video: VideoDetails = null
15 @ViewChild('modal') modal: ElementRef
17 downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
18 resolutionId: number | string = -1
21 private notificationsService: NotificationsService,
22 private modalService: NgbModal,
27 this.resolutionId = this.video.files[0].resolution.id
31 this.modalService.open(this.modal)
35 window.location.assign(this.getLink())
39 // HTML select send us a string, so convert it to a number
40 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
42 const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
44 console.error('Could not find file with resolution %d.', this.resolutionId)
49 switch (this.downloadType) {
51 return file.fileDownloadUrl
54 return file.torrentDownloadUrl
65 activateCopiedMessage () {
66 this.notificationsService.success(this.i18n('Success'), this.i18n('Copied'))