Added the ability to download (export) archives from subscriptions

pull/29/head
Isaac Grynsztein 5 years ago
parent 6f3e94cf24
commit 846dd7e250

@ -192,7 +192,7 @@ function watchSubscriptions() {
let current_delay = 0; let current_delay = 0;
for (let i = 0; i < subscriptions.length; i++) { for (let i = 0; i < subscriptions.length; i++) {
let sub = subscriptions[i]; let sub = subscriptions[i];
console.log('watching ' + sub.name + ' with delay interval of ' + delay_interval); if (debugMode) console.log('watching ' + sub.name + ' with delay interval of ' + delay_interval);
setTimeout(() => { setTimeout(() => {
subscriptions_api.getVideosForSub(sub); subscriptions_api.getVideosForSub(sub);
}, current_delay); }, current_delay);
@ -1145,6 +1145,20 @@ app.post('/api/deleteFile', async (req, res) => {
res.send() res.send()
}); });
app.post('/api/downloadArchive', async (req, res) => {
let sub = req.body.sub;
let archive_dir = sub.archive;
let full_archive_path = path.join(__dirname, archive_dir, 'archive.txt');
if (fs.existsSync(full_archive_path)) {
res.sendFile(full_archive_path);
} else {
res.sendStatus(404);
}
});
app.get('/api/video/:id', function(req , res){ app.get('/api/video/:id', function(req , res){
var head; var head;
let optionalParams = url_api.parse(req.url,true).query; let optionalParams = url_api.parse(req.url,true).query;

@ -21,5 +21,7 @@
<mat-dialog-actions> <mat-dialog-actions>
<button mat-button mat-dialog-close>Close</button> <button mat-button mat-dialog-close>Close</button>
<button mat-stroked-button (click)="downloadArchive()" color="accent">Export Archive</button>
<span class="spacer"></span>
<button mat-button (click)="unsubscribe()" color="warn">Unsubscribe</button> <button mat-button (click)="unsubscribe()" color="warn">Unsubscribe</button>
</mat-dialog-actions> </mat-dialog-actions>

@ -5,3 +5,5 @@
.info-item-value { .info-item-value {
font-size: 13px; font-size: 13px;
} }
.spacer {flex: 1 1 auto;}

@ -29,4 +29,11 @@ export class SubscriptionInfoDialogComponent implements OnInit {
}); });
} }
downloadArchive() {
this.postsService.downloadArchive(this.sub).subscribe(res => {
const blob: Blob = res;
saveAs(blob, 'archive.txt');
});
}
} }

@ -120,6 +120,10 @@ export class PostsService {
{responseType: 'blob'}); {responseType: 'blob'});
} }
downloadArchive(sub) {
return this.http.post(this.path + 'downloadArchive', {sub: sub}, {responseType: 'blob'});
}
getFileInfo(fileNames, type, urlMode) { getFileInfo(fileNames, type, urlMode) {
return this.http.post(this.path + 'getVideoInfos', {fileNames: fileNames, type: type, urlMode: urlMode}); return this.http.post(this.path + 'getVideoInfos', {fileNames: fileNames, type: type, urlMode: urlMode});
} }

@ -5,7 +5,7 @@
<button [matMenuTriggerFor]="action_menu" class="menuButton" mat-icon-button><mat-icon>more_vert</mat-icon></button> <button [matMenuTriggerFor]="action_menu" class="menuButton" mat-icon-button><mat-icon>more_vert</mat-icon></button>
<mat-menu #action_menu="matMenu"> <mat-menu #action_menu="matMenu">
<button (click)="deleteAndRedownload()" mat-menu-item><mat-icon>restore</mat-icon>Delete and redownload</button> <button (click)="deleteAndRedownload()" mat-menu-item><mat-icon>restore</mat-icon>Delete and redownload</button>
<button (click)="deleteForever()" mat-menu-item><mat-icon>delete_forever</mat-icon>Delete forever</button> <button (click)="deleteForever()" mat-menu-item *ngIf="sub.archive && use_youtubedl_archive"><mat-icon>delete_forever</mat-icon>Delete forever</button>
</mat-menu> </mat-menu>
<mat-card (click)="goToFile(file.name)" matRipple class="example-card mat-elevation-z6"> <mat-card (click)="goToFile(file.name)" matRipple class="example-card mat-elevation-z6">
<div style="padding:5px"> <div style="padding:5px">

@ -20,6 +20,7 @@ export class SubscriptionFileCardComponent implements OnInit {
@Input() file; @Input() file;
@Input() sub; @Input() sub;
@Input() use_youtubedl_archive = false;
@Output() goToFileEmit = new EventEmitter<any>(); @Output() goToFileEmit = new EventEmitter<any>();
@Output() reloadSubscription = new EventEmitter<boolean>(); @Output() reloadSubscription = new EventEmitter<boolean>();

@ -13,7 +13,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div *ngFor="let file of files" class="col mb-4 sub-file-col"> <div *ngFor="let file of files" class="col mb-4 sub-file-col">
<app-subscription-file-card (reloadSubscription)="getSubscription()" (goToFileEmit)="goToFile($event)" [file]="file" [sub]="subscription"></app-subscription-file-card> <app-subscription-file-card (reloadSubscription)="getSubscription()" (goToFileEmit)="goToFile($event)" [file]="file" [sub]="subscription" [use_youtubedl_archive]="use_youtubedl_archive"></app-subscription-file-card>
</div> </div>
</div> </div>
</div> </div>

@ -12,6 +12,7 @@ export class SubscriptionComponent implements OnInit {
id = null; id = null;
subscription = null; subscription = null;
files: any[] = null; files: any[] = null;
use_youtubedl_archive = false;
constructor(private postsService: PostsService, private route: ActivatedRoute, private router: Router) { } constructor(private postsService: PostsService, private route: ActivatedRoute, private router: Router) { }
@ -20,6 +21,7 @@ export class SubscriptionComponent implements OnInit {
this.id = this.route.snapshot.paramMap.get('id'); this.id = this.route.snapshot.paramMap.get('id');
this.getSubscription(); this.getSubscription();
this.getConfig();
} }
} }
@ -30,11 +32,17 @@ export class SubscriptionComponent implements OnInit {
getSubscription() { getSubscription() {
this.postsService.getSubscription(this.id).subscribe(res => { this.postsService.getSubscription(this.id).subscribe(res => {
this.subscription = res['subscription']; this.subscription = res['subscription'];
console.log(res['files']);
this.files = res['files']; this.files = res['files'];
}); });
} }
getConfig() {
this.postsService.loadNavItems().subscribe(res => {
const result = !this.postsService.debugMode ? res['config_file'] : res;
this.use_youtubedl_archive = result['YoutubeDLMaterial']['Subscriptions']['subscriptions_use_youtubedl_archive'];
});
}
goToFile(name) { goToFile(name) {
localStorage.setItem('player_navigator', this.router.url); localStorage.setItem('player_navigator', this.router.url);
this.router.navigate(['/player', {fileNames: name, type: 'subscription', subscriptionName: this.subscription.name, this.router.navigate(['/player', {fileNames: name, type: 'subscription', subscriptionName: this.subscription.name,

Loading…
Cancel
Save