diff options
Diffstat (limited to 'client/src/app/videos/+video-watch/modal/video-download.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/modal/video-download.component.ts | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/client/src/app/videos/+video-watch/modal/video-download.component.ts b/client/src/app/videos/+video-watch/modal/video-download.component.ts deleted file mode 100644 index 834385771..000000000 --- a/client/src/app/videos/+video-watch/modal/video-download.component.ts +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
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 { Notifier } from '@app/core' | ||
6 | |||
7 | @Component({ | ||
8 | selector: 'my-video-download', | ||
9 | templateUrl: './video-download.component.html', | ||
10 | styleUrls: [ './video-download.component.scss' ] | ||
11 | }) | ||
12 | export class VideoDownloadComponent implements OnInit { | ||
13 | @Input() video: VideoDetails = null | ||
14 | |||
15 | @ViewChild('modal') modal: ElementRef | ||
16 | |||
17 | downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent' | ||
18 | resolutionId: number | string = -1 | ||
19 | |||
20 | constructor ( | ||
21 | private notifier: Notifier, | ||
22 | private modalService: NgbModal, | ||
23 | private i18n: I18n | ||
24 | ) { } | ||
25 | |||
26 | ngOnInit () { | ||
27 | this.resolutionId = this.video.files[0].resolution.id | ||
28 | } | ||
29 | |||
30 | show () { | ||
31 | this.modalService.open(this.modal) | ||
32 | } | ||
33 | |||
34 | download () { | ||
35 | window.location.assign(this.getLink()) | ||
36 | } | ||
37 | |||
38 | getLink () { | ||
39 | // HTML select send us a string, so convert it to a number | ||
40 | this.resolutionId = parseInt(this.resolutionId.toString(), 10) | ||
41 | |||
42 | const file = this.video.files.find(f => f.resolution.id === this.resolutionId) | ||
43 | if (!file) { | ||
44 | console.error('Could not find file with resolution %d.', this.resolutionId) | ||
45 | return | ||
46 | } | ||
47 | |||
48 | const link = (() => { | ||
49 | switch (this.downloadType) { | ||
50 | case 'direct': { | ||
51 | return file.fileDownloadUrl | ||
52 | } | ||
53 | case 'torrent': { | ||
54 | return file.torrentDownloadUrl | ||
55 | } | ||
56 | case 'magnet': { | ||
57 | return file.magnetUri | ||
58 | } | ||
59 | } | ||
60 | })() | ||
61 | |||
62 | return link | ||
63 | } | ||
64 | |||
65 | activateCopiedMessage () { | ||
66 | this.notifier.success(this.i18n('Copied')) | ||
67 | } | ||
68 | } | ||