switch between audio and default custom directories on change

This commit is contained in:
James Woglom 2022-08-30 00:58:19 -04:00
parent ba712fc071
commit 52e3307d99
2 changed files with 12 additions and 5 deletions

View File

@ -77,6 +77,8 @@ export class AppComponent implements AfterViewInit {
qualityChanged() { qualityChanged() {
this.cookieService.set('metube_quality', this.quality, { expires: 3650 }); this.cookieService.set('metube_quality', this.quality, { expires: 3650 });
// Re-trigger custom directory change
this.downloads.customDirsChanged.next(this.downloads.customDirs);
} }
showAdvanced() { showAdvanced() {
@ -88,13 +90,13 @@ export class AppComponent implements AfterViewInit {
} }
getMatchingCustomDir() : Observable<string[]> { getMatchingCustomDir() : Observable<string[]> {
return this.downloads.customDirs.asObservable().pipe(map((output) => { return this.downloads.customDirsChanged.asObservable().pipe(map((output) => {
// Keep logic consistent with app/ytdl.py // Keep logic consistent with app/ytdl.py
if (this.quality != 'audio' && this.format != 'mp3') { if (this.quality != 'audio' && this.format != 'mp3') {
console.debug("download_dir", output["download_dir"]) console.debug("Showing default download directories");
return output["download_dir"]; return output["download_dir"];
} else { } else {
console.debug("audio_download_dir", output["audio_download_dir"]) console.debug("Showing audio-specific download directories");
return output["audio_download_dir"]; return output["audio_download_dir"];
} }
})); }));
@ -125,6 +127,8 @@ export class AppComponent implements AfterViewInit {
this.cookieService.set('metube_format', this.format, { expires: 3650 }); this.cookieService.set('metube_format', this.format, { expires: 3650 });
// Updates to use qualities available // Updates to use qualities available
this.setQualities() this.setQualities()
// Re-trigger custom directory change
this.downloads.customDirsChanged.next(this.downloads.customDirs);
} }
queueSelectionChanged(checked: number) { queueSelectionChanged(checked: number) {

View File

@ -33,8 +33,10 @@ export class DownloadsService {
done = new Map<string, Download>(); done = new Map<string, Download>();
queueChanged = new Subject(); queueChanged = new Subject();
doneChanged = new Subject(); doneChanged = new Subject();
customDirs = new Subject<Map<string, string[]>>(); customDirsChanged = new Subject();
configuration = {}; configuration = {};
customDirs = {};
constructor(private http: HttpClient, private socket: MeTubeSocket) { constructor(private http: HttpClient, private socket: MeTubeSocket) {
socket.fromEvent('all').subscribe((strdata: string) => { socket.fromEvent('all').subscribe((strdata: string) => {
@ -84,7 +86,8 @@ export class DownloadsService {
socket.fromEvent('custom_dirs').subscribe((strdata: string) => { socket.fromEvent('custom_dirs').subscribe((strdata: string) => {
let data = JSON.parse(strdata); let data = JSON.parse(strdata);
console.debug("got custom_dirs:", data); console.debug("got custom_dirs:", data);
this.customDirs.next(data); this.customDirs = data;
this.customDirsChanged.next(data);
}); });
} }