aboutsummaryrefslogtreecommitdiff
path: root/ui/src/app
diff options
context:
space:
mode:
authorAlex <alexta69@gmail.com>2022-09-30 09:10:57 +0300
committerGitHub <noreply@github.com>2022-09-30 09:10:57 +0300
commitb7c8c80362fdfb9a465042d8027c0af9063ff62a (patch)
treec8d195e229a7d9b9c98ffe71881fafaf96637320 /ui/src/app
parentupgraded yt-dlp (diff)
parentMerge branch 'master' of https://github.com/alexta69/metube into custom-downl... (diff)
downloadmetube-b7c8c80362fdfb9a465042d8027c0af9063ff62a.tar.gz
metube-b7c8c80362fdfb9a465042d8027c0af9063ff62a.tar.bz2
metube-b7c8c80362fdfb9a465042d8027c0af9063ff62a.zip
Merge pull request #177 from jwoglom/custom-download-folder
Custom download folders (fixes #129)
Diffstat (limited to 'ui/src/app')
-rw-r--r--ui/src/app/app.component.html23
-rw-r--r--ui/src/app/app.component.sass11
-rw-r--r--ui/src/app/app.component.ts66
-rw-r--r--ui/src/app/app.module.ts4
-rw-r--r--ui/src/app/downloads.service.ts24
5 files changed, 111 insertions, 17 deletions
diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html
index e96ee0d..6d59fd4 100644
--- a/ui/src/app/app.component.html
+++ b/ui/src/app/app.component.html
@@ -47,10 +47,21 @@
</div>
</div>
<div class="col-md-3 add-url-component">
- <button class="btn btn-primary add-url" type="submit" (click)="addDownload()" [disabled]="addInProgress || downloads.loading">
- <span class="spinner-border spinner-border-sm" role="status" id="add-spinner" *ngIf="addInProgress"></span>
- {{ addInProgress ? "Adding..." : "Add" }}
- </button>
+ <div [attr.class]="showAdvanced() ? 'btn-group add-url-group' : 'add-url-group'" ngbDropdown #advancedDropdown="ngbDropdown" display="dynamic" placement="bottom-end">
+ <button class="btn btn-primary add-url" type="submit" (click)="addDownload()" [disabled]="addInProgress || downloads.loading">
+ <span class="spinner-border spinner-border-sm" role="status" id="add-spinner" *ngIf="addInProgress"></span>
+ {{ addInProgress ? "Adding..." : "Add" }}
+ </button>
+ <button class="btn btn-primary dropdown-toggle dropdown-toggle-split" id="advancedButton" type="button" title="Advanced options" [disabled]="addInProgress || downloads.loading" ngbDropdownAnchor (focus)="advancedDropdown.open()" *ngIf="showAdvanced()">
+ <span class="sr-only">Advanced options</span>
+ </button>
+ <div ngbDropdownMenu aria-labelledby="advancedButton" class="dropdown-menu dropdown-menu-end folder-dropdown-menu">
+ <div class="input-group">
+ <span class="input-group-text">Download Folder</span>
+ <ng-select [items]="customDirs$ | async" placeholder="Default" [addTag]="allowCustomDir.bind(this)" addTagText="Create directory" [ngStyle]="{'flex-grow':'1'}" bindLabel="folder" [(ngModel)]="folder" [disabled]="addInProgress || downloads.loading"></ng-select>
+ </div>
+ </div>
+ </div>
</div>
</div>
</div>
@@ -118,11 +129,11 @@
<fa-icon *ngIf="download.value.status == 'finished'" [icon]="faCheckCircle" style="color: green;"></fa-icon>
<fa-icon *ngIf="download.value.status == 'error'" [icon]="faTimesCircle" style="color: red;"></fa-icon>
</div>
- <span ngbTooltip="{{download.value.msg}}"><a *ngIf="!!download.value.filename; else noDownloadLink" href="download/{{download.value.filename | encodeURIComponent}}" target="_blank">{{ download.value.title }}</a></span>
+ <span ngbTooltip="{{download.value.msg}}"><a *ngIf="!!download.value.filename; else noDownloadLink" href="{{buildDownloadLink(download.value)}}" target="_blank">{{ download.value.title }}</a></span>
<ng-template #noDownloadLink>{{ download.value.title }}</ng-template>
</td>
<td>
- <button *ngIf="download.value.status == 'error'" type="button" class="btn btn-link" (click)="retryDownload(download.key, download.value.url, download.value.quality)"><fa-icon [icon]="faRedoAlt"></fa-icon></button>
+ <button *ngIf="download.value.status == 'error'" type="button" class="btn btn-link" (click)="retryDownload(download.key, download.value.url, download.value.quality, download.value.folder)"><fa-icon [icon]="faRedoAlt"></fa-icon></button>
</td>
<td>
<a href="{{download.value.url}}" target="_blank"><fa-icon [icon]="faExternalLinkAlt"></fa-icon></a>
diff --git a/ui/src/app/app.component.sass b/ui/src/app/app.component.sass
index 517af03..0f98556 100644
--- a/ui/src/app/app.component.sass
+++ b/ui/src/app/app.component.sass
@@ -9,9 +9,20 @@
.add-url-component
margin: 0.5rem auto
+.add-url-group
+ width: 100%
+
button.add-url
width: 100%
+.folder-dropdown-menu
+ width: 500px
+
+.folder-dropdown-menu .input-group
+ display: flex
+ padding-left: 5px
+ padding-right: 5px
+
$metube-section-color-bg: rgba(0,0,0,.07)
.metube-section-header
diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts
index a9b46a3..7ef7da4 100644
--- a/ui/src/app/app.component.ts
+++ b/ui/src/app/app.component.ts
@@ -2,15 +2,16 @@ import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { faTrashAlt, faCheckCircle, faTimesCircle } from '@fortawesome/free-regular-svg-icons';
import { faRedoAlt, faSun, faMoon, faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons';
import { CookieService } from 'ngx-cookie-service';
+import { map, Observable, of } from 'rxjs';
-import { DownloadsService, Status } from './downloads.service';
+import { Download, DownloadsService, Status } from './downloads.service';
import { MasterCheckboxComponent } from './master-checkbox.component';
import { Formats, Format, Quality } from './formats';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
- styleUrls: ['./app.component.sass']
+ styleUrls: ['./app.component.sass'],
})
export class AppComponent implements AfterViewInit {
addUrl: string;
@@ -18,8 +19,10 @@ export class AppComponent implements AfterViewInit {
qualities: Quality[];
quality: string;
format: string;
+ folder: string;
addInProgress = false;
darkMode: boolean;
+ customDirs$: Observable<string[]>;
@ViewChild('queueMasterCheckbox') queueMasterCheckbox: MasterCheckboxComponent;
@ViewChild('queueDelSelected') queueDelSelected: ElementRef;
@@ -44,6 +47,10 @@ export class AppComponent implements AfterViewInit {
this.setupTheme(cookieService)
}
+ ngOnInit() {
+ this.customDirs$ = this.getMatchingCustomDir();
+ }
+
ngAfterViewInit() {
this.downloads.queueChanged.subscribe(() => {
this.queueMasterCheckbox.selectionChanged();
@@ -70,6 +77,36 @@ export class AppComponent implements AfterViewInit {
qualityChanged() {
this.cookieService.set('metube_quality', this.quality, { expires: 3650 });
+ // Re-trigger custom directory change
+ this.downloads.customDirsChanged.next(this.downloads.customDirs);
+ }
+
+ showAdvanced() {
+ return this.downloads.configuration['CUSTOM_DIRS'] == 'true';
+ }
+
+ allowCustomDir(tag: string) {
+ if (this.downloads.configuration['CREATE_CUSTOM_DIRS'] == 'true') {
+ return tag;
+ }
+ return false;
+ }
+
+ isAudioType() {
+ return this.quality == 'audio' || this.format == 'mp3';
+ }
+
+ getMatchingCustomDir() : Observable<string[]> {
+ return this.downloads.customDirsChanged.asObservable().pipe(map((output) => {
+ // Keep logic consistent with app/ytdl.py
+ if (this.isAudioType()) {
+ console.debug("Showing audio-specific download directories");
+ return output["audio_download_dir"];
+ } else {
+ console.debug("Showing default download directories");
+ return output["download_dir"];
+ }
+ }));
}
setupTheme(cookieService) {
@@ -97,6 +134,8 @@ export class AppComponent implements AfterViewInit {
this.cookieService.set('metube_format', this.format, { expires: 3650 });
// Updates to use qualities available
this.setQualities()
+ // Re-trigger custom directory change
+ this.downloads.customDirsChanged.next(this.downloads.customDirs);
}
queueSelectionChanged(checked: number) {
@@ -114,13 +153,15 @@ export class AppComponent implements AfterViewInit {
this.quality = exists ? this.quality : 'best'
}
- addDownload(url?: string, quality?: string, format?: string) {
+ addDownload(url?: string, quality?: string, format?: string, folder?: string) {
url = url ?? this.addUrl
quality = quality ?? this.quality
format = format ?? this.format
+ folder = folder ?? this.folder
+ console.debug('Downloading: url='+url+' quality='+quality+' format='+format+' folder='+folder);
this.addInProgress = true;
- this.downloads.add(url, quality, format).subscribe((status: Status) => {
+ this.downloads.add(url, quality, format, folder).subscribe((status: Status) => {
if (status.status === 'error') {
alert(`Error adding URL: ${status.msg}`);
} else {
@@ -130,8 +171,8 @@ export class AppComponent implements AfterViewInit {
});
}
- retryDownload(key: string, url: string, quality: string, format: string) {
- this.addDownload(url, quality, format);
+ retryDownload(key: string, url: string, quality: string, format: string, folder: string) {
+ this.addDownload(url, quality, format, folder);
this.downloads.delById('done', [key]).subscribe();
}
@@ -150,4 +191,17 @@ export class AppComponent implements AfterViewInit {
clearFailedDownloads() {
this.downloads.delByFilter('done', dl => dl.status === 'error').subscribe();
}
+
+ buildDownloadLink(download: Download) {
+ let baseDir = 'download/';
+ if (download.quality == 'audio' || download.filename.endsWith('.mp3')) {
+ baseDir = 'audio_download/';
+ }
+
+ if (download.folder) {
+ baseDir += download.folder + '/';
+ }
+
+ return baseDir + encodeURIComponent(download.filename);
+ }
}
diff --git a/ui/src/app/app.module.ts b/ui/src/app/app.module.ts
index 6ad5978..8eddbca 100644
--- a/ui/src/app/app.module.ts
+++ b/ui/src/app/app.module.ts
@@ -10,6 +10,7 @@ import { AppComponent } from './app.component';
import { EtaPipe, SpeedPipe, EncodeURIComponent } from './downloads.pipe';
import { MasterCheckboxComponent, SlaveCheckboxComponent } from './master-checkbox.component';
import { MeTubeSocket } from './metube-socket';
+import { NgSelectModule } from '@ng-select/ng-select';
@NgModule({
declarations: [
@@ -25,7 +26,8 @@ import { MeTubeSocket } from './metube-socket';
FormsModule,
NgbModule,
HttpClientModule,
- FontAwesomeModule
+ FontAwesomeModule,
+ NgSelectModule
],
providers: [CookieService, MeTubeSocket],
bootstrap: [AppComponent]
diff --git a/ui/src/app/downloads.service.ts b/ui/src/app/downloads.service.ts
index 8580a70..77d2fed 100644
--- a/ui/src/app/downloads.service.ts
+++ b/ui/src/app/downloads.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
-import { of, Subject } from 'rxjs';
+import { Observable, of, Subject } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { MeTubeSocket } from './metube-socket';
@@ -9,13 +9,14 @@ export interface Status {
msg?: string;
}
-interface Download {
+export interface Download {
id: string;
title: string;
url: string,
status: string;
msg: string;
filename: string;
+ folder: string;
quality: string;
percent: number;
speed: number;
@@ -33,6 +34,10 @@ export class DownloadsService {
done = new Map<string, Download>();
queueChanged = new Subject();
doneChanged = new Subject();
+ customDirsChanged = new Subject();
+
+ configuration = {};
+ customDirs = {};
constructor(private http: HttpClient, private socket: MeTubeSocket) {
socket.fromEvent('all').subscribe((strdata: string) => {
@@ -74,6 +79,17 @@ export class DownloadsService {
this.done.delete(data);
this.doneChanged.next(null);
});
+ socket.fromEvent('configuration').subscribe((strdata: string) => {
+ let data = JSON.parse(strdata);
+ console.debug("got configuration:", data);
+ this.configuration = data;
+ });
+ socket.fromEvent('custom_dirs').subscribe((strdata: string) => {
+ let data = JSON.parse(strdata);
+ console.debug("got custom_dirs:", data);
+ this.customDirs = data;
+ this.customDirsChanged.next(data);
+ });
}
handleHTTPError(error: HttpErrorResponse) {
@@ -81,8 +97,8 @@ export class DownloadsService {
return of({status: 'error', msg: msg})
}
- public add(url: string, quality: string, format: string) {
- return this.http.post<Status>('add', {url: url, quality: quality, format: format}).pipe(
+ public add(url: string, quality: string, format: string, folder: string) {
+ return this.http.post<Status>('add', {url: url, quality: quality, format: format, folder: folder}).pipe(
catchError(this.handleHTTPError)
);
}
bgstack15