1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { VideoDetails } from '../../../shared/video/video-details.model'
3 import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { AuthService, Notifier } from '@app/core'
6 import { VideoPrivacy } from '@shared/models'
9 selector: 'my-video-download',
10 templateUrl: './video-download.component.html',
11 styleUrls: [ './video-download.component.scss' ]
13 export class VideoDownloadComponent {
14 @ViewChild('modal', { static: true }) modal: ElementRef
16 downloadType: 'direct' | 'torrent' = 'torrent'
17 resolutionId: number | string = -1
20 activeModal: NgbActiveModal
23 private notifier: Notifier,
24 private modalService: NgbModal,
25 private auth: AuthService,
30 if (!this.video) return []
32 return this.video.getFiles()
35 show (video: VideoDetails) {
38 this.activeModal = this.modalService.open(this.modal)
40 this.resolutionId = this.getVideoFiles()[0].resolution.id
44 this.video = undefined
48 window.location.assign(this.getLink())
49 this.activeModal.close()
53 // HTML select send us a string, so convert it to a number
54 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
56 const file = this.getVideoFiles().find(f => f.resolution.id === this.resolutionId)
58 console.error('Could not find file with resolution %d.', this.resolutionId)
62 const suffix = this.video.privacy.id === VideoPrivacy.PRIVATE || this.video.privacy.id === VideoPrivacy.INTERNAL
63 ? '?access_token=' + this.auth.getAccessToken()
66 switch (this.downloadType) {
68 return file.fileDownloadUrl + suffix
71 return file.torrentDownloadUrl + suffix
75 activateCopiedMessage () {
76 this.notifier.success(this.i18n('Copied'))