]>
Commit | Line | Data |
---|---|---|
5f0805d3 | 1 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
df98563e | 2 | import { ModalDirective } from 'ngx-bootstrap/modal' |
4635f59d | 3 | import { VideoDetails } from '../../../shared/video/video-details.model' |
cf02fbfb C |
4 | |
5 | @Component({ | |
a96aed15 C |
6 | selector: 'my-video-download', |
7 | templateUrl: './video-download.component.html', | |
0727cab0 | 8 | styleUrls: [ './video-download.component.scss' ] |
cf02fbfb | 9 | }) |
5f0805d3 | 10 | export class VideoDownloadComponent implements OnInit { |
404b54e1 | 11 | @Input() video: VideoDetails = null |
cf02fbfb | 12 | |
df98563e | 13 | @ViewChild('modal') modal: ModalDirective |
cf02fbfb | 14 | |
5511da62 | 15 | downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent' |
09700934 | 16 | resolutionId: number | string = -1 |
5f0805d3 | 17 | |
df98563e | 18 | constructor () { |
cf02fbfb C |
19 | // empty |
20 | } | |
21 | ||
5f0805d3 | 22 | ngOnInit () { |
09700934 | 23 | this.resolutionId = this.video.files[0].resolution.id |
5f0805d3 C |
24 | } |
25 | ||
df98563e C |
26 | show () { |
27 | this.modal.show() | |
cf02fbfb C |
28 | } |
29 | ||
df98563e C |
30 | hide () { |
31 | this.modal.hide() | |
cf02fbfb | 32 | } |
5f0805d3 C |
33 | |
34 | download () { | |
00336945 | 35 | // HTML select send us a string, so convert it to a number |
09700934 | 36 | this.resolutionId = parseInt(this.resolutionId.toString(), 10) |
00336945 | 37 | |
09700934 | 38 | const file = this.video.files.find(f => f.resolution.id === this.resolutionId) |
5f0805d3 | 39 | if (!file) { |
09700934 | 40 | console.error('Could not find file with resolution %d.', this.resolutionId) |
5f0805d3 C |
41 | return |
42 | } | |
43 | ||
5511da62 RK |
44 | const link = (() => { |
45 | switch (this.downloadType) { | |
46 | case 'direct': { | |
47 | return file.fileDownloadUrl | |
48 | } | |
49 | case 'torrent': { | |
50 | return file.torrentDownloadUrl | |
51 | } | |
52 | case 'magnet': { | |
53 | return file.magnetUri | |
54 | } | |
55 | } | |
56 | })() | |
02756fbd | 57 | window.location.assign(link) |
5f0805d3 | 58 | } |
cf02fbfb | 59 | } |