From 4bc45da342597fb49593fc14c40f8dc5a97bb64e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Mar 2021 11:54:08 +0100 Subject: Add hooks support for video download --- .../video-download.component.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'client') diff --git a/client/src/app/shared/shared-video-miniature/video-download.component.ts b/client/src/app/shared/shared-video-miniature/video-download.component.ts index 90f4daf7c..a57e4ce6d 100644 --- a/client/src/app/shared/shared-video-miniature/video-download.component.ts +++ b/client/src/app/shared/shared-video-miniature/video-download.component.ts @@ -1,7 +1,9 @@ import { mapValues, pick } from 'lodash-es' +import { pipe } from 'rxjs' +import { tap } from 'rxjs/operators' import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core' -import { AuthService, Notifier } from '@app/core' -import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { AuthService, HooksService, Notifier } from '@app/core' +import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' import { VideoCaption, VideoFile, VideoPrivacy } from '@shared/models' import { BytesPipe, NumberFormatterPipe, VideoDetails, VideoService } from '../shared-main' @@ -26,7 +28,7 @@ export class VideoDownloadComponent { videoFileMetadataVideoStream: FileMetadata | undefined videoFileMetadataAudioStream: FileMetadata | undefined videoCaptions: VideoCaption[] - activeModal: NgbActiveModal + activeModal: NgbModalRef type: DownloadType = 'video' @@ -38,7 +40,8 @@ export class VideoDownloadComponent { private notifier: Notifier, private modalService: NgbModal, private videoService: VideoService, - private auth: AuthService + private auth: AuthService, + private hooks: HooksService ) { this.bytesPipe = new BytesPipe() this.numbersPipe = new NumberFormatterPipe(this.localeId) @@ -64,7 +67,12 @@ export class VideoDownloadComponent { this.resolutionId = this.getVideoFiles()[0].resolution.id this.onResolutionIdChange() + if (this.videoCaptions) this.subtitleLanguageId = this.videoCaptions[0].language.id + + this.activeModal.shown.subscribe(() => { + this.hooks.runAction('action:modal.video-download.shown', 'common') + }) } onClose () { @@ -88,6 +96,7 @@ export class VideoDownloadComponent { if (this.videoFile.metadata || !this.videoFile.metadataUrl) return await this.hydrateMetadataFromMetadataUrl(this.videoFile) + if (!this.videoFile.metadata) return this.videoFileMetadataFormat = this.videoFile ? this.getMetadataFormat(this.videoFile.metadata.format) @@ -201,7 +210,7 @@ export class VideoDownloadComponent { private hydrateMetadataFromMetadataUrl (file: VideoFile) { const observable = this.videoService.getVideoFileMetadata(file.metadataUrl) - observable.subscribe(res => file.metadata = res) + .pipe(tap(res => file.metadata = res)) return observable.toPromise() } -- cgit v1.2.3