From 3a0fb65c61f80b510bce979a45d59d17948745e8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Apr 2019 10:52:27 +0200 Subject: Add video miniature dropdown --- .../video/modals/video-download.component.ts | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 client/src/app/shared/video/modals/video-download.component.ts (limited to 'client/src/app/shared/video/modals/video-download.component.ts') diff --git a/client/src/app/shared/video/modals/video-download.component.ts b/client/src/app/shared/video/modals/video-download.component.ts new file mode 100644 index 000000000..64aaeb3c8 --- /dev/null +++ b/client/src/app/shared/video/modals/video-download.component.ts @@ -0,0 +1,69 @@ +import { Component, ElementRef, ViewChild } from '@angular/core' +import { VideoDetails } from '../../../shared/video/video-details.model' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { Notifier } from '@app/core' + +@Component({ + selector: 'my-video-download', + templateUrl: './video-download.component.html', + styleUrls: [ './video-download.component.scss' ] +}) +export class VideoDownloadComponent { + @ViewChild('modal') modal: ElementRef + + downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent' + resolutionId: number | string = -1 + + private video: VideoDetails + + constructor ( + private notifier: Notifier, + private modalService: NgbModal, + private i18n: I18n + ) { } + + show (video: VideoDetails) { + this.video = video + + const m = this.modalService.open(this.modal) + m.result.then(() => this.onClose()) + .catch(() => this.onClose()) + + this.resolutionId = this.video.files[0].resolution.id + } + + onClose () { + this.video = undefined + } + + download () { + window.location.assign(this.getLink()) + } + + getLink () { + // HTML select send us a string, so convert it to a number + this.resolutionId = parseInt(this.resolutionId.toString(), 10) + + const file = this.video.files.find(f => f.resolution.id === this.resolutionId) + if (!file) { + console.error('Could not find file with resolution %d.', this.resolutionId) + return + } + + switch (this.downloadType) { + case 'direct': + return file.fileDownloadUrl + + case 'torrent': + return file.torrentDownloadUrl + + case 'magnet': + return file.magnetUri + } + } + + activateCopiedMessage () { + this.notifier.success(this.i18n('Copied')) + } +} -- cgit v1.2.3