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'
6 selector: 'my-video-download',
7 templateUrl: './video-download.component.html',
8 styleUrls: [ './video-download.component.scss' ]
10 export class VideoDownloadComponent implements OnInit {
11 @Input() video: VideoDetails = null
13 @ViewChild('modal') modal: ElementRef
15 downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
16 resolutionId: number | string = -1
18 constructor (private modalService: NgbModal) {
23 this.resolutionId = this.video.files[0].resolution.id
27 this.modalService.open(this.modal)
31 // HTML select send us a string, so convert it to a number
32 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
34 const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
36 console.error('Could not find file with resolution %d.', this.resolutionId)
41 switch (this.downloadType) {
43 return file.fileDownloadUrl
46 return file.torrentDownloadUrl
53 window.location.assign(link)