diff options
author | Nikolay G <crushoverdrive@mail.ru> | 2023-02-17 20:51:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-17 20:51:50 +0300 |
commit | f30bd109f7573472c288280b28abb7dd9d30ac7f (patch) | |
tree | 247d01d84268d0211f426b0dba30c410e7247797 /ui/src/app/app.component.ts | |
parent | Update README.md (diff) | |
parent | Merge pull request #219 from PikuZheng/patch-1 (diff) | |
download | metube-f30bd109f7573472c288280b28abb7dd9d30ac7f.tar.gz metube-f30bd109f7573472c288280b28abb7dd9d30ac7f.tar.bz2 metube-f30bd109f7573472c288280b28abb7dd9d30ac7f.zip |
Merge branch 'master' into master
Diffstat (limited to 'ui/src/app/app.component.ts')
-rw-r--r-- | ui/src/app/app.component.ts | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index a9b46a3..7038b68 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -1,16 +1,17 @@ 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 { faRedoAlt, faSun, faMoon, faExternalLinkAlt, faDownload } 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; @@ -34,6 +37,7 @@ export class AppComponent implements AfterViewInit { faRedoAlt = faRedoAlt; faSun = faSun; faMoon = faMoon; + faDownload = faDownload; faExternalLinkAlt = faExternalLinkAlt; constructor(public downloads: DownloadsService, private cookieService: CookieService) { @@ -44,6 +48,10 @@ export class AppComponent implements AfterViewInit { this.setupTheme(cookieService) } + ngOnInit() { + this.customDirs$ = this.getMatchingCustomDir(); + } + ngAfterViewInit() { this.downloads.queueChanged.subscribe(() => { this.queueMasterCheckbox.selectionChanged(); @@ -70,6 +78,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']; + } + + allowCustomDir(tag: string) { + if (this.downloads.configuration['CREATE_CUSTOM_DIRS']) { + 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 +135,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 +154,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 +172,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 +192,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); + } } |