Merge pull request #528 from chepe263/master

Add download video button on player component.
pull/533/head
Glassed Silver 3 years ago committed by GitHub
commit 26eb687ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,4 +8,6 @@ export interface DownloadFileRequest {
uuid?: string;
sub_id?: string;
playlist_id?: string;
url?: string;
type?: string;
}

@ -33,6 +33,7 @@
<button *ngIf="(!postsService.isLoggedIn || postsService.permissions.includes('sharing')) && !auto" (click)="openShareDialog()" mat-icon-button><mat-icon>share</mat-icon></button>
</ng-container>
<ng-container *ngIf="db_file">
<button (click)="downloadVideo()" [disabled]="downloading" mat-icon-button><mat-icon>cloud_download</mat-icon><mat-spinner *ngIf="downloading" class="spinner" [diameter]="35"></mat-spinner></button>
<button (click)="downloadFile()" [disabled]="downloading" mat-icon-button><mat-icon>save</mat-icon><mat-spinner *ngIf="downloading" class="spinner" [diameter]="35"></mat-spinner></button>
<button *ngIf="type !== 'subscription' && (!postsService.isLoggedIn || postsService.permissions.includes('sharing'))" (click)="openShareDialog()" mat-icon-button><mat-icon>share</mat-icon></button>
<button (click)="openFileInfoDialog()" *ngIf="db_file" mat-icon-button><mat-icon>info</mat-icon></button>

@ -9,6 +9,7 @@ import { ShareMediaDialogComponent } from '../dialogs/share-media-dialog/share-m
import { FileType } from '../../api-types';
import { TwitchChatComponent } from 'app/components/twitch-chat/twitch-chat.component';
import { VideoInfoDialogComponent } from 'app/dialogs/video-info-dialog/video-info-dialog.component';
import { HttpClient, HttpParams } from '@angular/common/http';
export interface IMedia {
title: string;
@ -109,10 +110,9 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
}
constructor(public postsService: PostsService, private route: ActivatedRoute, private dialog: MatDialog, private router: Router,
public snackBar: MatSnackBar, private cdr: ChangeDetectorRef) {
public snackBar: MatSnackBar, private cdr: ChangeDetectorRef, private http: HttpClient) {
}
processConfig() {
this.baseStreamPath = this.postsService.path;
this.audioFolderPath = this.postsService.config['Downloader']['path-audio'];
@ -315,8 +315,10 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
downloadFile() {
const filename = this.playlist[0].title;
const ext = (this.playlist[0].type === 'audio/mp3') ? '.mp3' : '.mp4';
const type = this.playlist[0].type;
const url = this.playlist[0].url;
this.downloading = true;
this.postsService.downloadFileFromServer(this.uid, this.uuid, this.sub_id).subscribe(res => {
this.postsService.downloadFileFromServer(this.uid, this.uuid, this.sub_id, url, type).subscribe(res => {
this.downloading = false;
const blob: Blob = res;
saveAs(blob, filename + ext);
@ -326,6 +328,24 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
});
}
downloadVideo() {
const filename = this.currentItem.label;
const ext = (this.currentItem.type === 'audio/mp3') ? '.mp3' : '.mp4';
// const type = this.currentItem.type;
const url = this.currentItem.src;
this.downloading = true;
this.http.get(url, {
responseType: 'blob'
}).subscribe(res => {
const blob: Blob = res;
this.downloading = false;
saveAs(blob, filename + ext);
}, err => {
console.log(err);
this.downloading = false;
})
}
playlistPostCreationHandler(playlistID) {
// changes the route without moving from the current view or
// triggering a navigation event

@ -351,11 +351,13 @@ export class PostsService implements CanActivate {
return this.http.post<GetAllFilesResponse>(this.path + 'getAllFiles', {sort: sort, range: range, text_search: text_search, file_type_filter: file_type_filter}, this.httpOptions);
}
downloadFileFromServer(uid: string, uuid: string = null, sub_id: string = null) {
downloadFileFromServer(uid: string, uuid: string = null, sub_id: string = null, url: string = null, type: string = null) {
const body: DownloadFileRequest = {
uid: uid,
uuid: uuid,
sub_id: sub_id
sub_id: sub_id,
url: url,
type: type
};
return this.http.post(this.path + 'downloadFile', body, {responseType: 'blob', params: this.httpOptions.params});
}

Loading…
Cancel
Save