Added ability to download subscription videos as zip

This commit is contained in:
Isaac Grynsztein
2020-03-17 22:24:52 -04:00
parent b2730926c8
commit bdb6a08274
5 changed files with 69 additions and 14 deletions

View File

@@ -114,11 +114,12 @@ export class PostsService {
return this.http.post(this.path + 'getMp4s', {});
}
downloadFileFromServer(fileName, type, outputName = null) {
downloadFileFromServer(fileName, type, outputName = null, fullPathProvided = null) {
return this.http.post(this.path + 'downloadFile', {fileNames: fileName,
type: type,
is_playlist: Array.isArray(fileName),
outputName: outputName},
zip_mode: Array.isArray(fileName),
outputName: outputName,
fullPathProvided: fullPathProvided},
{responseType: 'blob'});
}

View File

@@ -42,4 +42,5 @@
</div>
</div>
</div>
<button class="save-button" color="primary" (click)="downloadContent()" [disabled]="downloading" mat-fab><mat-icon class="save-icon">save</mat-icon><mat-spinner *ngIf="downloading" class="spinner" [diameter]="50"></mat-spinner></button>
</div>

View File

@@ -38,7 +38,27 @@
display: block;
position: relative;
}
.col {
width: 33%;
display: inline-block;
}
.spinner {
width: 50px;
height: 50px;
bottom: 3px;
left: 3px;
position: absolute;
}
.save-button {
right: 25px;
position: absolute;
bottom: 25px;
}
.save-icon {
bottom: 1px;
position: relative;
}

View File

@@ -41,6 +41,7 @@ export class SubscriptionComponent implements OnInit {
}
};
filterProperty = this.filterProperties['upload_date'];
downloading = false;
constructor(private postsService: PostsService, private route: ActivatedRoute, private router: Router) { }
@@ -122,4 +123,21 @@ export class SubscriptionComponent implements OnInit {
this.filterByProperty(this.filterProperty['property']);
}
downloadContent() {
const fileNames = [];
for (let i = 0; i < this.files.length; i++) {
fileNames.push(this.files[i].path);
}
this.downloading = true;
this.postsService.downloadFileFromServer(fileNames, 'video', this.subscription.name, true).subscribe(res => {
this.downloading = false;
const blob: Blob = res;
saveAs(blob, this.subscription.name + '.zip');
}, err => {
console.log(err);
this.downloading = false;
});
}
}