Added download button to player component

This commit is contained in:
Isaac Grynsztein
2020-02-18 17:29:34 -05:00
parent 8e3d6a0af6
commit b41d10f514
3 changed files with 74 additions and 2 deletions

View File

@@ -31,6 +31,8 @@ export class PlayerComponent implements OnInit {
videoFolderPath = null;
innerWidth: number;
downloading = false;
@HostListener('window:resize', ['$event'])
onResize(event) {
this.innerWidth = window.innerWidth;
@@ -47,6 +49,12 @@ export class PlayerComponent implements OnInit {
this.baseStreamPath = result['YoutubeDLMaterial']['Downloader']['path-base'];
this.audioFolderPath = result['YoutubeDLMaterial']['Downloader']['path-audio'];
this.videoFolderPath = result['YoutubeDLMaterial']['Downloader']['path-video'];
const backendUrl = result['YoutubeDLMaterial']['Host']['backendurl'];
this.postsService.path = backendUrl;
this.postsService.startPath = backendUrl;
this.postsService.startPathSSL = backendUrl;
let fileType = null;
if (this.type === 'audio') {
fileType = 'audio/mp3';
@@ -117,4 +125,36 @@ export class PlayerComponent implements OnInit {
return decodeURI(string);
}
downloadContent() {
const fileNames = [];
for (let i = 0; i < this.playlist.length; i++) {
fileNames.push(this.playlist[i].title);
}
const zipName = fileNames[0].split(' ')[0] + fileNames[1].split(' ')[0];
this.downloading = true;
this.postsService.downloadFileFromServer(fileNames, this.type, zipName).subscribe(res => {
this.downloading = false;
const blob: Blob = res;
saveAs(blob, zipName + '.zip');
}, err => {
console.log(err);
this.downloading = false;
});
}
downloadFile() {
const ext = (this.type === 'audio') ? '.mp3' : '.mp4';
const filename = this.playlist[0].title;
this.downloading = true;
this.postsService.downloadFileFromServer(filename, this.type).subscribe(res => {
this.downloading = false;
const blob: Blob = res;
saveAs(blob, filename + ext);
}, err => {
console.log(err);
this.downloading = false;
});
}
}