diff --git a/src/api-types/models/DownloadFileRequest.ts b/src/api-types/models/DownloadFileRequest.ts
index 0986e59..31ba393 100644
--- a/src/api-types/models/DownloadFileRequest.ts
+++ b/src/api-types/models/DownloadFileRequest.ts
@@ -8,4 +8,6 @@ export interface DownloadFileRequest {
uuid?: string;
sub_id?: string;
playlist_id?: string;
+ url?: string;
+ type?: string;
}
\ No newline at end of file
diff --git a/src/app/player/player.component.html b/src/app/player/player.component.html
index 04b907b..74c0b1b 100644
--- a/src/app/player/player.component.html
+++ b/src/app/player/player.component.html
@@ -33,6 +33,7 @@
+
diff --git a/src/app/player/player.component.ts b/src/app/player/player.component.ts
index fb40ed1..5fe3936 100644
--- a/src/app/player/player.component.ts
+++ b/src/app/player/player.component.ts
@@ -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
diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts
index 9be0841..f157d47 100644
--- a/src/app/posts.services.ts
+++ b/src/app/posts.services.ts
@@ -351,11 +351,13 @@ export class PostsService implements CanActivate {
return this.http.post(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});
}